How to resize partition via command line?

I have Ubuntu installed on a VirtualBox VM. How can I resize the Linux partition (not the virtual drive)?

I already performed the VM resize using VBoxManage modifyhd to resize the virtual drive, but I need to resize the Linux partition. I do not have a GUI to gparted, so I need to resize the partition from the command line.

0

1 Answer

If you use LVM (Logical Volume Manager):

  1. Expand physical volume (sda3 replace by your partition name):

    sudo pvresize /dev/sda3

  2. Check free space:

    sudo vgdisplay

  3. Add space to logical volume (VG00/share replace by your LV name):

    sudo lvresize –L -r 100G VG00/share

  4. Check changes:

    sudo lvdisplay

If you don't use LVM:

All below commands work for unmounted partition, so you should boot from another source, for example, from iso (liveCD image).

  1. Change partition size: sudo fdisk /dev/sda3:
  • remove old partition (d)
  • create new one, bigger (n)
  • write changes (w)
  1. Expand file system:

    sudo e2fsck -f /dev/sda3 sudo resize2fs /dev/sda3

  2. Reboot system, boot as usual.

  3. Check partitions:

    df

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like