summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjandob2016-03-21 14:09:57 +0100
committerjandob2016-03-21 14:09:57 +0100
commitd6aba62f1fecffc19ebb55f354abadcb4fb24670 (patch)
tree41c9f67d8199926a0750a6a6c2efeeda7b682fee
parentadd Feature #834 (diff)
downloadsystemd-init-d6aba62f1fecffc19ebb55f354abadcb4fb24670.tar.gz
systemd-init-d6aba62f1fecffc19ebb55f354abadcb4fb24670.tar.xz
systemd-init-d6aba62f1fecffc19ebb55f354abadcb4fb24670.zip
add Feature #835
-rwxr-xr-xbuilder/build-initramfs.sh3
-rwxr-xr-xbuilder/dnbd3-rootfs/hooks/prepare-root-partition.sh48
-rwxr-xr-xbuilder/dnbd3-rootfs/module-setup.sh6
-rwxr-xr-xbuilder/dnbd3-rootfs/scripts/container-unpack-xmount.sh7
-rwxr-xr-xbuilder/dnbd3-rootfs/scripts/device-add-write-layer.sh1
-rw-r--r--dev-tools/example-openslx.config7
6 files changed, 56 insertions, 16 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh
index 746eb1aa..a20884dc 100755
--- a/builder/build-initramfs.sh
+++ b/builder/build-initramfs.sh
@@ -87,7 +87,8 @@ declare -A core_dependencies=(
declare -A optional_dependencies=(
[chroot]='build against a distribution other than this program runs in' \
['curl git gzip tar']='dynamically retrieve and unpack missing application which will be compiled for current or given kernel' \
- [qemu-img]='support template systems in container (usually used by virtual runtime environments')
+ [qemu-img]='support template systems in container (usually used by virtual runtime environments' \
+ ['mkfs.ext4 fsck']='support for persistent binary diffs in image files')
# shellcheck disable=SC2034
declare -A core_shared_library_pattern_dependencies=(
[libz]='compile dnbd3 for given or current kernel')
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
diff --git a/builder/dnbd3-rootfs/module-setup.sh b/builder/dnbd3-rootfs/module-setup.sh
index ccffabb6..9d1ad549 100755
--- a/builder/dnbd3-rootfs/module-setup.sh
+++ b/builder/dnbd3-rootfs/module-setup.sh
@@ -176,8 +176,7 @@ install() {
'
# region binaries
inst "$moddir/binaries/dnbd3/build/dnbd3-client" /usr/bin/dnbd3-client
- inst \
- "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" \
+ inst "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" \
/usr/bin/systemd-preserve-process-marker
inst "$moddir/scripts/device-add-write-layer.sh" \
/usr/bin/device-add-write-layer
@@ -260,7 +259,8 @@ install() {
qemu-img \
sed sleep sort \
touch tr \
- wget
+ wget \
+ mkfs.ext4 fsck.ext4
}
# endregion
# region vim modline
diff --git a/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh b/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh
index 802c4e2f..49bb7418 100755
--- a/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh
+++ b/builder/dnbd3-rootfs/scripts/container-unpack-xmount.sh
@@ -7,10 +7,11 @@ exceptions.activate
# endregion
in_device="$1"
-mkdir /mnt
-systemd-preserve-process-marker xmount --in qemu $in_device --out raw /mnt
+mkdir --parents /mnt/xmount
+systemd-preserve-process-marker xmount --in qemu "$in_device" --out raw \
+ /mnt/xmount
loop_device="$(losetup --find)"
-losetup "$loop_device" /mnt/*.dd --partscan
+losetup "$loop_device" /mnt/xmount/*.dd --partscan
udevadm settle
echo "$loop_device"
diff --git a/builder/dnbd3-rootfs/scripts/device-add-write-layer.sh b/builder/dnbd3-rootfs/scripts/device-add-write-layer.sh
index 4125ba45..2e4116a7 100755
--- a/builder/dnbd3-rootfs/scripts/device-add-write-layer.sh
+++ b/builder/dnbd3-rootfs/scripts/device-add-write-layer.sh
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# region imports
+# shellcheck source=./rebash/core.sh
source "/usr/lib/rebash/core.sh"
core.import exceptions
exceptions.activate
diff --git a/dev-tools/example-openslx.config b/dev-tools/example-openslx.config
index 9a02d197..eb6dd218 100644
--- a/dev-tools/example-openslx.config
+++ b/dev-tools/example-openslx.config
@@ -3,9 +3,16 @@ SLX_DNBD3_SERVERS='132.230.4.201,132.230.4.202,10.0.2.2'
SLX_DNBD3_RID='0'
SLX_DNBD3_DEVICE='/dev/dnbd0'
SLX_DNBD3_IMAGE='archLinux/archLinux.vmdk'
+# If empty the whole device is used
SLX_SYSTEM_PARTITION_IDENTIFIER='system'
SLX_TMP_PARTITION_IDENTIFIER=''
SLX_WRITABLE_DEVICE_IDENTIFIER=''
+SLX_WRITABLE_DEVICE_STORAGE_FILE='storage.img'
+# NOTE: if the filesystem is any other than ext4, then the corresponding
+# filesystem tools have to be added to the initramfs manually. (use the dracut
+# --install parameter)
+SLX_WRITABLE_DEVICE_STORAGE_FILSYSTEM_CREATE_COMMAND='mkfs.ext4'
+SLX_WRITABLE_DEVICE_STORAGE_FILSYSTEM_CHECK_COMMAND='fsck.ext4'
SLX_WRITABLE_DEVICE_PERSISTENT='yes'
# if empty will use all available ram
SLX_RAMDISK_SIZE=''