Resizing a VM
If you run out of space on your Linux VM, stuff stops working. In this case, you need to add space to your virtual disk, create a partition, extend your main partition and tell the file system to reflect this. The following are steps from this website on 2/11/2023. Note: The volume group for ubuntu should be ubuntu-vg
and the logical volume (volume/lv) should be 'ubuntu-lv`.
Extending Partition and Filesystem
- Shutdown the VM
- Right click the VM and select Edit Settings
- Select the hard disk you would like to extend
- On the right side, make the provisioned size as large as you need it
- Click OK
- Power on the VM
- Connect to the command line of the Linux VM via the console or putty session
- Log in as root
- The fdisk command provides disk partitioning functions and using it with the -l switch lists information about your disk partitions. At the command prompt type
fdisk -l
- The response should say something like Disk /dev/sda : xxGB.
- At the command prompt type fdisk /dev/sda. (if dev/sda is what was returned after step 10)
- Type p to print the partition table and press Enter.
- Type n to add a new partition
- Type p again to make it a primary partition
- Now youâll be prompted to pick the first cylinder which will most likely come at the end of your last partition (ex: /dev/sda3 ends at 2610). So I chose 2611 for my first cylinder, which is also listed as the default.
- If you want it to take up the rest of the space available (as allocated in step 4), just choose the default value for the last cylinder.
- Type w to save these changes
- Restart the VM
- Log back in as root
- At the command prompt type fdisk -l. Youâll notice another partition is present.
- You need to initialize this new partition as a physical volume so you can manipulate it later using the Logical Volume Manager (LVM).
- Now youâll add the physical volume to the existing volume group using the vgextend command. First type
df -h
to find the name of the volume group. The name of the volume group is vg_root. Now typevgextend [volume group] /dev/sdaX
. (ex: vgextend vg_root /dev/sda4) - To find the amount of free space available on the physical volume type
vgdisplay [volume group] | grep âFreeâ
- Extend the logical volume by the amount of free space shown in the previous step by typing
lvextend -L+[freespace]G /dev/volgroup/volume
. (ex: lvextend -L+20G /dev/vg_root/lv_root) - You can finally expand the ext3 file system in the logical volume using the command
resize2fs /dev/volgroup/volume
(ex: resize2fs /dev/vg_root/lv_root). - You can now run the
df -h
command to verify that you have more spaceÂ
Related articles
Welcome to the University Wiki Service! Please use your IID (yourEID@eid.utexas.edu) when prompted for your email address during login or click here to enter your EID. If you are experiencing any issues loading content on pages, please try these steps to clear your browser cache.