automate/loop-devices-in-docker.txt

34 lines
907 B
Plaintext

$ sudo losetup -f
/dev/loop28
$ sudo mknod /dev/loop28 b 7 28
$ sudo mount /mnt/loops/parity01.img /mnt/snapraid/parity01
-----
LOOPDEV=$(losetup --find --show --partscan ${IMAGE_FILE})
# drop the first line, as this is our LOOPDEV itself, but we only want the child partitions
PARTITIONS=$(lsblk --raw --output "MAJ:MIN" --noheadings ${LOOPDEV} | tail -n +2)
COUNTER=1
for i in $PARTITIONS; do
MAJ=$(echo $i | cut -d: -f1)
MIN=$(echo $i | cut -d: -f2)
if [ ! -e "${LOOPDEV}p${COUNTER}" ]; then mknod ${LOOPDEV}p${COUNTER} b $MAJ $MIN; fi
COUNTER=$((COUNTER + 1))
done
----
CAP=SYS_ADMIN or --privileged
In container:
apt update && apt install -y gdisk
dd if=/dev/zero of=/ofile.img bs=1M count=500
sgdisk -n 1:2048:194559 -n 2:195560:300000 /ofile.img
losetup -f /ofile.img -P --show
ls -l /dev/loop*
In host:
In host: see that partition files _have* been created: ls -l /dev/loop*