Home / How-To & Tutorials / VMware and Hot Adding Hard Disks to a Running CentOS or RHEL Linux System

VMware and Hot Adding Hard Disks to a Running CentOS or RHEL Linux System

Its possible to extend your disk space on your running virtual machine without even needing to reboot! There are a few caveats obviously, you need to be using LVM (if you are not, SHAME ON YOU!) and be comfortable with file systems and VMware.

  • First add the new Hard Disk in the virtual machine settings.
  • This can be done on the command line on the ESX server, but in this case I am not trying to extend the primary hard disk but just add another one.


  • Using this script (It was written by someone named Kurt Garloff) rescan-scsi-bus.sh
  • We will also upload this script to the Linux Digest git repo
# ./rescan-sci-bus.sh 
  • After executing run dmesg and you should see the new device added, pretty need huh?Screen-Shot-2012-06-19-at-1.12.05-AM
  • Once the disk has been added you can execute fdisk to display the new deviceScreen-Shot-2012-06-19-at-1.20.18-AM
  • Using fdisk create a partition, I’m going to asume you’ll want to use the entire disk but if desired you could create multiple partitions on the new disk. Here we will just be using the entire disk
# fdisk /dev/sdb
  • Type n for new partition
  • p for primary
  • Just hit enter again to use the default last cylinder since we want to use the entire disk in this case
  • Finally enter w and enter to write the partition table to disk and sync the diskScreen-Shot-2012-06-19-at-1.24.32-AM
  • After adding the new partition we have to change the partition type to LVM vs 83  Linux (regular Linux partition type)
 # fdisk /dev/sdb 
  • t (change partition type)
  • 8e (for Linux LVM)
  • And finally w and enter to write changes to disk
  • Now that we have a valid LVM partition we need to Initialize the Physical Volume
# pvcreate /dev/sdb1 
  • Here using
# vgdisplay
  • you can see the VG size prior to adding the new diskScreen-Shot-2012-06-19-at-1.53.36-AM
  •  Once you have initialized the physical volume you can add it to the volume group that you wish. In this can I want to extend the root volume and I have named it vg00.
# vgextend vg00 /dev/sdb1 

Screen-Shot-2012-06-19-at-2.03.16-AM

  • Once you have added it to the volume group, you should see the newly available free space.
#vgdisplay
 Screen-Shot-2012-06-19-at-2.03.40-AM
  • You can see on the Free PE / Size line that I have 29.97 GB of free space, now lets use it!
  • What we have to do now is actually extend the logical volume (vg00) so that it consumes the rest of the available space.

Tip: You can find out the path to your volume group with the df command and vgdisplay

# vgextend -L +29G /dev/vg00/rootvol 

Screen-Shot-2012-06-19-at-2.08.30-AM

  • Now that we hav extended the volume we have to extend the file system so the available space can be written to by the system. We do this by using the resize2fs command. Now because I am simply using ext3 this is the command for me, but if you were using a different file system such as xfs you need to use the tool available for that FS (xfs_grow for example)
# resize2fs /dev/mapper/vg00-rootvol

Screen-Shot-2012-06-19-at-2.08.47-AM

  • And thats it! Checkout df to see your newly available disk space.
  • Check back again for more articles on LVM here at Linux Digest, I will be writing another one on LVM snapshots and choosing the best file system for your needs.
  • Also a side note, if you are using SAN backed storage like I am (In this case Netapp). You must make sure you align your VMDK before adding it to your vgroup. I will also be writing an article on how to do this and why its important for performance.

Thanks for reading!

Kyle

About kyle

Leave a Reply

Your email address will not be published. Required fields are marked *

*