| 21 Sep 2024 |
matthewcroughan | Right now I have all this boiler plate in my disko.nix's | 15:50:41 |
matthewcroughan | boot.postBootCommands = ''
# On the first boot, resize the disk
if [ -f /disko-first-boot ]; then
set -euo pipefail
set -x
# Figure out device names for the boot device and root filesystem.
rootPart=$(${pkgs.util-linux}/bin/findmnt -n -o SOURCE /)
bootDevice=$(lsblk -npo PKNAME $rootPart)
partNum=$(lsblk -npo MAJ:MIN $rootPart | ${pkgs.gawk}/bin/awk -F: '{print $2}')
# Resize the root partition and the filesystem to fit the disk
echo ",+," | sfdisk -N$partNum --no-reread $bootDevice
${pkgs.parted}/bin/partprobe
${pkgs.bcachefs-tools}/bin/bcachefs device resize $rootPart
# Prevents this from running on later boots.
rm -f /disko-first-boot
fi
'';
| 15:50:43 |
matthewcroughan | basically stealing the bits from nixpkgs that expand on boot | 15:50:52 |
matthewcroughan | postMountHook = toString (pkgs.writeScript "postMountHook.sh" ''
touch /mnt/disko-first-boot
'');
| 15:51:10 |
matthewcroughan | * postMountHook = toString (pkgs.writeScript "postMountHook.sh" ''
touch /mnt/disko-first-boot
'');
| 15:51:12 |
matthewcroughan | Lassulus said something about how this shouldn't be a disko feature at all, because of what you're saying about the filesystem specific code | 15:51:35 |
matthewcroughan | but if we're gonna have to do it for auto calculating the imageSize, this might as well get dealt with at the same time | 15:52:02 |
matthewcroughan | I like that disko doesn't inject any extra stuff, unless the user specifies it via postVM though, having to DIY it feels bad though | 15:52:21 |
matthewcroughan | * I like that disko doesn't inject any extra stuff, unless the user specifies it via postVM though, having to DIY it feels bad too though | 15:52:27 |
matthewcroughan | * I like that disko doesn't inject any extra stuff, unless the user specifies it via postVM/postMount though, having to DIY it feels bad too though | 15:52:38 |
Mic92 | doesn't systemd has some auto disk increase thingy? | 15:53:07 |
matthewcroughan | Yeah but that only works well with systemd-reparted | 15:53:15 |
matthewcroughan | and reparted sucks because it cannot build images for embedded devices due to demanding everything implement GPT | 15:53:27 |
matthewcroughan | * and reparted sucks because it cannot build images for embedded devices due to demanding everything implement GPT properly | 15:53:32 |
Mic92 | I think on-first-boot resizing is also different from disk images | 15:53:37 |
matthewcroughan | you can't make an image with arbitrary start sector for example, where you would put uboot | 15:53:49 |
matthewcroughan | I've played a lot with both disko and reparted, and reparted is only nice for x86 uefi, everything else is out of the window | 15:54:32 |
matthewcroughan | disko can do everything | 15:54:41 |
matthewcroughan | I also tried to coerce systemd into resizing the things that disko creates, but that can't be done, at least I couldn't figure it out | 15:55:14 |
matthewcroughan | afaik you can only coerce systemd into doing that for you if you have made everything with reparted | 15:55:35 |
matthewcroughan | In reply to @joerg:thalheim.io I think on-first-boot resizing is also different from disk images it is, but you can't do it without impacting the disk image | 16:02:11 |
matthewcroughan | You have to put some state on the disk image, so it knows that it's the first boot, there's no other strategy I know of that could indicate a disk image is being booted for the first time | 16:03:13 |
matthewcroughan | zfs autoResize is cool though, only zfs could do that however | 16:03:45 |
matthewcroughan | the strategy of touching a file in the disk image so the system knows when first-boot is happening, is filesystem agnostic | 16:04:20 |
Mic92 | can you not the sentinil file the other way around? | 16:05:26 |
Mic92 | And create the file after the resize? | 16:05:35 |
matthewcroughan | That would mean that on any boot, it attempts to resize, unless told not to? | 16:06:03 |
matthewcroughan | as opposed to attempting the resize only when told to | 16:06:49 |
matthewcroughan | feels risky to me, unless we trust the filesystem utils very much | 16:07:09 |
Mic92 | Well it only tries it once | 16:07:54 |