X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/m1-debian/blobdiff_plain/e1af00a32584e2155a2252a2eafe838cf40aeb39..d72e8ddda6951cdbde257806597e2cd29684d19e:/files/rc.local diff --git a/files/rc.local b/files/rc.local index fbd572a..c2e649b 100755 --- a/files/rc.local +++ b/files/rc.local @@ -1,13 +1,13 @@ #!/usr/bin/perl # [x] resize root filesystem -# [ ] find boot partition -# [ ] generate fstab -# [ ] mount boot +# [x] find root fs uuid +# [x] find boot partition +# [x] generate fstab +# [x] mount /boot/efi +# [x] install grub # [ ] extract wifi firmware -# [ ] reloads the kernel modules -# [ ] install grub -# [ ] disables itself +# [ ] In order to change the uuid of the root filesystem, bootstrap.sh must remember it in a file within the mounted disk image. And the initrd needs to change it. sub find_root_device @@ -25,6 +25,92 @@ find_root_device die("Could not find root device"); } -my $root_block_device = find_root_device(); +sub +find_fs_uuid_of_device +{ + my $dev = shift || die; + my $blkid_output = `blkid ${dev}`; + # /dev/nvme0n1p5: LABEL="/" UUID="fe9c5ac8-edf4-442e-a09e-e0451606898e" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="03378b79-346d-42f9-b404-44b22bc6798f" + if ($blkid_output =~ /UUID="([^"]+)"/) { + return $1; + } + + die("Could not find fs uuid of $dev"); +} + +sub +find_efi_parition +{ + my $uuid_in_grub_cfg = shift || die; + my @candidates; + + my $efi_parition = undef; + + for (`blkid`) { + if (/^([\S]+):.*TYPE="vfat"/) { + push(@candidates, $1); + } + } + + for my $dev (@candidates) { + system("mount -o ro $dev /mnt"); + if (-f '/mnt/EFI/boot/grub.cfg') { + open(GRUBCFG, '<', '/mnt/EFI/boot/grub.cfg') || die ("Can't open /mnt/EFI/boot/grub.cfg: $!"); + my @lines = ; + for (@lines) { + if (/${uuid_in_grub_cfg}/) { + $efi_parition = $dev; + } + } + close(GRUBCFG); + } + system("umount /mnt"); + last if defined $efi_parition; + } + + die ("No efi parition found") unless defined $efi_parition; -system("resize2fs $root_block_device"); + return $efi_parition; +} + +sub +generate_fstab +{ + my $root_fs_uuid = shift || die; + my $efi_fs_uuid = shift || die; + + open(FSTAB, '>', '/etc/fstab') || die ("Can not open fstab"); + print FSTAB <