-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcreate-livecd.sh
executable file
·202 lines (202 loc) · 11.6 KB
/
create-livecd.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env bash
#
# MassOS Live CD (ISO) Creation Script - Copyright (C) 2025 Daniel Massey.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# Exit on error.
set -e
# Ensure we are running as root.
if test $EUID -ne 0; then
echo "ERROR: $(basename "$0") must be run as root."
exit 1
fi
# Add the MassOS programs directory to our path, in case we're not on MassOS.
export PATH="$PATH:$PWD/utils/programs"
# Ensure dependencies are present.
which curl &>/dev/null || (echo "Error: curl is required." >&2; exit 1)
which mass-chroot &>/dev/null || (echo "Error: mass-chroot (from MassOS) is required." >&2; exit 1)
which mkfs.fat &>/dev/null || (echo "Error: mkfs.fat from dosfstools is required." >&2; exit 1)
which mksquashfs &>/dev/null || (echo "Error: mksquashfs from squashfs-tools is required." >&2; exit 1)
which parallel &>/dev/null || (echo "Error: parallel is required." >&2; exit 1)
which rdfind &>/dev/null || (echo "Error: rdfind is required." >&2; exit 1)
which unzip &>/dev/null || (echo "Error: unzip is required." >&2; exit 1)
which xorriso &>/dev/null || (echo "Error: xorriso from libisoburn is required." >&2; exit 1)
# Ensure that the rootfs file is specified and exists.
if test -z "$1"; then
echo "Error: No rootfs file was specified." >&2
echo "Usage: $(basename "$0") <rootfs-file-name>.tar.xz" >&2
exit 1
fi
if test ! -f "$1"; then
echo "Error: Specified file $1 does not exist." >&2
exit 1
fi
# Ensure the rootfs file is a MassOS image and is a new enough version.
if ! tar tf "$1" 2>/dev/null | grep -q '^usr/lib/massos-release$'; then
echo "Error: The specified file $1 is not a valid MassOS rootfs." >&2
echo "Note: $(basename "$0") does not support MassOS 2022.10 or older." >&2
exit 1
fi
# Check if an existing directory exists.
if test -e "iso-workdir"; then
echo "The working directory 'iso-workdir' already exists, please remove" >&2
echo "it before running $(basename "$0")." >&2
exit 1
fi
# Create directories.
mkdir -p iso-workdir/{firmware,iso-root,massos-rootfs,mcode,mnt,mt86plus,osinstallgui,sof,squashfs-tmp,syslinux}
mkdir -p iso-workdir/iso-root/EFI/{BOOT,tools}
mkdir -p iso-workdir/iso-root/isolinux
mkdir -p iso-workdir/iso-root/LICENSES
mkdir -p iso-workdir/iso-root/LiveOS
mkdir -p iso-workdir/squashfs-tmp/LiveOS
mkdir -p iso-workdir/efitmp
# Get information from the rootfs (before extracting the whole thing).
echo "Gathering information from the rootfs..."
# Get firmware versions.
tar -xf "$1" -C iso-workdir --strip-components=3 usr/share/massos/firmwareversions
FW_VER="$(grep -m1 "^linux-firmware:" iso-workdir/firmwareversions | cut -d' ' -f2-)"
MVER="$(grep -m1 "^intel-microcode:" iso-workdir/firmwareversions | cut -d' ' -f2-)"
SOF_VER="$(grep -m1 "^sof-firmware:" iso-workdir/firmwareversions | cut -d' ' -f2-)"
# Get osinstallgui version.
tar -xf "$1" -C iso-workdir --strip-components=3 usr/share/massos/.osinstallguiver
OSINSTALLGUI_VER="$(cat iso-workdir/.osinstallguiver)"
# Download stuff.
echo "Downloading osinstallgui..."
curl -fL "https://github.com/DanielMYT/osinstallgui/archive/$OSINSTALLGUI_VER/osinstallgui-$OSINSTALLGUI_VER.tar.gz" -o iso-workdir/osinstallgui.tar.gz
tar -xf iso-workdir/osinstallgui.tar.gz -C iso-workdir/osinstallgui --strip-components=1
echo "Downloading SYSLINUX..."
curl -fL https://cdn.kernel.org/pub/linux/utils/boot/syslinux/Testing/6.04/syslinux-6.04-pre1.tar.xz -o iso-workdir/syslinux.tar.xz
tar --no-same-owner -xf iso-workdir/syslinux.tar.xz -C iso-workdir/syslinux --strip-components=1
echo "Downloading Memtest86+..."
curl -fL https://www.memtest.org/download/v7.20/mt86plus_7.20.binaries.zip -o iso-workdir/mt86plus.zip
unzip -q iso-workdir/mt86plus.zip -d iso-workdir/mt86plus
echo "Downloading UEFI Interactive Shell..."
curl -fL https://github.com/pbatard/UEFI-Shell/releases/download/24H2/shellx64.efi -o iso-workdir/shellx64.efi
echo "Downloading firmware..."
curl -fL "https://cdn.kernel.org/pub/linux/kernel/firmware/linux-firmware-$FW_VER.tar.xz" -o iso-workdir/firmware.tar.xz
curl -fL "https://github.com/intel/Intel-Linux-Processor-Microcode-Data-Files/archive/microcode-$MVER.tar.gz" -o iso-workdir/mcode.tar.gz
curl -fL "https://github.com/thesofproject/sof-bin/releases/download/v$SOF_VER/sof-bin-$SOF_VER.tar.gz" -o iso-workdir/sof.tar.gz
tar --no-same-owner -xf iso-workdir/firmware.tar.xz -C iso-workdir/firmware --strip-components=1
tar --no-same-owner -xf iso-workdir/mcode.tar.gz -C iso-workdir/mcode --strip-components=1
tar --no-same-owner -xf iso-workdir/sof.tar.gz -C iso-workdir/sof --strip-components=1
# Extract rootfs.
echo "Extracting rootfs..."
tar -xpf "$1" -C iso-workdir/massos-rootfs
ver="$(cat iso-workdir/massos-rootfs/etc/massos-release)"
# Prepare the live system.
echo "Preparing the live system..."
chroot iso-workdir/massos-rootfs /usr/sbin/groupadd -r autologin
chroot iso-workdir/massos-rootfs /usr/sbin/useradd -c "Live User" -G wheel,autologin -ms /bin/bash massos
echo "massos:massos" | chroot iso-workdir/massos-rootfs /usr/sbin/chpasswd -c YESCRYPT
echo "massos ALL=(ALL) NOPASSWD: ALL" > iso-workdir/massos-rootfs/etc/sudoers.d/live
cat > iso-workdir/massos-rootfs/etc/polkit-1/rules.d/49-live.rules << "END"
// Allow elevation without password prompt in the live environment.
polkit.addRule(function(action, subject) {
if (subject.isInGroup("massos")) {
return polkit.Result.YES;
}
});
END
# Install osinstallgui.
echo "Installing osinstallgui..."
make -C iso-workdir/osinstallgui
make -C iso-workdir/osinstallgui DESTDIR="$PWD"/iso-workdir/massos-rootfs install
sed -e "s|<Your Distro Name Here>|MassOS $ver|g" -e "s|<name-of-live-user>|massos|g" -e "s|</path/to/your/distro/logo>|/usr/share/massos/massos-logo.png|g" iso-workdir/osinstallgui/osinstallgui.desktop.example > iso-workdir/massos-rootfs/usr/share/applications/osinstallgui.desktop
chroot iso-workdir/massos-rootfs /usr/bin/install -o massos -g massos -dm755 /home/massos/Desktop
chroot iso-workdir/massos-rootfs /usr/bin/install -o massos -g massos -m755 /usr/share/applications/osinstallgui.desktop /home/massos/Desktop/osinstallgui.desktop
# Set up desktop-specific autologin configuration.
. livecd-data/autologin/autologin.sh
# Install firmware.
echo "Installing firmware (please ignore any citation warnings)..."
pushd iso-workdir/firmware
./copy-firmware.sh -j$(nproc) --xz "$PWD"/../massos-rootfs/usr/lib/firmware
./dedup-firmware.sh "$PWD"/../massos-rootfs/usr/lib/firmware
install -t "$PWD"/../massos-rootfs/usr/share/licenses/linux-firmware -Dm644 GPL-2 GPL-3 LICENCE* LICENSE* WHENCE
popd
install -dm755 iso-workdir/massos-rootfs/usr/lib/firmware/intel-ucode
install -m644 iso-workdir/mcode/intel-ucode{,-with-caveats}/* iso-workdir/massos-rootfs/usr/lib/firmware/intel-ucode
install -t iso-workdir/massos-rootfs/usr/share/licenses/intel-microcode -Dm644 iso-workdir/mcode/license
pushd iso-workdir/sof
cp -at "$PWD"/../massos-rootfs/usr/lib/firmware/intel sof*
install -t "$PWD"/../massos-rootfs/usr/share/licenses/sof-firmware -Dm644 LICENCE.Intel LICENCE.NXP Notice.NXP
popd
cat > iso-workdir/massos-rootfs/usr/share/massos/builtins.d/firmware << "END"
intel-microcode
linux-firmware
sof-firmware
END
# Create squashfs image.
echo "Creating squashfs image..."
cd iso-workdir/massos-rootfs
mksquashfs * ../iso-root/LiveOS/squashfs.img -comp xz -quiet
cd ../..
# Install kernel and generate initramfs.
echo "Installing kernel..."
cp iso-workdir/massos-rootfs/boot/vmlinuz* iso-workdir/iso-root/vmlinuz
echo "Generating initramfs..."
mass-chroot iso-workdir/massos-rootfs /usr/sbin/mkinitramfs "$(cat iso-workdir/massos-rootfs/usr/share/massos/.krel)" >/dev/null
mv iso-workdir/massos-rootfs/boot/initramfs-*.img iso-workdir/iso-root/initramfs.img
# Install bootloader files.
echo "Setting up bootloader..."
## Legacy BIOS.
cp iso-workdir/syslinux/bios/core/isolinux.bin iso-workdir/iso-root/isolinux/isolinux.bin
cp iso-workdir/syslinux/bios/com32/elflink/ldlinux/ldlinux.c32 iso-workdir/iso-root/isolinux/ldlinux.c32
cp iso-workdir/syslinux/bios/com32/lib/libcom32.c32 iso-workdir/iso-root/isolinux/libcom32.c32
cp iso-workdir/syslinux/bios/com32/libutil/libutil.c32 iso-workdir/iso-root/isolinux/libutil.c32
cp iso-workdir/syslinux/bios/com32/menu/vesamenu.c32 iso-workdir/iso-root/isolinux/vesamenu.c32
cp iso-workdir/syslinux/bios/com32/modules/reboot.c32 iso-workdir/iso-root/isolinux/reboot.c32
cp iso-workdir/syslinux/bios/com32/modules/poweroff.c32 iso-workdir/iso-root/isolinux/poweroff.c32
cp iso-workdir/syslinux/bios/mbr/isohdpfx.bin iso-workdir/iso-root/isolinux/isohdpfx.bin
cp iso-workdir/syslinux/COPYING iso-workdir/iso-root/LICENSES/ISOLINUX.txt
cp livecd-data/isolinux.cfg iso-workdir/iso-root/isolinux/isolinux.cfg
cp livecd-data/splash.png iso-workdir/iso-root/isolinux/splash.png
## UEFI.
mkdir -p iso-workdir/massos-rootfs/boot/grub
cp livecd-data/grub.cfg iso-workdir/massos-rootfs/boot/grub/grub.cfg
mass-chroot iso-workdir/massos-rootfs /usr/bin/grub-mkstandalone -d /usr/lib/grub/x86_64-efi -O x86_64-efi -o BOOTX64.EFI --compress=xz /boot/grub/grub.cfg >/dev/null
cp iso-workdir/massos-rootfs/BOOTX64.EFI iso-workdir/iso-root/EFI/BOOT/BOOTX64.EFI
chmod +x iso-workdir/iso-root/EFI/BOOT/BOOTX64.EFI
cp iso-workdir/massos-rootfs/usr/share/grub/unicode.pf2 iso-workdir/iso-root/unicode.pf2
cp iso-workdir/massos-rootfs/usr/share/licenses/grub/COPYING iso-workdir/iso-root/LICENSES/GRUB.txt
fallocate -l $(($(du -bc iso-workdir/iso-root/EFI/BOOT/BOOTX64.EFI | tail -n1 | cut -f1) + 80000)) iso-workdir/iso-root/EFI/BOOT/efiboot.img
mkfs.fat -F12 iso-workdir/iso-root/EFI/BOOT/efiboot.img -n "MASSOS_EFI"
mount -o loop iso-workdir/iso-root/EFI/BOOT/efiboot.img iso-workdir/efitmp
mkdir -p iso-workdir/efitmp/EFI/BOOT
cp iso-workdir/iso-root/EFI/BOOT/BOOTX64.EFI iso-workdir/efitmp/EFI/BOOT/BOOTX64.EFI
sync
umount iso-workdir/efitmp
# Install Memtest86+ and UEFI EDK2 Shell.
cp iso-workdir/mt86plus/memtest64.bin iso-workdir/iso-root/isolinux/memtest64.bin
cp iso-workdir/mt86plus/memtest64.efi iso-workdir/iso-root/EFI/tools/memtest64.efi
cp iso-workdir/shellx64.efi iso-workdir/iso-root/EFI/tools/shellx64.efi
# Copy additional files.
cp livecd-data/autorun.ico iso-workdir/iso-root/autorun.ico
cp livecd-data/autorun.inf iso-workdir/iso-root/autorun.inf
cp livecd-data/README.txt iso-workdir/iso-root/README.txt
cp LICENSE iso-workdir/iso-root/LICENSE.txt
cp livecd-data/LICENSES/*.txt iso-workdir/iso-root/LICENSES/
touch iso-workdir/iso-root/THIS_IS_THE_MASSOS_LIVECD
# Create the ISO image.
echo "Creating ISO image..."
xorrisofs -iso-level 3 -d -J -N -R -max-iso9660-filenames -relaxed-filenames -allow-lowercase -V "MASSOS" -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e EFI/BOOT/efiboot.img -isohybrid-gpt-basdat -no-emul-boot -isohybrid-mbr iso-workdir/iso-root/isolinux/isohdpfx.bin -o "massos-$ver-livecd-x86_64-$variant.iso" iso-workdir/iso-root
# Clean up.
echo "Cleaning up..."
rm -rf iso-workdir
# Finishing message.
echo "All done! Output image written to massos-$ver-livecd-x86_64-$variant.iso."
# Generate Blake-2 checksum.
b2sum "massos-$ver-livecd-x86_64-$variant.iso" > "massos-$ver-livecd-x86_64-$variant.iso.b2"
echo "Blake-2 checksum written to massos-$ver-livecd-x86_64-$variant.iso.b2."