-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release: use systemd-repart for partition resizing
Switch from our `growpart` tool to `systemd-repart` to resize the data partition. For a unified root+data image. `growpart` uses the `gptman` crate, which calls the BLKRRPART ioctl to tell the kernel to re-read the partition table. This call fails if the device contains mounted partitions. `systemd-repart` uses the newer BLKPG ioctl, which manipulates the kernel's view of individual partitions. This works even if the root filesystem is present on the same device and already mounted. It also avoids the need to handle the partition symlink going away and coming back, since udev does not get the change event that triggers this. The two tools differ in how much free space is left on the device after the last partition is resized. `growpart` ends the partition one sector before the last 1 MiB boundary, while `systemd-repart` ends it just before the GPT label. Both tools run on every boot. To avoid problems on downgrade after a newer release resizes the data filesystem beyond where the older release will end the partition, we constrain `systemd-repart` to leave the older number of free sectors. Since `/local` can be mounted during the resize operation, we can use a real mount unit for it, which greatly simplifies the dependencies, and allows us to decouple the "prepare" logic from "resize" logic. Signed-off-by: Ben Cressey <[email protected]>
- Loading branch information
Showing
5 changed files
with
78 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[Unit] | ||
Description=Local Directory (/local) | ||
DefaultDependencies=no | ||
Conflicts=umount.target | ||
Before=local-fs.target umount.target | ||
|
||
[Mount] | ||
What=/dev/disk/by-partlabel/BOTTLEROCKET-DATA | ||
Where=/local | ||
Type=ext4 | ||
Options=defaults,noatime,nosuid,nodev | ||
|
||
[Install] | ||
WantedBy=preconfigured.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Partition] | ||
# This is the partition type UUID for BOTTLEROCKET-DATA, which will be resized | ||
# to fill the remaining sectors on the disk where it resides. | ||
Type=626f7474-6c65-6474-6861-726d61726b73 | ||
|
||
# We want the partition to end on the last 1 MiB boundary before the end of | ||
# the disk, to match the historical implementation. Assuming the disk itself is | ||
# an even multiple of MiBs in size, and using 512 byte sectors as an example, | ||
# we need 33 sectors for the GPT label in the last MiB, and therefore want 2015 | ||
# sectors left, or 1031680 bytes. The repart tool expects a multiple of 4096, | ||
# which is (1031680 - (1031680 % 4096)), or 1028096 bytes. | ||
PaddingMinBytes=1028096 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[Unit] | ||
Description=Resize Data Partition | ||
DefaultDependencies=no | ||
Conflicts=shutdown.target | ||
Wants=dev-disk-by\x2dpartlabel-BOTTLEROCKET\x2dDATA.device | ||
After=dev-disk-by\x2dpartlabel-BOTTLEROCKET\x2dDATA.device | ||
|
||
# Ensure the device is mounted first, to avoid racing with the unit that tries | ||
# to mount it since the symlink can disappear if the partition is resized. | ||
RequiresMountsFor=/local | ||
|
||
[Service] | ||
Type=oneshot | ||
|
||
# Resize the partition, whether or not it resides on the same disk as /. | ||
ExecStart=/usr/bin/systemd-repart --dry-run=no /dev/disk/by-partlabel/BOTTLEROCKET-DATA | ||
|
||
# Grow the filesystem to fill the partition. Doing this in another unit could | ||
# introduce a race if the underlying block device is not ready after resizing. | ||
ExecStart=/usr/lib/systemd/systemd-growfs /local | ||
|
||
RemainAfterExit=true | ||
StandardError=journal+console | ||
|
||
# systemd-repart returns 77 if there's no existing GPT partition table | ||
SuccessExitStatus=77 | ||
|
||
[Install] | ||
WantedBy=local-fs.target |