#!/usr/bin/perl # [x] resize root filesystem # [x] find root fs uuid # [x] find boot partition # [x] generate fstab # [x] mount /boot/efi # [ ] install grub # [ ] extract wifi firmware # [ ] reboots if grub or wifi firmware has changed sub find_root_device { open(MOUNT, '<', '/proc/mounts') || die ("Can not open /proc/mounts for reading: $!"); my @lines = ; close(MOUNT); for (@lines) { if (/^([\S]+)+ \/ /) { return $1; } } die("Could not 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; 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 <