You are on page 1of 6

Live Expand RedHat-based Linux LVM

Volume and Filesystem on VMWare


Virtual Machines
10/24/2010

Cale Dunlap (cdunlap@enterprisehostinginc.com)


Systems Engineer
Enterprise Hosting, Inc.
http://www.enterprisehostinginc.com/

1. Before You Start


It is a good idea to take a snapshot before doing anything. This is to guard against the case
where the process of expanding the partition fails and corrupts data.
1. Right click on the VM
2. Highlight ‘Snapshot’ then click ‘Take Snapshot’

3. Name the snapshot something descriptive like the current date and time of the
snapshot. In the description field, describe what the snapshot is being taken for.
Example: “Prior to LVM and partition expansion.”
Note: There is no need to snapshot the VM’s memory for this purpose, it will only
bloat the snapshot as there is no benefit (in this case) to snapping the VM’s
memory. Uncheck the ‘Snapshot the virtual machine’s memory’ option.

4. Click OK

2. Adding a Disk
If needed, add a disk to the VM. This can be done while the guest is running with no need to
reboot.
1. Right click on the VM
2. Click “Edit Settings”
3. In the “Hardware” tab, click the “Add” button
4. Select “Hard Disk” from the list
5. Click “Next”

6. Select “Create new virtual disk” from the next window


7. Click “Next”
8. Set the disk size for the new disk as desired (the amount by which to extend)
9. [optional] If desired/capable, select “Allocate and commit space on demand
(Thin Provisioning)”

10. Click “Next”


11. Set the advanced options as desired (defaults are OK in most cases)
12. Click “Next”
13. Click “Finish”
14. Click “OK” on the “Virtual Machine Properties Window” to finalize the changes
and commit the settings.

3. Forcing a Drive Rescan


This step rescans the SCSI controller for new drives. This will detect the drive that was just
added and allow it to be used by the operating system.
1. Log into the VM via SSH or the console as root or ‘sudo’ to root from another
user
2. Type the following at the command prompt:
echo “- - -” > /sys/class/scsi_host/<host#>/scan
fdisk -l
Where “<host#>” is the SCSI host number1. Most cases will only have one:
host0
3. Make note of the new device path.2 A warning message should have printed to
the console about an ‘unknown partition table’. This is most likely the new drive
(although that may not always be the case).

4. Partition the New Drive


These steps will prepare the new disk for use as a physical volume in a LVM volume group.
1. Log into the VM via SSH or the console as root or ‘sudo’ to root from another
user
2. Type the following at the command prompt: fdisk <device path> where
“<device path>” is the device path references in step 3 of section 3.
3. Press the “n” key to create a new partition.
4. Press the “p” key to make the partition a primary partition
5. Press the “1” key to tell fdisk that this is primary partition number 1
6. Set all size parameters to the defaults (just press enter) to use the full disk
7. After the partition has been created, press the “t” key from within fdisk to change
the partition type.
8. Type 8e when prompted for the partition type hex code. This will identify the
partition as a Linux LVM partition.
9. Press the “w” key to write the partition table to the disk and quit fdisk.

5. Extend the Existing LVM and Partition


These steps create an LVM physical volume from the new disk and add it to the existing volume
group.
1. Log into the VM via SSH or the console as root or ‘sudo’ to root from another
user
2. Type the following at the command prompt: pvcreate <device path> where
“<device path>” is the path to the device references in section 3 step 3.
3. Type the following at the command prompt: vgextend <volume group name>
<device path> where “<volume group name>” is the name of the existing
volume group.3
4. Find the number of available extents on the volume group by typing the following
at the console: vgdisplay | grep PE. Look for the line that starts with “Free PE /
Size”. The number before the slash (/) is the number of available extents.

1
The SCSI host number can be found by issuing the following command:
ls /sys/class/scsi_host
2
The device path for connected drives can be found by issuing the following command:
fdisk -l | grep ‘^Disk’
3
Existing volume groups can be listed by typing: vgdisplay at the console.
5. Type the following at the command prompt: lvextend -l +<#> <logical
volume path> <device path> where “<logical volume path>” is the logical
volume to extend and “#” is the number of available extents references in step
4.4
6. Resize the existing partition by typing: resize2fs <logical volume path>
Note: This process may take a few minutes.
7. Confirm the changes by listing the file system mount points and their available
sizes. Type the following at the console: df -h

References
● Vmware Linux Guest Add a New Hard Disk Without Rebooting Guest:
http://www.cyberciti.biz/tips/vmware-add-a-new-hard-disk-without-rebooting-
guest.html
● Extend LVM Disk Space Dynamically
http://bloggerdigest .blogspot.com/2006/11/extend-lvm-disk-space-
dynamically.html
● Linux Disk Format
http://www.cyberciti.biz/faq/linux-disk-format/
● Linux Partition Naming Convention and IDE Drive Mappings
http://www.cyberciti.biz/faq/linux-partition-naming-convention-and-ide-drive-
mappings/

4
Finding which mount points are using which volume groups and/or logical volumes can be done by typing: df -h at the console.

You might also like