File: first-boot

package info (click to toggle)
asahi-scripts 20250713-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 316 kB
  • sloc: sh: 860; makefile: 117
file content (47 lines) | stat: -rwxr-xr-x 1,321 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
# SPDX-License-Identifier: MIT

set -e

root_dev=$(findmnt -n -o SOURCE /)
efi_dev=$(findmnt -n -o SOURCE /boot/efi)

if [ -e "$root_dev" ]; then
    echo "Randomizing root filesystem UUID..."
    tune2fs -U random "$root_dev"

    root_uuid="$(blkid -c /dev/null "$root_dev" -o export | grep '^UUID=')"
    echo "Root filesystem: $root_uuid"
    echo
fi

if [ -e "$efi_dev" ] && \
    blkid "$efi_dev" | grep -q 'TYPE="vfat"'; then

    echo "Randomizing EFI system partition UUID..."
    # Ugly... why isn't there a command to do this?
    ssize="$(blockdev --getss "$efi_dev")"
    dd bs=1 seek=67 count=4 conv=notrunc if=/dev/urandom of="$efi_dev"
    dd bs=1 skip=67 seek=$((67+6*$ssize)) count=4 conv=notrunc if="$efi_dev" of="$efi_dev"

    efi_uuid="$(blkid -c /dev/null "$efi_dev" -o export | grep '^UUID=')"
    echo "EFI partition: $efi_uuid"
    echo
fi

if [ ! -z "$root_uuid" ] && [ ! -z "$efi_uuid" ]; then
    echo "Regenerating /etc/fstab..."
    tee /etc/fstab <<EOF
$root_uuid / ext4 rw,relatime,x-systemd.growfs 0 1
$efi_uuid /boot/efi vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro    0 2
EOF
    echo
fi

update-grub

echo
echo "Initializing Pacman keyring..."
pacman-key --init
pacman-key --populate archlinuxarm asahilinux
echo