Skip to content

Instantly share code, notes, and snippets.

@sophoah
Last active July 22, 2021 12:00
Show Gist options
  • Save sophoah/02254da18ec33d9363b5622bebde8fd6 to your computer and use it in GitHub Desktop.
Save sophoah/02254da18ec33d9363b5622bebde8fd6 to your computer and use it in GitHub Desktop.
linux command operation and help

Extend a parition without restart on ubuntu

assumption

you need to have some space free before doing the below if not command will fail

you need the ubuntu tool growpart / resize2fs / xfs_growfs apt install cloud-guest-utils xfsprogs -y

check and confirm which type (ext4 or xfs) is your partition

df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     1.6G  640K  1.6G   1% /run
/dev/sda2      ext4      195G  173G   13G  94% /        ==> ext4
tmpfs          tmpfs     7.9G   12K  7.9G   1% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sda1      ext4      922M  139M  720M  17% /boot
tmpfs          tmpfs     1.6G     0  1.6G   0% /run/user/0

Check you have room for growth

lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   400G  0 disk              ==> total of 400G
├─sda1   8:1    0   953M  0 part /boot
└─sda2   8:2    0 199.1G  0 part /            ==> used 200G

extend the partition

in this example, you wanna extend the / disk from sda2 so partition 2 of sda disk

growpart /dev/sda 2

Resize the parition (ext4)

resize2fs /dev/sda2

resize the partition (xfs)

xfs_growfs /dev/sda2

check everything is ok

df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  7.8G     0  7.8G   0% /dev
tmpfs          tmpfs     1.6G  640K  1.6G   1% /run
/dev/sda2      ext4      392G  174G  201G  47% /
tmpfs          tmpfs     7.9G   12K  7.9G   1% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs     7.9G     0  7.9G   0% /sys/fs/cgroup
/dev/sda1      ext4      922M  139M  720M  17% /boot
tmpfs          tmpfs     1.6G     0  1.6G   0% /run/user/0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment