-
Notifications
You must be signed in to change notification settings - Fork 16
/
genstrap.sh
executable file
·109 lines (87 loc) · 2.67 KB
/
genstrap.sh
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
set -e
cleanup() {
echo "Cleaning up...."
echo
rm -rf /mnt/temp/
rm -rf squashfs-root
rm -rf image.squashfs
rm -rf new.squashfs
rm -rf overlay
rm -rf squashtree
}
if [[ $(whoami) != "root" ]]; then
echo "This script must be run as root. Type your password"
echo "when prompted."
sudo ./genstrap.sh
exit 0
fi
echo "This script will bootstrap an initramfs for installing Gentoo on"
echo "Apple Silicon machines. It must be run from an Asahi Linux install."
echo
echo "Please ensure that the latest Gentoo arm64 minimal install"
echo "image is located in this directory and named install.iso before"
echo "continuing."
echo
read -sp "Press Enter to continue."
echo
cleanup
echo "Installing dependencies..."
dnf install squashfs-tools dracut-live cpio parted bsdtar
echo "Extracting squashfs..."
bsdtar -xf install.iso --include image.squashfs
echo "Creating temporary mount..."
echo
mkdir /mnt/temp
modprobe brd rd_nr=1 rd_size=1280000
parted -sf /dev/ram0 mklabel gpt
parted -sf /dev/ram0 "mkpart root 0 -1"
mkfs.ext4 /dev/ram0p1
mount /dev/ram0p1 /mnt/temp
echo "Unsquashing Gentoo live environment."
echo
unsquashfs -q image.squashfs
echo "Setting up Gentoo live environment for Apple Silicon..."
echo
cd squashfs-root
rm -rf lib/firmware/*
rm -rf lib/modules/*gentoo*
cp -r /lib/modules/$(uname -r) lib/modules/
depmod -a --basedir=. $(uname -r)
cp -r /lib/firmware/{vendor,brcm} lib/firmware/
# The squashfs doesn't log in automatically for some reason?
echo "agetty_options=\"--autologin root\"" >> etc/conf.d/agetty
sed -i 's/\<agetty\>/& --autologin root/g' etc/inittab
echo "Creating live image..."
echo
cd ..
cp -r squashfs-root/* /mnt/temp/
umount /dev/ram0p1
mkdir -p squashtree/LiveOS
dd if=/dev/ram0p1 of=squashtree/LiveOS/rootfs.img
mksquashfs squashtree new.squashfs -quiet
echo "Setting up initramfs..."
mkdir -p overlay \
overlay/etc/cmdline.d \
overlay/mnt/efi
cp new.squashfs overlay/squash.img
echo "root=live:/squash.img ro console=tty0 init=/sbin/init" \
> overlay/etc/cmdline.d/01-default.conf
dracut --force \
--quiet \
--kver $(uname -r) \
--add-drivers "squashfs" \
--add "dmsquash-live" \
--filesystems "squashfs ext4 btrfs vfat" \
--install "grep mkdir" \
--include overlay / \
--no-hostonly \
./bootstrap_image.img
echo "Setting up initramfs and GRUB..."
cp /boot/vmlinuz-$(uname -r) /boot/vmlinuz-linux-asahi
mv bootstrap_image.img /boot/initramfs-gentoo-live.img
cat resources/init_grub >> /boot/grub2/grub.cfg
cleanup
modprobe -r brd
echo "When rebooting your system, select Gentoo Live Install environment from"
echo "the GRUB menu to boot into the Gentoo LiveCD."