diff options
author | torben | 2015-11-05 15:32:34 +0100 |
---|---|---|
committer | torben | 2015-11-05 15:32:34 +0100 |
commit | d93a1fd23ce8f0a157d251aa74a6e76b9ac1c046 (patch) | |
tree | fad8f39c0ac491d73739c3710d8082ffd9dbec8c /dev-tools | |
parent | Remove deprecated files. (diff) | |
download | systemd-init-d93a1fd23ce8f0a157d251aa74a6e76b9ac1c046.tar.gz systemd-init-d93a1fd23ce8f0a157d251aa74a6e76b9ac1c046.tar.xz systemd-init-d93a1fd23ce8f0a157d251aa74a6e76b9ac1c046.zip |
Refactoring.
Diffstat (limited to 'dev-tools')
-rw-r--r-- | dev-tools/snippets.sh | 113 | ||||
-rwxr-xr-x | dev-tools/startup.nsh | 5 |
2 files changed, 118 insertions, 0 deletions
diff --git a/dev-tools/snippets.sh b/dev-tools/snippets.sh new file mode 100644 index 00000000..6f4f21cc --- /dev/null +++ b/dev-tools/snippets.sh @@ -0,0 +1,113 @@ +su nobody -s /bin/bash +yaourt -S multipath-tools +exit + +# close running connection +./dnbd3-client -d /dev/dnbd0 -c + +# 1. connect to dnbd3 server +cd dnbd3/build +insmod dnbd3.ko +./dnbd3-client -h gateway -i archLinux.qcow2 -d /dev/dnbd0 + +# 2. make available partition in qemu container +modprobe nbd +qemu-nbd --connect=/dev/nbd0 /dev/dnbd0 --read-only + +# 2. make available partition in qemu container (writable) +# qemu-nbd --connect=/dev/nbd0 /dev/dnbd0 --snapshot +# todo where is the cow device? +# todo why does --partition not work? +# todo use qemu-img instead? + +# 3. mount container partition +modprobe dm_multipath +kpartx -av /dev/nbd0 # or use fdisk -l and mount offset +mount /dev/mapper/nbd0p2 /mnt/ + +# 5. cleanup +umount /mnt/ +kpartx -d /dev/nbd0 +qemu-nbd --disconnect /dev/nbd0 + + +# mount container partition directly +# yaourt -S libguestfs +guestmount -a /dev/dnbd0 -m /dev/sda2 --ro /mnt -v + + +# make read-only partition writable +mknod -m 660 /dev/ram0 b 1 1 +chown root.disk /dev/ram0 +DEV=/dev/mapper/nbd0p2 +SIZE=`blockdev --getsz $DEV` +dmsetup create sandbox --table "0 $SIZE snapshot $DEV /dev/ram0 N 1" +mount /dev/mapper/sandbox /mnt +umount /mnt +dmsetup remove sandbox + +modprobe loop +dd if=/dev/zero of=persistent_storage.img bs=1k count=1000 +losetup /dev/loop0 persistent_storage.img + +# Mount second partion example. +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 diff --git a/dev-tools/startup.nsh b/dev-tools/startup.nsh new file mode 100755 index 00000000..197beb46 --- /dev/null +++ b/dev-tools/startup.nsh @@ -0,0 +1,5 @@ +if exist fs0:\debug then + rm fs0:\debug + \vmlinuz-linux initrd=\initramfs-4.2.2-1-ARCH.img root=PARTLABEL=system rw rootflags=subvol=root quiet loglevel=2 acpi_osi="!Windows 2012" +endif +\vmlinuz-linux initrd=\initramfs-linux.img root=PARTLABEL=system rw rootflags=subvol=root quiet loglevel=2 acpi_osi="!Windows 2012" |