fickit: Handle raid and non-raid setup

This commit is contained in:
nemunaire 2022-06-02 11:40:43 +02:00
parent f61b0a8e47
commit 152bbe178f
5 changed files with 94 additions and 31 deletions

View File

@ -12,9 +12,9 @@ init:
- nemunaire/mdadm:3886edd37c79d5f8000e4f3c4bacaff1f6302aa3
onboot:
# - name: mod
# image: linuxkit/modprobe:1b59b4f2ebb877085ea0d8d3a41cf06f64c09a15
# command: ["/bin/sh", "-c", "modprobe e1000e"]
- name: mod
image: linuxkit/modprobe:1b59b4f2ebb877085ea0d8d3a41cf06f64c09a15
command: ["/bin/sh", "-c", "modprobe xhci_pci ahci intel_lpss_pci i2c_i801 megaraid_sas tg3 bnxt_en"]
- name: sysctl
image: linuxkit/sysctl:bdc99eeedc224439ff237990ee06e5b992c8c1ae
@ -24,10 +24,10 @@ onboot:
# Filesystem
- name: swap
image: linuxkit/swap:77305236719ed7ab4be0f3bccc179c583fe7f5ff
command: ["/sbin/swapon", "/dev/md1"]
command: ["/sbin/swapon", "/dev/sda2"]
- name: dm-crypt
image: linuxkit/dm-crypt:908d3a270650aff7388092a307673c44d86e1ed0
command: ["/usr/bin/crypto", "-l", "crypt_fic", "/dev/md0"]
command: ["/usr/bin/crypto", "-l", "crypt_fic", "/dev/sda3"]
- name: mount
image: linuxkit/mount:422b219bb1c7051096126ac83e6dcc8b2f3f1176
command: ["/usr/bin/mountie", "-device", "/dev/mapper/crypt_fic", "/var/lib/fic" ]

View File

@ -13,9 +13,9 @@ init:
- nemunaire/fic-frontend-ui:latest
onboot:
# - name: mod
# image: linuxkit/modprobe:1b59b4f2ebb877085ea0d8d3a41cf06f64c09a15
# command: ["/bin/sh", "-c", "modprobe r8169;"]
- name: mod
image: linuxkit/modprobe:1b59b4f2ebb877085ea0d8d3a41cf06f64c09a15
command: ["/bin/sh", "-c", "modprobe xhci_pci ahci intel_lpss_pci i2c_i801 megaraid_sas tg3 bnxt_en"]
- name: sysctl
image: linuxkit/sysctl:bdc99eeedc224439ff237990ee06e5b992c8c1ae
@ -23,10 +23,10 @@ onboot:
# Filesystem
- name: swap
image: linuxkit/swap:77305236719ed7ab4be0f3bccc179c583fe7f5ff
command: ["/sbin/swapon", "/dev/md1"]
command: ["/sbin/swapon", "/dev/sda2"]
- name: dm-crypt
image: linuxkit/dm-crypt:908d3a270650aff7388092a307673c44d86e1ed0
command: ["/usr/bin/crypto", "-l", "crypt_fic", "/dev/md0"]
command: ["/usr/bin/crypto", "-l", "crypt_fic", "/dev/sda3"]
- name: mount
image: linuxkit/mount:422b219bb1c7051096126ac83e6dcc8b2f3f1176
command: ["/usr/bin/mountie", "-device", "/dev/mapper/crypt_fic", "/var/lib/fic" ]

View File

@ -9,6 +9,14 @@ cmdline() {
[ "$value" != "" ] && echo "$value"
}
modprobe xhci_pci
modprobe ahci
modprobe intel_lpss_pci
modprobe i2c_i801
modprobe megaraid_sas
modprobe tg3
modprobe bnxt_en
mount -t devtmpfs none /dev
mount -t proc none /proc

View File

