summaryrefslogtreecommitdiffstats
path: root/dev_tools/snippets.sh
diff options
context:
space:
mode:
authorjandob2015-11-05 14:47:19 +0100
committerjandob2015-11-05 14:47:19 +0100
commit5c56d85a65077e0c8e6230a5e092f17e6f2f2e0f (patch)
treeff61a9f9feda0e3fb99b96f044805a1a90ca8054 /dev_tools/snippets.sh
parentAdd device-mapper proof of concept to snippets. (diff)
downloadsystemd-init-5c56d85a65077e0c8e6230a5e092f17e6f2f2e0f.tar.gz
systemd-init-5c56d85a65077e0c8e6230a5e092f17e6f2f2e0f.tar.xz
systemd-init-5c56d85a65077e0c8e6230a5e092f17e6f2f2e0f.zip
added functions to create writable partitions from container devices
Diffstat (limited to 'dev_tools/snippets.sh')
-rw-r--r--dev_tools/snippets.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/dev_tools/snippets.sh b/dev_tools/snippets.sh
index 02cad0b2..36fc447d 100644
--- a/dev_tools/snippets.sh
+++ b/dev_tools/snippets.sh
@@ -54,3 +54,62 @@ losetup /dev/loop0 persistent_storage.img
fdisk -lu
losetup -o $((1050624*512)) /dev/loop0 /dev/nbd0 -v
mount /dev/loop0 /mnt/
+
+
+
+function create_partition_via_offset() {
+ local device="$1"
+ local nameOrUUID="$2"
+ local loopDevice=$(losetup -f)
+
+ #local sector_size=$(fdisk -l -u $device | grep "Sector size" | cut -d' ' -f4)
+ local sectorSize=$(blockdev --getbsz $device)
+ echo sector size: $sectorSize
+ local partitionInfo=$(partx --raw --noheadings --output START,NAME,UUID /dev/nbd0 2>/dev/null| grep $nameOrUUID)
+ local offsetSectors=$(echo $partitionInfo | cut -d' ' -f1)
+ if [ -z "$offsetSectors" ]; then
+ build_initramfs_log 'error' \
+ "could not find partition with label/uuid '$nameOrUUID' on device $device"
+ return 1
+ fi
+ #echo $(($offsetSectors*512)) # could overflow on 32bit systems
+ offsetBytes=$(echo $| awk -v x=$offsetSectors -v y=$sectorSize '{print x * y}')
+ echo $offsetBytes
+
+ # test if mount works directly (problem with btrfs device id)
+ #mount -v -o loop,offset=$offsetBytes $device $mountPoint
+ losetup -v -o $offsetBytes $loopDevice $device
+ echo $loopDevice
+}
+function make_partition_writable() {
+ local deviceName="$1"
+ local partition="$2"
+ local writable_device="$3"
+
+ local size=$(blockdev --getsz $partition)
+ dmsetup create "$deviceName" --table \
+ "0 $size snapshot $partition $writable_device N 1"
+ mount /dev/mapper/sandbox /mnt
+}
+function make_ram_device() {
+ mknod -m 660 /dev/ram0 b 1 1
+ chown root.disk /dev/ram0
+ echo /dev/ram0
+}
+function make_device_from_file() {
+ local file="$1"
+ local sizeInMegaByte="$2"
+ #modprobe loop
+ local loopDevice=$(losetup -f)
+ dd if=/dev/zero of="$file" bs=1M count=$sizeInMegaByte
+ losetup "$loopDevice" "$file"
+ mkfs.ext4 "$loopDevice"
+ echo $loopDevice
+}
+
+local partition=$(create_partition_via_offset "/dev/nbd0" "system")
+
+local writableDevice=$(make_device_from_file "persistent_storage.img" "50")
+local writableDevice=$(make_ram_device)
+make_partition_writable "sandbox" "$partition" "$writableDevice"
+mount /dev/mapper/sandbox $mountPoint