This document describes how to add disk space to Linux Virtual Machines (VMs).
Linux (and Linux VMs) are installed on hard disks, whether real or virtual. On top of this is stacked a Volume Manager followed by a filesystem which is what is typically used.
For a Linux VM, these steps are required in order to increase the size of a filesystem:
- In order to resize the partition, enter the fdisk command and use the PV Name (from Section 1 Step 2) without the number on the end.
# fdisk <pv_name without the number on the end>
This sample shows output for the fdisk /dev/sda command:
[root@sessionmgr02 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 9137.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help):
- At the command prompt, enter p and press Enter in order to view the partition table.
Command (m for help): p
This example shows output that shows the partition table after you type the letter 'p':
Command (m for help): p
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help):
- Record the Start and Id values for the partition that you want to resize. For example, from the example output in Step 2, Start: 14 Id: 8e .
Start:_______________________Id:_________________________
- Delete the Partition entry for the device you want to resize. Enter d at the command prompt.
Command (m for help): d
This example shows the results after you enter d:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4):
- At the Partition number prompt, enter the partition number you want to delete and press Enter. (The number at the end of the Device name is the partition number.)
Partition number (1-4): <number>
This example shows the results after you enter the partition number:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 9137 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help):
- At the Command prompt, enter n in order to create a new partition.
Command (m for help): n
This example shows the results after you enter n:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
Command (m for help): n
- Enter p for a primary partition.
Command (m for help): p
This example shows output after you enter p:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
- At the Partition number prompt enter the partition number and press Enter (same partition number as the one deleted). In this example, the number is 2.
Partition number (1-4): 2
This example shows the results after you enter the partition number:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9137, default 14):
- Verify that the default value for the First cylinder number matches the Start value from Step 3 of this Section. If it does, press Enter in order to accept the default. If it does not match, ensure that it does not overlap with any existing partitions then manually enter the value and press Enter.
This example shows the results after you accept the default value and press Enter:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9790, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-9790, default 9790):
- For the Last cylinder value press Enter in order to use the default value.
This sample shows the results after you accept the default value and press Enter:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9790, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-9790, default 9790):
Using default value 9790
Command (m for help):
- At the Command prompt, enter t and press Enter.
Command (m for help): t
This example shows the results after you enter t:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9790, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-9790, default 9790):
Using default value 9790
Command (m for help): t
Partition number (1-4):
- At the Partition number prompt, enter the partition number you want to resize and press Enter.
Partition number (1-4): 2
This example shows the results after you enter the partition number:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9790, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-9790, default 9790):
Using default value 9790
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes):
- At the Hex code prompt, type the hex code. This is the Id value from Step 3 in this Section. Press Enter.
Hex code (type L to list codes): 8e
This example shows the results after you enter the hex code:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9790, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-9790, default 9790):
Using default value 9790
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help):
- At the Command prompt, enter w in order to write the partition to the disk.
Command (m for help): w
This example shows the results after you enter w at the prompt:
Disk /dev/sda: 75.1 GB, 75161927680 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 9137 73288530 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (14-9790, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-9790, default 9790):
Using default value 9790
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@sessionmgr02 ~]#
This exits fdisk and takes you to the root prompt.
- Reboot the VM in order to ensure the new settings match up with the kernel.
# init 6
- After the VM completes the reboot (about 5 minutes) log into (ssh) the VM as root.
- Check in order to ensure the disk size is now larger with the fdisk -l <PV Name> command in order to view the new partition size (PV Name is from Section 1 Step 2).
[root@sessionmgr02 ~]# fdisk -l /dev/sda
Disk /dev/sda2: 80.4 GB, 80418562560 bytes
255 heads, 63 sectors/track, 9777 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
This example output shows that /dev/sda now has 80Gigabytes allocated to it.