0

I am attempting to use "growpart" to grow a partition on a vm that is using LVM. The command reports successfully, and seems to output the correct changes. Though, nothing happens after running, and the partition is not changed even after a restart.

I am attempting to expand partition 5(lvm) on /dev/sda with the 42g from the current 32g

$ lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                     8:0    0   42G  0 disk
├─sda1                  8:1    0  487M  0 part /boot
├─sda2                  8:2    0    1K  0 part
└─sda5                  8:5    0 31.5G  0 part
  ├─debian--vg-root   254:0    0 30.5G  0 lvm  /
  └─debian--vg-swap_1 254:1    0  976M  0 lvm  [SWAP]
sr0                    11:0    1 1024M  0 rom

$ fdisk -l
Disk /dev/sda: 42 GiB, 45097156608 bytes, 88080384 sectors
Disk model: QEMU HARDDISK
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: dos
Disk identifier: 0x3991920e

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 67106815 66105346 31.5G  5 Extended
/dev/sda5       1001472 67106815 66105344 31.5G 8e Linux LVM


Disk /dev/mapper/debian--vg-root: 30.5 GiB, 32774291456 bytes, 64012288 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


Disk /dev/mapper/debian--vg-swap_1: 976 MiB, 1023410176 bytes, 1998848 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

Now, using growpart to dry-run than grow the partition, which you can see the end block changed from 66105344 to 87078879 on partition 5

$ sudo growpart -N /dev/sda 5
CHANGE: partition=5 start=1001472 old: size=66105344 end=67106816 new: size=87078879,end=88080351
# === old sfdisk -d ===
label: dos
label-id: 0x3991920e
device: /dev/sda
unit: sectors

/dev/sda1 : start=        2048, size=      997376, type=83, bootable
/dev/sda2 : start=     1001470, size=    66105346, type=5
/dev/sda5 : start=     1001472, size=    66105344, type=8e
# === new sfdisk -d ===
label: dos
label-id: 0x3991920e
device: /dev/sda
unit: sectors

/dev/sda1 : start=        2048, size=      997376, type=83, bootable
/dev/sda2 : start=     1001470, size=    66105346, type=5
/dev/sda5 : start=     1001472, size=    87078879, type=8e

$ sudo growpart /dev/sda 5
CHANGED: partition=5 start=1001472 old: size=66105344 end=67106816 new: size=87078879,end=88080351

Now I would expect the lsblk to show the expanded size, but nothing has changed. Not sure whats going on to be honest, and its the same after a restart

$ lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                     8:0    0   42G  0 disk
├─sda1                  8:1    0  487M  0 part /boot
├─sda2                  8:2    0    1K  0 part
└─sda5                  8:5    0 31.5G  0 part
  ├─debian--vg-root   254:0    0 30.5G  0 lvm  /
  └─debian--vg-swap_1 254:1    0  976M  0 lvm  [SWAP]
sr0
donkeyx
  • 101
  • 1
  • sda5 can, at most, be the size of sda2 (less two sectors if I recall) - since sda5 is a partition inside the sda2 extended partition - I believe you'll need to extend sda2 first, and then sda5 ... though, reading the documentation for growpart, probably not an option - perhaps you'll have to *carefully* use fdisk or parted etc – Jaromanda X Jan 25 '23 at 21:54
  • correction: I've seen guides that in this scenario extend partition 2, then partition 5 using growpart - [here](https://serverfault.com/questions/1076077/extending-a-partition-in-ubuntu-14) ... though, personally I'd use parted as described in the same answer – Jaromanda X Jan 25 '23 at 22:03
  • cheers @JaromandaX, will take a look on monday, though that thread does look promising – donkeyx Jan 25 '23 at 23:02

1 Answers1

0

The process was exactly what was mentioned above. Grow the extended partition, then the child. After that you can proceed as normal.

extend the two parts -> extended -> child:

# grow the extended part
$ sudo growpart /dev/sda 2
CHANGED: partition=2 start=1001470 old: size=66105346 end=67106816 new: size=87078881,end=88080351

# now grow the child part
$ sudo growpart /dev/sda 5
CHANGED: partition=5 start=1001472 old: size=66105344 end=67106816 new: size=87078879,end=88080351

Then expand the physical volume :

$ sudo pvresize /dev/sda5

Now the logical volume :

$ sudo lvextend -l +100%FREE /dev/debian-vg/root

Last piece is the filesystem :

$ sudo resize2fs /dev/debian-vg/root

# now you will finally see it under `df` and is usable by the filesystem without restart
$ df -h
Filesystem                   Size  Used Avail Use% Mounted on
udev                         9.8G     0  9.8G   0% /dev
tmpfs                        2.0G   17M  2.0G   1% /run
/dev/mapper/debian--vg-root   40G   17G   21G  45% /
tmpfs                        9.9G     0  9.9G   0% /dev/shm
tmpfs                        5.0M     0  5.0M   0% /run/lock
tmpfs                        9.9G     0  9.9G   0% /sys/fs/cgroup
/dev/sda1                    470M   83M  363M  19% /boot
tmpfs                        2.0G     0  2.0G   0% /run/user/0
tmpfs                        2.0G     0  2.0G   0% /run/user/1002
tmpfs                        2.0G     0  2.0G   0% /run/user/1000
donkeyx
  • 101
  • 1