server/fickit-prepare.yml

260 lines
7.6 KiB
YAML
Raw Normal View History

2018-12-10 01:16:07 +00:00
kernel:
2022-06-01 10:39:40 +00:00
#image: nemunaire/kernel:5.10.62-0b705d955f5e283f62583c4e227d64a7924c138f-amd64
image: linuxkit/kernel:6.6.13
2018-12-10 01:16:07 +00:00
cmdline: "console=ttyS0 console=tty0"
init:
2024-03-24 10:42:11 +00:00
- nemunaire/mdadm:04814350d71ba9417e1f861be1685de26adf7a67
2023-04-03 09:42:00 +00:00
- nemunaire/syslinux:086f221f281d577d300949aa1094fb20c5cd90dc
2024-03-24 10:42:11 +00:00
- linuxkit/format:v1.0.0
- linuxkit/dm-crypt:d49723bc9d10c5ada9e03b0670f4e57416d5d084
- linuxkit/metadata:v1.0.0
- alpine:latest
2018-12-10 01:16:07 +00:00
files:
- path: /init
contents: |
#!/bin/sh
2022-06-02 09:40:43 +00:00
modprobe xhci_pci
modprobe ahci
modprobe megaraid_sas
modprobe e1000e
modprobe tg3
modprobe bnxt_en
echo -n "Waiting module loading... "
sleep 3
echo
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
mdev -s
mdadm --auto-detect
2022-06-02 09:40:43 +00:00
if [ -b /dev/sdb ]; then
DISKS="/dev/sda /dev/sdb"
BOOT_PART=/dev/md2
META_PART=/dev/md3
2022-06-02 09:40:43 +00:00
SWAP_PART=/dev/md1
ROOT_PART=/dev/md0
RAID=1
else
DISKS="/dev/sda"
BOOT_PART=/dev/sda1
META_PART=/dev/sda2
SWAP_PART=/dev/sda3
ROOT_PART=/dev/sda4
2022-06-02 09:40:43 +00:00
RAID=0
fi
ip link set eth0 up
udhcpc -i eth0
2023-07-25 04:42:42 +00:00
# /proc/cmdline parser (from Gentoo Wiki)
cmdline() {
local value
value=" $(cat /proc/cmdline) "
value="${value##* $1=}"
value="${value%% *}"
[ "$value" != "" ] && echo "$value"
}
2023-07-24 14:14:52 +00:00
# Retrieve metadata
wget -O /tmp/metadata.iso "$(ip r | grep default | awk '{ print $3 }')/fickit-metadata.iso"
mount /tmp/metadata.iso /mnt
/usr/bin/metadata -v file=/mnt/user-data
2023-07-24 14:14:52 +00:00
2023-07-25 04:42:42 +00:00
AUTOPREPARE=$(cmdline fickit.autoprepare)
if [ -z "${AUTOPREPARE}" ]
then
2023-07-25 04:42:42 +00:00
# Try to detect backend/frontend setup
if ip l | grep -q eth3
then
DEFAULT_BOOT=1
echo -n "Detected: FRONTEND host "
else
DEFAULT_BOOT=0
echo -n "Detected: BACKEND host "
fi
2023-07-25 04:42:42 +00:00
[ "${RAID}" -eq 1 ] && echo "with RAID setup" || echo "without raid"
2022-06-02 09:40:43 +00:00
2023-07-25 04:42:42 +00:00
echo
read -p "Proceed? (y/N/Front/Back) " V
if [ "$V" == "F" ] || [ "$V" == "f" ]; then
DEFAULT_BOOT=1
elif [ "$V" == "B" ] || [ "$V" == "b" ]; then
DEFAULT_BOOT=0
elif [ "$V" != "y" ]; then
while true; do
/bin/ash
done
fi
elif [ "${AUTOPREPARE}" == "backend" ]
then
2023-10-23 16:43:33 +00:00
DEFAULT_BOOT=0
2023-07-25 04:42:42 +00:00
elif [ "${AUTOPREPARE}" == "frontend" ]
then
2023-10-23 16:43:33 +00:00
DEFAULT_BOOT=1
2023-07-25 04:42:42 +00:00
else
echo
echo "Invalid fickit.autoprepare value: got $AUTOPREPARE, expected frontend or backend."
echo
while true; do
/bin/ash
done
fi
2022-06-02 09:40:43 +00:00
# Create partition table and boot records
for DISK in ${DISKS}
do
cat /etc/fdisk_cmd | fdisk "${DISK}" &&
cat /etc/sfdisk_schema | sfdisk --force "${DISK}" ||
/bin/ash
done
# Create RAID arrays
if [ "${RAID}" -eq 1 ]; then
/sbin/mdadm --create "${BOOT_PART}" --run --level=1 --metadata=1.0 --raid-devices=2 /dev/sda1 /dev/sdb1
/sbin/mdadm --create "${META_PART}" --run --level=1 --metadata=1.1 --raid-devices=2 /dev/sda2 /dev/sdb2
/sbin/mdadm --create "${SWAP_PART}" --run --level=1 --metadata=1.1 --raid-devices=2 /dev/sda3 /dev/sdb3
/sbin/mdadm --create "${ROOT_PART}" --run --level=1 --metadata=0 --raid-devices=2 /dev/sda4 /dev/sdb4
2022-06-02 09:40:43 +00:00
fi
2022-06-02 09:40:43 +00:00
# Format partitions
mkswap "${SWAP_PART}"
#mkfs.ext4 -F "${ROOT_PART}"
2023-07-24 14:14:52 +00:00
cryptsetup -q -s 512 luksFormat "${ROOT_PART}" /run/config/dm-crypt/key
cryptsetup luksOpen -d /run/config/dm-crypt/key "${ROOT_PART}" crypt_fic
mkfs.ext4 -F /dev/mapper/crypt_fic
sync
2022-06-02 09:40:43 +00:00
mkfs.vfat "${BOOT_PART}"
mkdir -p /boot
2022-06-02 09:40:43 +00:00
mount "${BOOT_PART}" /boot/ && {
for DISK in ${DISKS}
do
/root/install_grub ${DEFAULT_BOOT} "${DISK}"
done
/root/update_imgs "$(ip r | grep default | awk '{ print $3 }')" "${META_PART}"
} ||
/bin/ash
umount /boot &&
2022-06-02 09:40:43 +00:00
sync
2022-06-02 09:40:43 +00:00
echo "System is ready. You can now reboot."
/bin/ash
mode: "0755"
2018-12-10 01:16:07 +00:00
- path: root/update_imgs
source: configs/update_imgs.sh
mode: "0755"
2018-12-10 01:16:07 +00:00
- path: root/install_syslinux
contents: |
#!/bin/sh
mkdir -p /boot/EFI/boot /boot/imgs
[ $1 == "0" ] && ONTIMEOUT="backend" || ONTIMEOUT="frontend"
2018-12-10 01:16:07 +00:00
cd /usr/share/syslinux/efi64
cp ldlinux.e64 menu.c32 libcom32.c32 libutil.c32 vesamenu.c32 poweroff.c32 /boot/EFI/boot
cp syslinux.efi /boot/EFI/boot/bootx64.efi
cat <<EOF > /boot/syslinux.cfg
TIMEOUT 30
ONTIMEOUT ${ONTIMEOUT}
2018-12-10 01:16:07 +00:00
MENU background #00000000 * *
MENU color title * #FF22BBCC *
MENU color sel * #FFFFFFFF #FF22BBCC *
MENU color hotsel 1;7;37;40 #ffffffff #76a1d0ff *
UI vesamenu.c32
MENU TITLE Server FIC Challenge
LABEL backend
MENU LABEL FIC Backend
LINUX /imgs/fickit-boot-kernel
2018-12-10 01:16:07 +00:00
INITRD /imgs/fickit-boot-initrd.img
APPEND console=ttyS0 console=tty0 root=fickit-backend-squashfs.img
LABEL frontend
MENU LABEL FIC Frontend
LINUX /imgs/fickit-boot-kernel
2018-12-10 01:16:07 +00:00
INITRD /imgs/fickit-boot-initrd.img
APPEND console=ttyS0 console=tty0 root=fickit-frontend-squashfs.img
LABEL update
MENU LABEL Update images
LINUX /imgs/fickit-boot-kernel
2018-12-10 01:16:07 +00:00
INITRD /imgs/fickit-update-initrd.img
APPEND console=ttyS0 console=tty0
MENU SEPARATOR
LABEL poweroff
MENU LABEL ^Shutdown
KERNEL poweroff.c32
EOF
cp /usr/share/syslinux/libcom32.c32 /usr/share/syslinux/libutil.c32 /usr/share/syslinux/poweroff.c32 /usr/share/syslinux/vesamenu.c32 /boot/
shift
for p
do
# BIOS part
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/mbr.bin of=${p}
syslinux --install ${p}
done
mode: "0550"
- path: root/install_grub
contents: |
#!/bin/sh
mkdir -p /boot/EFI/boot /boot/grub /boot/imgs
cat <<EOF > /boot/grub/grub.cfg
set timeout=3
set default=$1
menuentry 'FIC Backend' {
set root=(hd0,1)
linux /imgs/fickit-boot-kernel console=ttyS0 console=tty0 quiet root=fickit-backend-squashfs.img
initrd /imgs/fickit-boot-initrd.img
}
menuentry 'FIC Frontend' {
set root=(hd0,1)
linux /imgs/fickit-boot-kernel console=ttyS0 console=tty0 quiet root=fickit-frontend-squashfs.img
initrd /imgs/fickit-boot-initrd.img
}
menuentry 'Update images' {
set root=(hd0,1)
linux /imgs/fickit-boot-kernel console=ttyS0 console=tty0 quiet
initrd /imgs/fickit-update-initrd.img
}
EOF
cp "/boot/grub/grub.cfg" "/boot/EFI/boot/grub.cfg"
shift
for p
do
grub-mkimage -o "/boot/EFI/boot/bootx64.efi" -p /efi/boot -O x86_64-efi fat iso9660 part_gpt part_msdos normal boot linux configfile loopback chain efifwsetup efi_gop efi_uga ls search search_label search_fs_uuid search_fs_file gfxterm gfxterm_background gfxterm_menu test all_video loadenv exfat ext2
grub-install --boot-directory="/boot/" --target=i386-pc "${p}"
2018-12-10 01:16:07 +00:00
done
mode: "0550"
- path: etc/sfdisk_schema
contents: |
2023-07-24 18:56:03 +00:00
,750M,U,*
,5M,L,-
,4G,S,-
2018-12-10 01:16:07 +00:00
,+,R,-
mode: "0440"
- path: etc/fdisk_cmd
contents: |
o
w
mode: "0440"