summaryrefslogtreecommitdiffstats
path: root/dev-tools/snippets.sh
diff options
context:
space:
mode:
Diffstat (limited to 'dev-tools/snippets.sh')
-rw-r--r--dev-tools/snippets.sh113
1 files changed, 0 insertions, 113 deletions
diff --git a/dev-tools/snippets.sh b/dev-tools/snippets.sh
deleted file mode 100644
index 6f4f21cc..00000000
--- a/dev-tools/snippets.sh
+++ /dev/null
@@ -1,113 +0,0 @@
-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