summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortorben2018-09-05 14:57:34 +0200
committertorben2018-09-05 14:57:34 +0200
commitd1c74e2dcf75d2a056102d104d5c1d7674174739 (patch)
treee63b0b933bc40833f38f2b08b2a31b536d406009
parentfix. (diff)
downloadsystemd-init-d1c74e2dcf75d2a056102d104d5c1d7674174739.tar.gz
systemd-init-d1c74e2dcf75d2a056102d104d5c1d7674174739.tar.xz
systemd-init-d1c74e2dcf75d2a056102d104d5c1d7674174739.zip
Adding logic to auto initialize boot partitions.
-rwxr-xr-xmodules.d/dnbd-root-filesystem/hooks/update-boot-files.sh (renamed from modules.d/dnbd-root-filesystem/hooks/fetch-config.sh)62
-rwxr-xr-xmodules.d/dnbd-root-filesystem/module-setup.sh12
2 files changed, 70 insertions, 4 deletions
diff --git a/modules.d/dnbd-root-filesystem/hooks/fetch-config.sh b/modules.d/dnbd-root-filesystem/hooks/update-boot-files.sh
index da94242d..071bfdcc 100755
--- a/modules.d/dnbd-root-filesystem/hooks/fetch-config.sh
+++ b/modules.d/dnbd-root-filesystem/hooks/update-boot-files.sh
@@ -8,10 +8,16 @@ bl.exception.try {
cat /proc/cmdline | \
sed --regexp-extended 's:^(BOOT_IMAGE=)?([^ ]+).+$:\2:' | \
sed 's:\\:/:')"
+ if [ "$kernel_file_path" = '' ]; then
+ kernel_file_path=kernel
+ fi
local initramfs_file_path="$(
cat /proc/cmdline | \
sed --regexp-extended 's:^(.+ )?initrd=([^ ]+).*$:\2:' | \
sed 's:\\:/:')"
+ if [ "$initramfs_file_path" = '' ]; then
+ initramfs_file_path=initramfs
+ fi
mkdir --parents /mnt
local boot_partition_mounted=false
local device_name
@@ -110,13 +116,65 @@ bl.exception.try {
fi
if [ -f /etc/openslx ] && ! $boot_partition_mounted; then
source /etc/openslx
- # TODO maybe "a create if not exists" logic could make sende here.
+ # TODO iterate through $SLX_INITIAL_BOOT_PARTITION_IDENTIFIER
if \
[[ "$SLX_INITIAL_BOOT_PARTITION_IDENTIFIER" != '' ]] && \
mount "$SLX_INITIAL_BOOT_PARTITION_IDENTIFIER" /mnt \
&>/dev/null
then
- boot_partition_mounted=true
+ if [ -d /mnt/syslinux ]; then
+ boot_partition_mounted=true
+ elif $SLX_AUTO_INITIALIZE_BOOT_PARTITION && false; then
+ mkdir --parents /mnt/syslinux
+ #bl.logging.info Copy boot menu binaries to bootloader.
+ #cp /usr/lib/syslinux/boot/*.c32 /mnt/syslinux
+ bl.logging.info Install bootloader.
+ extlinux --install /mnt/syslinux
+ if false; then
+ bl.logging.info \
+ Set the \"legacy_boot\" flag to gpt based boot partition.
+ sgdisk /dev/sda --attributes=1:set:2
+ bl.logging.info Install MBR to gpt partition layout.
+ dd \
+ bs=440 \
+ count=1 \
+ conv=notrunc \
+ if=/usr/lib/syslinux/bios/gptmbr.bin \
+ of=/dev/sda \
+ seek=TODO
+ else
+ if ! fdisk --list /dev/sda | grep '^/dev/sda2 +\*' &>/dev/null; then
+ bl.logging.info \
+ Set the \"boot\" flag to mbr based boot partition.
+ fdisk /dev/sda << EOF
+a
+2
+w
+EOF
+ fi
+ bl.logging.info Install MBR to gpt partition layout.
+ dd \
+ bs=440 \
+ count=1 \
+ conv=notrunc \
+ if=/usr/lib/syslinux/bios/mbr.bin \
+ of=/dev/sda
+ fi
+ cat << EOF > /mnt/syslinux/syslinux.cfg
+PROMPT 1
+TIMEOUT 50
+DEFAULT arch
+
+LABEL arch
+ LINUX ../$kernel_file_path
+ APPEND $(cat /proc/cmdline)
+ INITRD ../$initramfs_file_path
+EOF
+ boot_partition_mounted=true
+ fi
+ elif $SLX_AUTO_INITIALIZE_BOOT_PARTITION; then
+ bl.logging.info TODO make gdisk!
+ #boot_partition_mounted=true
fi
fi
if [ -f /etc/openslx ]; then
diff --git a/modules.d/dnbd-root-filesystem/module-setup.sh b/modules.d/dnbd-root-filesystem/module-setup.sh
index f28c8102..388276e6 100755
--- a/modules.d/dnbd-root-filesystem/module-setup.sh
+++ b/modules.d/dnbd-root-filesystem/module-setup.sh
@@ -231,7 +231,7 @@ install() {
inst_hook pre-udev 00 "$moddir/hooks/load-custom-kernel-modules.sh"
# Get the openslx config from the servers configured in the kernel command
# line (${SLX_SERVER}/${SLX_SERVER_BASE}/config).
- inst_hook pre-mount 10 "$moddir/hooks/fetch-config.sh"
+ inst_hook pre-mount 10 "$moddir/hooks/update-boot-files.sh"
# make the final blockdevice for the root system (dnbd -> xmount ->
# device-mapper)
if dracut_module_included systemd-initrd; then
@@ -295,7 +295,15 @@ install() {
pgrep pkill killall \
losetup lsblk \
mkfifo mkfs.ext4 \
- kexec
+ kexec \
+ fdisk \
+ gdisk \
+ syslinux \
+ extlinux \
+ sgdisk \
+ /usr/lib/syslinux/bios/gptmbr.bin \
+ /usr/lib/syslinux/bios/mbr.bin
+ #/usr/lib/syslinux/boot/*.c32 \
}
# endregion
# region vim modline