1

I have a ubuntu 18.04 VM running which I would rather not shut down to resize its root partition. I've found the following question and I'm wondering if its still the optimal way: How can I resize an ext root partition at runtime? .

My console output:

Command (m for help): p
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: B68A975A-BFCD-4FDE-B965-B9B169C3FBE9

Device       Start       End   Sectors  Size Type
/dev/sda1     2048      4095      2048    1M BIOS boot
/dev/sda2     4096   2101247   2097152    1G Linux filesystem
/dev/sda3  2101248 629143551 627042304  299G Linux filesystem

Command (m for help): q

plex@plex:~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
udev                               3.9G     0  3.9G   0% /dev
tmpfs                              798M  1.3M  797M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv   49G   36G   11G  77% /
tmpfs                              3.9G  8.0K  3.9G   1% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
tmpfs                              3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop0                          89M   89M     0 100% /snap/core/7270
/dev/loop1                          89M   89M     0 100% /snap/core/7169
/dev/sda2                          976M  143M  766M  16% /boot
192.168.178.200:/mnt/user/Series    70T   62T  8.6T  88% /series
192.168.178.200:/mnt/user/Coding    70T   62T  8.1T  89% /coding
192.168.178.200:/mnt/user/Movies    70T   62T  8.1T  89% /movies
192.168.178.200:/mnt/user/Music     70T   62T  8.1T  89% /music
tmpfs                              798M     0  798M   0% /run/user/1000

Would this be safe?

sudo resize2fs /dev/sda1

Thanks for any suggestions

In0cenT
  • 205

1 Answers1

2

Since your root partition is on LVM, you can always add a new disk to your VM and extend your root partition online.

Create a new partition on your newly added disk with parted or similar tool.

Create LVM Physical Volume as (assuming your new partition is /dev/sdb1):

sudo pvcreate /dev/sdb1

Extend the Volume Group (replace ubuntu--vg with your VG name, check under vgs command):

sudo vgextend ubuntu--vg /dev/sdb1

Extend the Logical Volume:

sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

Finally resize the ext based filesystem (for xfs filesystem use xfs_growfs command):

sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Abhishek Nair
  • 574
  • 3
  • 9