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
|
2024-01-29 13:26:29 +00:00
|
|
|
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
|
2020-01-30 18:00:46 +00:00
|
|
|
- alpine:latest
|
2018-12-10 01:16:07 +00:00
|
|
|
|
|
|
|
files:
|
2020-01-30 18:00:46 +00:00
|
|
|
- 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
|
|
|
|
|
2020-01-30 18:00:46 +00:00
|
|
|
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
|
2023-07-24 17:05:35 +00:00
|
|
|
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
|
2023-07-24 17:05:35 +00:00
|
|
|
META_PART=/dev/sda2
|
|
|
|
SWAP_PART=/dev/sda3
|
|
|
|
ROOT_PART=/dev/sda4
|
2022-06-02 09:40:43 +00:00
|
|
|
RAID=0
|
|
|
|
fi
|
|
|
|
|
2020-01-30 18:00:46 +00:00
|
|
|
ip link set eth0 up
|
2022-06-02 10:02:38 +00:00
|
|
|
udhcpc -i eth0
|
2020-01-30 18:00:46 +00:00
|
|
|
|
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
|
2023-07-24 17:05:35 +00:00
|
|
|
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}" ]
|
2020-01-30 18:00:46 +00:00
|
|
|
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
|
2020-01-30 18:00:46 +00:00
|
|
|
|
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
|
|
|
|
|
2021-09-04 18:50:56 +00:00
|
|
|
while true; do
|
|
|
|
/bin/ash
|
|
|
|
done
|
|
|
|
fi
|
2020-01-30 18:00:46 +00:00
|
|
|
|
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
|
2023-07-24 17:05:35 +00:00
|
|
|
/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
|
2020-01-30 18:00:46 +00:00
|
|
|
|
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
|
2020-01-30 18:00:46 +00:00
|
|
|
mkfs.ext4 -F /dev/mapper/crypt_fic
|
|
|
|
sync
|
|
|
|
|
2022-06-02 09:40:43 +00:00
|
|
|
mkfs.vfat "${BOOT_PART}"
|
2020-01-30 18:00:46 +00:00
|
|
|
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
|
2023-10-23 15:32:40 +00:00
|
|
|
/root/update_imgs "$(ip r | grep default | awk '{ print $3 }')" "${META_PART}"
|
2020-01-30 18:00:46 +00:00
|
|
|
} ||
|
|
|
|
/bin/ash
|
|
|
|
|
|
|
|
umount /boot &&
|
2022-06-02 09:40:43 +00:00
|
|
|
sync
|
2020-01-30 18:00:46 +00:00
|
|
|
|
2022-06-02 09:40:43 +00:00
|
|
|
echo "System is ready. You can now reboot."
|
2020-01-30 18:00:46 +00:00
|
|
|
/bin/ash
|
|
|
|
mode: "0755"
|
|
|
|
|
2018-12-10 01:16:07 +00:00
|
|
|
- path: root/update_imgs
|
|
|
|
source: configs/update_imgs.sh
|
|
|
|
mode: "0755"
|
2020-01-30 18:00:46 +00:00
|
|
|
|
2018-12-10 01:16:07 +00:00
|
|
|
- path: root/install_syslinux
|
|
|
|
contents: |
|
|
|
|
#!/bin/sh
|
|
|
|
mkdir -p /boot/EFI/boot /boot/imgs
|
2020-01-30 18:00:46 +00:00
|
|
|
|
|
|
|
[ $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
|
2020-01-30 18:00:46 +00:00
|
|
|
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
|
2023-10-22 10:47:44 +00:00
|
|
|
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
|
2023-10-22 10:47:44 +00:00
|
|
|
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
|
2023-10-22 10:47:44 +00:00
|
|
|
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/
|
|
|
|
|
2020-01-30 18:00:46 +00:00
|
|
|
shift
|
|
|
|
for p
|
|
|
|
do
|
|
|
|
# BIOS part
|
|
|
|
dd bs=440 conv=notrunc count=1 if=/usr/share/syslinux/mbr.bin of=${p}
|
|
|
|
syslinux --install ${p}
|
2019-01-21 03:32:50 +00:00
|
|
|
done
|
|
|
|
mode: "0550"
|
|
|
|
- path: root/install_grub
|
|
|
|
contents: |
|
|
|
|
#!/bin/sh
|
2020-01-30 18:00:46 +00:00
|
|
|
mkdir -p /boot/EFI/boot /boot/grub /boot/imgs
|
|
|
|
|
2019-01-21 03:32:50 +00:00
|
|
|
cat <<EOF > /boot/grub/grub.cfg
|
|
|
|
set timeout=3
|
2020-01-30 18:00:46 +00:00
|
|
|
set default=$1
|
2019-01-21 03:32:50 +00:00
|
|
|
|
|
|
|
menuentry 'FIC Backend' {
|
|
|
|
set root=(hd0,1)
|
2023-10-22 10:47:44 +00:00
|
|
|
linux /imgs/fickit-boot-kernel console=ttyS0 console=tty0 quiet root=fickit-backend-squashfs.img
|
2019-01-21 03:32:50 +00:00
|
|
|
initrd /imgs/fickit-boot-initrd.img
|
|
|
|
}
|
|
|
|
|
|
|
|
menuentry 'FIC Frontend' {
|
|
|
|
set root=(hd0,1)
|
2023-10-22 10:47:44 +00:00
|
|
|
linux /imgs/fickit-boot-kernel console=ttyS0 console=tty0 quiet root=fickit-frontend-squashfs.img
|
2019-01-21 03:32:50 +00:00
|
|
|
initrd /imgs/fickit-boot-initrd.img
|
|
|
|
}
|
|
|
|
|
|
|
|
menuentry 'Update images' {
|
|
|
|
set root=(hd0,1)
|
2023-10-22 10:47:44 +00:00
|
|
|
linux /imgs/fickit-boot-kernel console=ttyS0 console=tty0 quiet
|
2019-01-21 03:32:50 +00:00
|
|
|
initrd /imgs/fickit-update-initrd.img
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
cp "/boot/grub/grub.cfg" "/boot/EFI/boot/grub.cfg"
|
|
|
|
|
2020-01-30 18:00:46 +00:00
|
|
|
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"
|