]> git.zerfleddert.de Git - m1-debian/blob - files/rc.local
work on rc.local script
[m1-debian] / files / rc.local
1 #!/usr/bin/perl
2
3 # [x] resize root filesystem
4 # [x] find root fs uuid
5 # [ ] find boot partition
6 # [ ] generate fstab
7 # [ ] mount boot
8 # [ ] install grub
9 # [ ] extract wifi firmware
10 # [ ] reboots if grub or wifi firmware has changed
11
12 my $root_block_device = undef;
13 my $root_fs_uuid = undef;
14 my $efi_block_device = undef;
15
16 sub
17 find_root_device
18 {
19 open(MOUNT, '<', '/proc/mounts') || die ("Can not open /proc/mounts for reading: $!");
20 my @lines = <MOUNT>;
21 close(MOUNT);
22
23 for (@lines) {
24 if (/^([\S]+)+ \/ /) {
25 return $1;
26 }
27 }
28
29 die("Could not find root device");
30 }
31
32 sub
33 find_fs_uuid_of_device
34 {
35 my $dev = shift || die;
36 my $blkid_output = `blkid ${dev}`;
37 # /dev/nvme0n1p5: LABEL="/" UUID="fe9c5ac8-edf4-442e-a09e-e0451606898e" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="03378b79-346d-42f9-b404-44b22bc6798f"
38 if ($blkid_output =~ /UUID="([^"]+)"/) {
39 return $1;
40 }
41
42 die("Could not find fs uuid of $dev");
43 }
44
45 sub
46 find_efi_parition
47 {
48 my $uuid_in_grub_cfg = shift || die;
49 my @candidates;
50
51 my $efi_parition = undef;
52
53 for (`blkid`) {
54 if (/^([\S]+):.*TYPE="vfat"/) {
55 push(@candidates, $1);
56 }
57 }
58
59 for my $dev (@candidates) {
60 system("mount -o ro $dev /mnt");
61 if (-f '/mnt/EFI/boot/grub.cfg') {
62 open(GRUBCFG, '<', '/mnt/EFI/boot/grub.cfg') || die ("Can't open /mnt/EFI/boot/grub.cfg: $!");
63 my @lines = <GRUBCFG>;
64 for (@lines) {
65 if (/${uuid_in_grub_cfg}/) {
66 $efi_parition = $dev;
67 }
68 }
69 close(GRUBCFG);
70 }
71 system("umount /mnt");
72 last if defined $efi_parition;
73 }
74
75 die ("No efi parition found") unless defined $efi_parition;
76
77 return $efi_parition;
78 }
79
80
81 $root_block_device = find_root_device();
82 # system("resize2fs $root_block_device");
83
84 $root_fs_uuid = find_fs_uuid_of_device($root_block_device);
85 $efi_block_device = find_efi_parition($root_fs_uuid);
Impressum, Datenschutz