humbargs
12/23/2013 - 4:25 PM

Disk: Extend Disk Space on a Linux VM

Disk: Extend Disk Space on a Linux VM

1. Add disk space to the vm by adding another virtual disk.

2. In the linux VM, issue the following commands:
   # List existing disks
   fdisk -l
   
   # Scan for the new disk created in step 1.
   echo "- - -" >/sys/class/scsi_host/host0/scan
   
   # List existing disks (should see the new disk)
   # and it should contain a message saying the 
   # partition table is invalid
   fdisk -l
   
   # Partition the Disk
   fdisk /dev/sdb
   
   # Select 'n' to add/create a partition
   n
   
   # Select 'p' to create a primary partition
   p
   
   # Select '1' to create the 1st primary partition
   1
   
   # Press enter to select the default cylinder (which is 1)
   <enter>
   
   # Press enter to select the default last cylinder (depends on the size of the disk)
   <enter>
   
   # Press 't' change the partition's system id
   t
   
   # Select hex code '8e' to create an LVM
   8e
   
   # Select 'w' to write table to disk and exit
   w
   
   # Create your physical volume for the partion created with the fdisk command above
   pvcreate /dev/sdb1
   
   # Determine the VolGroup you want to extend
   vgdisplay
   
   # Extend the volume group by adding the new physical volume to it
   vgextend <volgroup> /dev/sdb1
   
   # List volumes
   ls /dev/<volgroup>
   
   # Resize the lvm (Change +10G to what is appropriate)
   lvresize -L +10G /dev/<volgroup>/<vol>
   resize4fs /dev/<volgroup>/<vol>  # may need to do resize2fs on fedora 20 and ubuntu
   
   # Check your partition sizes again
   df -h
   
   YOU ARE DONE!