summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortorben2018-09-05 16:15:03 +0200
committertorben2018-09-05 16:15:03 +0200
commit7417303164fbcd9f25f9f042b429e98c5f657793 (patch)
tree759922ff7ec3dee52f55b6996c2344bb1203e39f
parentAdding logic to auto initialize boot partitions. (diff)
downloadsystemd-init-7417303164fbcd9f25f9f042b429e98c5f657793.tar.gz
systemd-init-7417303164fbcd9f25f9f042b429e98c5f657793.tar.xz
systemd-init-7417303164fbcd9f25f9f042b429e98c5f657793.zip
Improve boot partition installation.
-rwxr-xr-xmodules.d/dnbd-root-filesystem/hooks/prepare-root-filesystem.sh8
-rwxr-xr-xmodules.d/dnbd-root-filesystem/hooks/update-boot-files.sh137
2 files changed, 82 insertions, 63 deletions
diff --git a/modules.d/dnbd-root-filesystem/hooks/prepare-root-filesystem.sh b/modules.d/dnbd-root-filesystem/hooks/prepare-root-filesystem.sh
index 3cd49e00..8dae12dd 100755
--- a/modules.d/dnbd-root-filesystem/hooks/prepare-root-filesystem.sh
+++ b/modules.d/dnbd-root-filesystem/hooks/prepare-root-filesystem.sh
@@ -117,9 +117,7 @@ bl.exception.try {
## region find cache partition
local persistent_device
local identifier
- local IFS_backup="$IFS"
- IFS=', '
- for identifier in $SLX_WRITABLE_DEVICE_IDENTIFIER; do
+ for identifier in "${SLX_WRITABLE_DEVICE_IDENTIFIER[@]}"; do
if [[ "$identifier" != '' ]] && persistent_device="$(
bl.filesystem.find_block_device \
"$identifier" \
@@ -129,7 +127,6 @@ bl.exception.try {
break
fi
done
- IFS="$IFS_backup"
## endregion
if [[ "$persistent_device" = *' '* ]]; then
bl.logging.warn \
@@ -250,8 +247,6 @@ bl.exception.try {
# region connect dnbd
local read_only_devices=()
local layer
- local IFS_backup="$IFS"
- IFS=$'\n'
for layer in "${SLX_DNBD_LAYERS[@]}"; do
local dnbd_rid="$(
echo "$layer" | \
@@ -327,7 +322,6 @@ bl.exception.try {
SLX_DNBD_IMAGE="$dnbd_image"
fi
done
- IFS="$IFS_backup"
if \
$SLX_ACTIVATE_BACKGROUND_REPLICATION_AFTER_SWITCH_ROOT && \
[[ "$persistent_device" != '' ]]
diff --git a/modules.d/dnbd-root-filesystem/hooks/update-boot-files.sh b/modules.d/dnbd-root-filesystem/hooks/update-boot-files.sh
index 071bfdcc..a54b574b 100755
--- a/modules.d/dnbd-root-filesystem/hooks/update-boot-files.sh
+++ b/modules.d/dnbd-root-filesystem/hooks/update-boot-files.sh
@@ -4,17 +4,19 @@ source /usr/lib/configure-logging.sh
bl.module.import bashlink.path
bl.exception.try {
# region determine boot partition
- local kernel_file_path="$(
- cat /proc/cmdline | \
- sed --regexp-extended 's:^(BOOT_IMAGE=)?([^ ]+).+$:\2:' | \
- sed 's:\\:/:')"
+ local kernel_file_path=''
+ #local kernel_file_path="$(
+ # 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:\\:/:')"
+ local initramfs_file_path=''
+ #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
@@ -116,66 +118,89 @@ bl.exception.try {
fi
if [ -f /etc/openslx ] && ! $boot_partition_mounted; then
source /etc/openslx
- # TODO iterate through $SLX_INITIAL_BOOT_PARTITION_IDENTIFIER
- if \
- [[ "$SLX_INITIAL_BOOT_PARTITION_IDENTIFIER" != '' ]] && \
- mount "$SLX_INITIAL_BOOT_PARTITION_IDENTIFIER" /mnt \
- &>/dev/null
- then
- 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
+ local boot_partition_identifier
+ for boot_partition_identifier in "${SLX_INITIAL_BOOT_PARTITION_IDENTIFIER[@]}"; do
+ local device_partition_path="$boot_partition_identifier"
+ if fdisk --list | grep "$boot_partition_identifier" &>/dev/null; then
+ device_partition_path="$(
+ fdisk --list | \
+ grep "$boot_partition_identifier" | \
+ grep \
+ --extended-regexp \
+ --only-matching \
+ '^[^ ]+')"
+ fi
+ if mount "$device_partition_path" /mnt &>/dev/null; then
+ if [ -d /mnt/syslinux ]; then
+ boot_partition_mounted=true
+ break
+ elif $SLX_AUTO_INITIALIZE_BOOT_PARTITION; then
+ local device_path="$(
+ echo "$device_partition_path" | \
+ grep --extended-regexp --only-matching '^[^0-9]+')"
+ local device_partition_position="$(
+ echo "$device_partition_path" | \
+ grep --extended-regexp --only-matching '[0-9]+$')"
+ 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 \"$device_partition_path\".
+ sgdisk \
+ "$device_path" \
+ --attributes=1:set:"$device_partition_position"
bl.logging.info \
- Set the \"boot\" flag to mbr based boot partition.
- fdisk /dev/sda << EOF
+ Install MBR to gpt partition layout on \
+ \"$device_path\".
+ dd \
+ bs=440 \
+ count=1 \
+ conv=notrunc \
+ if=/usr/lib/syslinux/bios/gptmbr.bin \
+ of="$device_path" \
+ seek=TODO
+ else
+ if ! fdisk --list "$device_path" | \
+ grep "^$device_path +\*" &>/dev/null
+ then
+ bl.logging.info \
+ Set the \"boot\" flag to mbr based boot \
+ partition \"$device_partition_path\".
+ fdisk "$device_path" << EOF
a
-2
+$device_partition_position
w
EOF
+ fi
+ bl.logging.info \
+ Install MBR to gpt partition layout on \
+ \"$device_path\".
+ dd \
+ bs=440 \
+ count=1 \
+ conv=notrunc \
+ if=/usr/lib/syslinux/bios/mbr.bin \
+ of="$device_path"
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
+ 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
+ LINUX ../$kernel_file_path
+ APPEND $(cat /proc/cmdline)
+ INITRD ../$initramfs_file_path
EOF
- boot_partition_mounted=true
+ boot_partition_mounted=true
+ break
+ fi
fi
- elif $SLX_AUTO_INITIALIZE_BOOT_PARTITION; then
- bl.logging.info TODO make gdisk!
- #boot_partition_mounted=true
- fi
+ done
fi
if [ -f /etc/openslx ]; then
if $boot_partition_mounted && ! [ -f /mnt/openslx ]; then