summaryrefslogtreecommitdiffstats
path: root/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
diff options
context:
space:
mode:
authortorben2016-01-28 17:22:46 +0100
committertorben2016-01-28 17:22:46 +0100
commitbed90c1c45ab9956756813a8596410d18143de78 (patch)
tree330310d7750c7d91af33641d8e23b7f040aa5aca /builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
parentImprove debugging configurations. (diff)
downloadsystemd-init-bed90c1c45ab9956756813a8596410d18143de78.tar.gz
systemd-init-bed90c1c45ab9956756813a8596410d18143de78.tar.xz
systemd-init-bed90c1c45ab9956756813a8596410d18143de78.zip
CentOS now supported!
Diffstat (limited to 'builder/dnbd3-rootfs/hooks/prepare-root-partition.sh')
-rwxr-xr-xbuilder/dnbd3-rootfs/hooks/prepare-root-partition.sh109
1 files changed, 57 insertions, 52 deletions
diff --git a/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh b/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
index c527062a..be327555 100755
--- a/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
+++ b/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
@@ -14,6 +14,46 @@ logging.set_log_level debug
SLX_SERVER_BASE="$(getargs slxbase=)"
source /etc/openslx
+# region find writable partition
+if ! persistent_device=$(utils.find_block_device \
+ "$SLX_WRITABLE_DEVICE_IDENTIFIER"); then
+ logging.warn "Failed to find unique device with identifier" \
+ "'${SLX_WRITABLE_DEVICE_IDENTIFIER}'; matched devices:" \
+ "'${persistent_device}'"
+fi
+
+# TODO move somewhere else
+#tmp_device="$(utils.find_block_device \
+ #'$SLX_TMP_PARTITION_IDENTIFIER')"
+
+#if [ -n $tmp_device ]; then
+ #mount --type auto "$tmp_device" "$NEWROOT/tmp"
+#fi
+
+persistent='N' # 'P' for persistent storage, 'N' for not persistent
+if [ -n "$persistent_device" ]; then
+ writable_device="$persistent_device"
+ if [ "$SLX_WRITABLE_DEVICE_PERSISTENT" = "yes" ]; then
+ persistent='P'
+ fi
+else
+ ramdisk_size="$SLX_RAMDISK_SIZE"
+ if [ "$ramdisk_size" = "" ]; then
+ ramdisk_size="$(cat /proc/meminfo | awk '/MemTotal/ {print $2}')"
+ fi
+ modprobe brd max_part=1 rd_size="$ramdisk_size"
+ writable_device='/dev/ram0'
+ persistent='N'
+fi
+
+# persistent storage on a filesystem (e.g. usb stick)
+# writable_device="$(losetup -f)"
+#dd if=/dev/zero of=persistent_storage.img bs=1k count=1000
+#losetup "$writable_device" persistent_storage.img
+#persistent='P'
+
+# endregion
+
# region connect dnbd3
IFS_backup="$IFS"
IFS=","
@@ -50,7 +90,7 @@ else
loop_device="$(losetup --find)"
losetup "$loop_device" "$SLX_DNBD3_DEVICE" --partscan
read_only_device="$loop_device"
- touch $read_only_device
+ touch "$read_only_device"
udevadm settle
fi
# Fail fast if no device could be determined.
@@ -58,64 +98,29 @@ fi
# endregion
# region find read-only partition
-for i in 0.5 1 2; do
- if read_only_partition=$(utils.find_block_device \
- "$SLX_SYSTEM_PARTITION_IDENTIFIER" "$read_only_device"); then
- break
- else
- logging.warn "Failed to find unique device with identifier" \
- "'${SLX_SYSTEM_PARTITION_IDENTIFIER}'; matched devices:" \
- "'${read_only_partition}'"
- sleep $i
- fi
-done
-# endregion
-
-# region find writable partition
-if ! persistent_device=$(utils.find_block_device \
- "$SLX_WRITABLE_DEVICE_IDENTIFIER"); then
- logging.warn "Failed to find unique device with identifier" \
- "'${SLX_WRITABLE_DEVICE_IDENTIFIER}'; matched devices:" \
- "'${persistent_device}'"
-fi
-
-# TODO move somewhere else
-#tmp_device="$(utils.find_block_device \
- #'$SLX_TMP_PARTITION_IDENTIFIER')"
-
-#if [ -n $tmp_device ]; then
- #mount --type auto "$tmp_device" "$NEWROOT/tmp"
-#fi
-
-persistent='N' # 'P' for persistent storage, 'N' for not persistent
-if [ -n "$persistent_device" ]; then
- writable_device="$persistent_device"
- if [ "$SLX_WRITABLE_DEVICE_PERSISTENT" = "yes" ]; then
- persistent='P'
- fi
+if [ -z "$SLX_SYSTEM_PARTITION_PREPARATION_SCRIPT" ]; then
+ read_only_partition="$(utils.find_block_device \
+ "$SLX_SYSTEM_PARTITION_IDENTIFIER" "$read_only_device")"
else
- ramdisk_size="$SLX_RAMDISK_SIZE"
- if [ "$ramdisk_size" = "" ]; then
- ramdisk_size="$(cat /proc/meminfo | awk '/MemTotal/ {print $2}')"
- fi
- modprobe brd max_part=1 rd_size="$ramdisk_size"
- writable_device='/dev/ram0'
- persistent='N'
+ logging.plain
+ logging.plain "$SLX_SYSTEM_PARTITION_PREPARATION_SCRIPT"
+ logging.plain
+ eval "$SLX_SYSTEM_PARTITION_PREPARATION_SCRIPT"
+fi
+if [[ ! $? || -z "$read_only_partition" ]]; then
+ logging.error "Failed to find unique device with identifier" \
+ "\"${SLX_SYSTEM_PARTITION_IDENTIFIER}\"; matched devices:" \
+ "\"${read_only_partition}\""
+ exit 1
fi
-
-# persistent storage on a filesystem (e.g. usb stick)
-# writable_device="$(losetup -f)"
-#dd if=/dev/zero of=persistent_storage.img bs=1k count=1000
-#losetup "$writable_device" persistent_storage.img
-#persistent='P'
-
# endregion
-logging.info "Using read-only device: $read_only_partition"
+logging.info "Using read-only partition: $read_only_partition"
logging.info "Using writable device $writable_device, persistency: $persistent"
# combine devices with device mapper
-device-add-write-layer "root" "$read_only_partition" "$writable_device" "$persistent"
+device-add-write-layer "root" "$read_only_partition" "$writable_device" \
+ "$persistent"
) || exit $?
exceptions.deactivate