Wednesday, August 27, 2014

Extend /home partition under VMWare+Ubuntu

Say I want to add 512GB more space onto existing Ubuntu hosted by VMWare Workstation.


0. You have to turn off your Ubuntu system then switch VMWare Workstation
Right Click the Machine-> "Settings" -> "Hard Disk" in left panel -> click "Utilities" in right panel -> "Expand" -> Enter the new total space. Since my system has 512GB already, and I want to add 512GB, the total would be "1024".

1. Check existing disk partitions. write down the biggest number of End column. here it is 3221225471 

$sudo fdisk -l

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda3      2147481600  3221225471   536871936   83  Linux
/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM



2. Add new partition

$sudo fdisk /dev/sda

press "n" to create new partition, when when prompting "Partition type" , enter "p".

when prompting First sector, enter 3221225472 (3221225471 + 1) 

when prompting Last sector, accept defaults (use all remaining space)

then press "w" to write to disk.

3. reboot 

$sudo reboot

4. Run "sudo fdisk -l" again. This time you should see a new partition  "/dev/sda4"

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  2147481599  1073489921    5  Extended
/dev/sda3      2147481600  3221225471   536871936   83  Linux
/dev/sda4      3221225472  4294967294   536870911+  83  Linux

/dev/sda5          501760  2147481599  1073489920   8e  Linux LVM


4. Find a folder under "/dev/" which ends with "-vg". In should be named as "-vg". e.g. "master-vg" if your hostname is master.


5. Extend the volume group

$sudo vgextend cloud-vg /dev/sda4

You should see screen outputs like this:
  No physical volume label read from /dev/sda4
  Physical volume "/dev/sda4" successfully created

  Volume group "cloud-vg" successfully extended


6. Add logical volume

#add 512G

$sudo lvextend -L+512G /dev/cloud-vg/root

#or add all free space

$sudo lvextend -l+100%FREE /dev/cloud-vg/root

You should see screen outputs like this:

  Extending logical volume root to 1.98 TiB
  Logical volume root successfully resized


7. Final step - Reize 
$sudo resize2fs /dev/cloud-vg/root


8. Check out the disk usage now

$df -h

No comments:

Post a Comment