Wednesday, January 22, 2014

Extending a Linux Virtual Disk

Something that popped up at work the other day, figured it was worth sharing given it's probably a fairly common task for a Sysadmin these days.
 
Check current disk size/free space
# df -h

 
Shut the machine down
# shutdown -h now

Using Microsoft Virtual Machine Manager (2008 R2):
- Right click the machine, and click on Properties
- Select the Hardware Configuration tab
- Select the disk from the left hand pane
- check Expand virtual hard disk, enter the new disk size and click OK

It will take a minute to rewrite the configuration and expand the current fixed vhd. Once complete, power the machine on again.


Delete current partition table for disk:
# fdisk device (eg. /dev/sda1)
d (delete partition)
n (create new partition)
p (primary)
1 (partition 1)
Enter (use default)
Enter (use default)
w (write new label)

Reboot machine:
# shutdown -r now

Resize filesystem:
# resize2fs (eg. /dev/sda1)

Confirm your changes have worked:
# df -h

...do the happy dance

No comments:

Post a Comment