How to resize partition via command line?

54,812

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

Share:
54,812

Related videos on Youtube

Jake
Author by

Jake

Updated on September 18, 2022

Comments

  • Jake
    Jake almost 2 years

    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.