Skip to content

Expand root to all available volume space when it's a partition

Created by: tomalok

Fixes #15 (closed)

Manually doing what the script does...

alpine@ip-172-31-55-52:~$ df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/nvme0n1p2          985.0M    111.2M    806.9M  12% /
root@ip-172-31-55-52:~# echo ", +" | sfdisk --no-reread -N 2 /dev/nvme0n1
GPT PMBR size mismatch (2097151 != 20971519) will be corrected by write.
The backup GPT table is not on the end of the device. This problem will be corrected by write.
Disk /dev/nvme0n1: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: Amazon Elastic Block Store
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: 00E78CAF-AFC7-49A8-A758-31719F801C98

Old situation:

Device         Start     End Sectors  Size Type
/dev/nvme0n1p1  4096   14335   10240    5M EFI System
/dev/nvme0n1p2 14336 2097118 2082783 1017M Linux filesystem

/dev/nvme0n1p2:
New situation:
Disklabel type: gpt
Disk identifier: 00E78CAF-AFC7-49A8-A758-31719F801C98

Device         Start      End  Sectors Size Type
/dev/nvme0n1p1  4096    14335    10240   5M EFI System
/dev/nvme0n1p2 14336 20971486 20957151  10G Linux filesystem

The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or partx(8).
Syncing disks.
root@ip-172-31-55-52:~# partx -u /dev/nvme0n1
root@ip-172-31-55-52:~# resize2fs /dev/nvme0n1p2
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/nvme0n1p2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/nvme0n1p2 is now 2619643 (4k) blocks long.
root@ip-172-31-55-52:~# df -h /
Filesystem                Size      Used Available Use% Mounted on
/dev/nvme0n1p2            9.8G    115.4M      9.3G   1% /

Merge request reports