summaryrefslogtreecommitdiffstats
path: root/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
diff options
context:
space:
mode:
Diffstat (limited to 'builder/dnbd3-rootfs/hooks/prepare-root-partition.sh')
-rwxr-xr-xbuilder/dnbd3-rootfs/hooks/prepare-root-partition.sh48
1 files changed, 39 insertions, 9 deletions
diff --git a/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh b/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
index 71f70df2..20c06814 100755
--- a/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
+++ b/builder/dnbd3-rootfs/hooks/prepare-root-partition.sh
@@ -22,12 +22,6 @@ then
"'${persistent_device}'"
fi
-# persistent storage on a filesystem (e.g. usb stick)
-# writable_device="$(losetup --find)"
-#dd if=/dev/zero of=persistent_storage.img bs=1k count=1000
-#losetup "$writable_device" persistent_storage.img
-#persistent='P'
-
# TODO move somewhere else
#tmp_device="$(tools.find_block_device \
#'$SLX_TMP_PARTITION_IDENTIFIER')"
@@ -36,7 +30,43 @@ fi
#mount --type auto "$tmp_device" "$NEWROOT/tmp"
#fi
-persistent='N' # 'P' for persistent storage, 'N' for not persistent
+if [ -n "$SLX_WRITABLE_DEVICE_STORAGE_FILE" ] && [ -n "$persistent_device" ]
+then
+ persistent_mountpoint=/mnt/slx_writable_device
+ storage_file=$persistent_mountpoint/$SLX_WRITABLE_DEVICE_STORAGE_FILE
+ ! mkdir --parents $persistent_mountpoint
+ if ! mount --type auto "$persistent_device" "$persistent_mountpoint"; then
+ logging.warn "Failed to mount $persistent_device, checking filesystem"
+ ! $SLX_WRITABLE_DEVICE_STORAGE_FILSYSTEM_CHECK_COMMAND \
+ "$persistent_device"
+ if ! mount --type auto "$persistent_device" "$persistent_mountpoint"
+ then
+ logging.warn "Mounting $persistent_device, still failing," \
+ "creating new filesystem on device"
+ $SLX_WRITABLE_DEVICE_STORAGE_FILSYSTEM_CREATE_COMMAND \
+ "$persistent_device"
+ fi
+ if ! mount --type auto "$persistent_device" "$persistent_mountpoint"
+ then
+ logging.warn "Mounting $persistent_device, still failing," \
+ "giving up, and using ramdisk"
+ persistent_device=""
+ fi
+ fi
+ if [ -n "$persistent_device" ]; then
+ if [ ! -e "$storage_file" ]; then
+ # create sparse file
+ dd of="$storage_file" bs=1k \
+ seek="$SLX_WRITABLE_DEVICE_STORAGE_FILE_MAX_SIZE" count=0
+ fi
+ persistent_device="$(losetup --find)"
+ losetup "$persistent_device" "$storage_file"
+ fi
+fi
+
+# 'P' for persistent storage, 'N' for not persistent (affects dmsetup call,
+# see scripts/device-add-write-layer.sh)
+persistent='N'
if [ -n "$persistent_device" ]; then
writable_device="$persistent_device"
if [ "$SLX_WRITABLE_DEVICE_PERSISTENT" = "yes" ]; then
@@ -58,8 +88,6 @@ else
dd of="$ramdisk_location" seek="$ramdisk_size" count=0 1>/dev/null
writable_device="$(losetup --find)"
losetup "$writable_device" "$ramdisk_location"
- #
- persistent='N'
fi
@@ -108,6 +136,7 @@ fi
# region find read-only partition
if [ -z "$SLX_SYSTEM_PARTITION_PREPARATION_SCRIPT" ]; then
if [ -z "$SLX_SYSTEM_PARTITION_IDENTIFIER" ]; then
+ # if empty use whole device
read_only_partition="$read_only_device"
true
else
@@ -135,6 +164,7 @@ device-add-write-layer "root" "$read_only_partition" "$writable_device" \
}
exceptions.catch
{
+ type getarg >/dev/null 2>&1 || source /lib/dracut-lib.sh
emergency_shell "error in ${BASH_SOURCE[0]}"
}
# region vim modline