os: build bootable images

This commit is contained in:
Alex Zenla
2024-03-10 00:22:24 +00:00
parent 817509bcef
commit 4894bd9d1c
28 changed files with 384 additions and 82 deletions

80
os/internal/stage1.sh Executable file
View File

@ -0,0 +1,80 @@
#!/bin/sh
set -e
apk add --update-cache alpine-base \
linux-lts linux-firmware-none \
mkinitfs dosfstools e2fsprogs \
tzdata chrony
apk add --allow-untrusted /mnt/target/os/krata.apk
for SERVICE in kratad kratanet
do
rc-update add "${SERVICE}" default
done
apk add xen xen-hypervisor
for SERVICE in xenconsoled xenstored
do
rc-update add "${SERVICE}" default
done
for MODULE in xen-netblock xen-blkback tun tap
do
echo "${MODULE}" >> /etc/modules
done
cat > /etc/network/interfaces <<-EOF
auto eth0
iface eth0 inet dhcp
EOF
for SERVICE in networking chronyd
do
rc-update add "${SERVICE}" default
done
for SERVICE in devfs dmesg mdev hwdrivers cgroups
do
rc-update add "${SERVICE}" sysinit
done
for SERVICE in modules hwclock swap hostname sysctl bootmisc syslog seedrng
do
rc-update add "${SERVICE}" boot
done
for SERVICE in killprocs savecache mount-ro
do
rc-update add "${SERVICE}" shutdown
done
echo 'root:krata' | chpasswd
echo 'krata' > /etc/hostname
{
echo '# krata resolver configuration'
echo 'nameserver 1.1.1.1'
echo 'nameserver 1.0.0.1'
echo 'nameserver 2606:4700:4700::1111'
echo 'nameserver 2606:4700:4700::1001'
} > /etc/resolv.conf
{
echo 'Welcome to krataOS!'
echo 'You may now login to the console to manage krata.'
} > /etc/issue
echo > /etc/motd
ln -s /usr/share/zoneinfo/UTC /etc/localtime
rm -rf /var/cache/apk/*
rm -rf /.dockerenv
cd /
rm -f /mnt/target/os/rootfs.tar
tar cf /mnt/target/os/rootfs.tar --numeric-owner \
--exclude 'mnt/**' --exclude 'proc/**' \
--exclude 'sys/**' --exclude 'dev/**' .

19
os/internal/stage2.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/sh
set -e
apk add --update-cache grub-efi
grub-install --target=x86_64-efi --efi-directory=/boot/efi --no-nvram --skip-fs-probe --bootloader-id=BOOT
mv /boot/efi/EFI/BOOT/grubx64.efi /boot/efi/EFI/BOOT/BOOTX64.efi
ROOT_UUID="$(cat /root-uuid)"
{
echo 'GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=1024M,max:1024M"'
echo "GRUB_CMDLINE_LINUX_DEFAULT=\"quiet rootfstype=ext4 root=UUID=${ROOT_UUID} modules=ext4\""
echo 'GRUB_DEFAULT="saved"'
echo 'GRUB_SAVEDEFAULT="true"'
} >> /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
grub-set-default "$(grep ^menuentry /boot/grub/grub.cfg | grep Xen | cut -d \' -f 2 | head -1)"
rm -rf /var/cache/apk/*