@ -15,6 +15,17 @@ files:
- path: /init
contents: |
#!/bin/sh
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
@ -22,6 +33,20 @@ files:
mdev -s
mdadm --auto-detect
if [ -b /dev/sdb ]; then
DISKS="/dev/sda /dev/sdb"
BOOT_PART=/dev/md2
SWAP_PART=/dev/md1
ROOT_PART=/dev/md0
RAID=1
else
DISKS="/dev/sda"
BOOT_PART=/dev/sda1
SWAP_PART=/dev/sda2
ROOT_PART=/dev/sda3
RAID=0
fi
ip a add 10.10.10.5/29 dev eth0
ip link set eth0 up
@ -29,12 +54,15 @@ files:
if ip l | grep eth3 > /dev/null
then
DEFAULT_BOOT=1
echo "Detected: FRONTEND host"
echo -n "Detected: FRONTEND host "
else
DEFAULT_BOOT=0
echo "Detected: BACKEND host"
echo -n "Detected: BACKEND host "
fi
[ "${RAID}" -eq 1 ] && echo "with RAID setup" || echo "without raid"
echo
read -p "Proceed? (y/N/Front/Back) " V
if [ "$V" == "F" ] || [ "$V" == "f" ]; then
DEFAULT_BOOT=1
@ -46,35 +74,45 @@ files:
done
fi
cat /etc/fdisk_cmd | fdisk /dev/sda &&
cat /etc/fdisk_cmd | fdisk /dev/sdb &&
cat /etc/sfdisk_schema | sfdisk --force /dev/sda &&
cat /etc/sfdisk_schema | sfdisk --force /dev/sdb
# 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
/sbin/mdadm --create /dev/md2 --run --level=1 --metadata=1.0 --raid-devices=2 /dev/sda1 /dev/sdb1
/sbin/mdadm --create /dev/md1 --run --level=1 --metadata=1.1 --raid-devices=2 /dev/sda2 /dev/sdb2
/sbin/mdadm --create /dev/md0 --run --level=1 --metadata=0 --raid-devices=2 /dev/sda3 /dev/sdb3
# 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 "${SWAP_PART}" --run --level=1 --metadata=1.1 --raid-devices=2 /dev/sda2 /dev/sdb2
/sbin/mdadm --create "${ROOT_PART}" --run --level=1 --metadata=0 --raid-devices=2 /dev/sda3 /dev/sdb3
fi
mkswap /dev/md1
#mkfs.ext4 -F /dev/md0
cryptsetup -q -s 512 luksFormat /dev/md0 /etc/dm-crypt/key
cryptsetup luksOpen -d /etc/dm-crypt/key /dev/md0 crypt_fic
# Format partitions
mkswap "${SWAP_PART}"
#mkfs.ext4 -F "${ROOT_PART}"
cryptsetup -q -s 512 luksFormat "${ROOT_PART}" /etc/dm-crypt/key
cryptsetup luksOpen -d /etc/dm-crypt/key "${ROOT_PART}" crypt_fic
mkfs.ext4 -F /dev/mapper/crypt_fic
sync
mkfs.vfat /dev/md2
mkfs.vfat "${BOOT_PART}"
mkdir -p /boot
mount /dev/md2 /boot/ && {
/root/install_grub ${DEFAULT_BOOT} /dev/sda /dev/sdb
mount "${BOOT_PART}" /boot/ && {
for DISK in ${DISKS}
do
/root/install_grub ${DEFAULT_BOOT} "${DISK}"
done
/root/update_imgs
} ||
/bin/ash
umount /boot &&
sync &&
reboot -f
sync
echo "System is ready. You can now reboot."
/bin/ash
mode: "0755"

View File

@ -13,13 +13,30 @@ files:
- path: /init
contents: |
#!/bin/sh -x
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
mdadm --assemble /dev/md2 /dev/sd*1
if [ -b /dev/sdb ]; then
mdadm --auto-detect
mdadm --assemble /dev/md2 /dev/sd*1
BOOT_PART=/dev/md2
else
BOOT_PART=/dev/sda1
fi
ip a add 10.10.10.5/29 dev eth0
ip link set eth0 up
@ -39,7 +56,7 @@ files:
/bin/ash
done
mount /dev/md2 /boot/ &&
mount "${BOOT_PART}" /boot/ &&
/root/update_imgs ||
/bin/ash