Michael R. Head (suppressingfire) wrote,
Michael R. Head
suppressingfire

  • Location:
  • Music:

Extending the root filesystem on a RHEL5 virtual machine running in VMWare ESXi

Problem: a RHEL5 VM with the default LVM filesystem layout has outgrown its initial root partition. How can the capacity of the filesystem mounted on root be increased with minimal impact (beyond having to restart the VM)?

I'm sure this isn't the optimal solution, but it has worked for me a few times, so it's worth writing down (and receiving feedback on... I'm sure there's a way to do it without powering down the VM at all):
  1. Power down the VM.
  2. Log in using the VMWare infrastructure client
    1. "Edit Settings" on the VM of interest
    2. Increase the size of Hard Disk 1
    3. Ensure an Ubuntu 10.04 LTS Desktop iso will be connected at power on
    4. Ensure that the boot menu timeout is at least 5 seconds
  3. Boot the VM (pressing escape to boot using the cd rom, and "Try Ubuntu")
  4. Open a Terminal (Applications/Accessories/Terminal) and run these commands:
    1. sudo apt-get install lvm2
    2. sudo fdisk /dev/sda
    3. Create a new partition in the empty space with the sequences of key strokes:
      n [ret] p [ret] 3 [ret] [ret] [ret] t [ret] 3 [ret] 8e [ret] w [ret]
    4. sudo pvcreate /dev/sda3
    5. sudo vgextend VolGroup00 /dev/sda3
    6. sudo vgdisplay VolGroup00
      Note the "Free PE" number (e.g., 320)
    7. sudo lvextend -l +320 /dev/mapper/VolGroup00-LogVol00
      replacing 320 with the Free PE value from above
      N.B. the + character before 320 is of critical importance. If it isn't present, the command may truncate the filesystem
    8. sudo e2fsck /dev/mapper/VolGroup00-LogVol00
    9. sudo resize2fs /dev/mapper/VolGroup00-LogVol00
    10. sudo reboot
  5. When the RHEL5 has booted, the root partition will now have the additional desired capacity.
This works for the first drive extension, but would need to be modified if more partitions are added. /dev/sda4 (or an extended partition) would need to be added to support future extensions. Another possibility is to simply add a new virtual disk and add its capacity to the same logical volume.
Tags: linux, rhel, ubuntu, virtualization
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments