i want to create a bunch of “mock” block devices to mimic disks inside of a container. there is an odd situation where i can only mount one new loop per container start. so, the first one will create 1 new mount, and the rest will fail. if i stop and start the container it will mount the first one and one more new one and the rest will fail until my script is done mounting the needed devices.
in my image i have:
RUN mkdir -p /mnt/loops \
&& mkdir -p /mnt/snapraid/disk{00..03} \
&& mkdir -p /mnt/snapraid/parity{00..01} \
&& dd if=/dev/zero of=/mnt/loops/disk00.img bs=1 count=0 seek=200M \
&& dd if=/dev/zero of=/mnt/loops/disk01.img bs=1 count=0 seek=200M \
&& dd if=/dev/zero of=/mnt/loops/disk02.img bs=1 count=0 seek=200M \
&& dd if=/dev/zero of=/mnt/loops/disk03.img bs=1 count=0 seek=200M \
&& dd if=/dev/zero of=/mnt/loops/parity00.img bs=1 count=0 seek=250M \
&& dd if=/dev/zero of=/mnt/loops/parity01.img bs=1 count=0 seek=250M \
&& mkfs.ext4 -q /mnt/loops/disk00.img \
&& mkfs.ext4 -q /mnt/loops/disk01.img \
&& mkfs.ext4 -q /mnt/loops/disk02.img \
&& mkfs.ext4 -q /mnt/loops/disk03.img \
&& mkfs.ext4 -q /mnt/loops/parity00.img \
&& mkfs.ext4 -q /mnt/loops/parity01.img
at the top of my entry.sh
i have:
sudo mount /mnt/loops/disk00.img /mnt/snapraid/disk00
sudo mount /mnt/loops/disk01.img /mnt/snapraid/disk01
sudo mount /mnt/loops/disk02.img /mnt/snapraid/disk02
sudo mount /mnt/loops/disk03.img /mnt/snapraid/disk03
sudo mount /mnt/loops/parity00.img /mnt/snapraid/parity00
sudo mount /mnt/loops/parity01.img /mnt/snapraid/parity01
sudo chown -R deno:deno /mnt/snapraid/disk*
so the first container run you can see that disk00
mounts fine:
$ df -h
Filesystem Size Used Avail Use% Mounted on
…
/dev/loop24 178M 216K 164M 1% /mnt/snapraid/disk00
and the rest fail:
Creating devcontainer_app_1 … done
Attaching to devcontainer_app_1
app_1 | mount: /mnt/snapraid/disk01: failed to setup loop device for /mnt/loops/disk01.img.
app_1 | mount: /mnt/snapraid/disk02: failed to setup loop device for /mnt/loops/disk02.img.
app_1 | mount: /mnt/snapraid/disk03: failed to setup loop device for /mnt/loops/disk03.img.
app_1 | mount: /mnt/snapraid/parity00: failed to setup loop device for /mnt/loops/parity00.img.
app_1 | mount: /mnt/snapraid/parity01: failed to setup loop device for /mnt/loops/parity01.img.
then if i stop and restart the container i get 1 more device to properly mount, disk00
and disk01
:
$ df -h
Filesystem Size Used Avail Use% Mounted on
…
/dev/loop24 178M 216K 164M 1% /mnt/snapraid/disk00
/dev/loop25 178M 216K 164M 1% /mnt/snapraid/disk01
and the rest failing:
Creating devcontainer_app_1 … done
Attaching to devcontainer_app_1
app_1 | mount: /mnt/snapraid/disk02: failed to setup loop device for /mnt/loops/disk02.img.
app_1 | mount: /mnt/snapraid/disk03: failed to setup loop device for /mnt/loops/disk03.img.
app_1 | mount: /mnt/snapraid/parity00: failed to setup loop device for /mnt/loops/parity00.img.
app_1 | mount: /mnt/snapraid/parity01: failed to setup loop device for /mnt/loops/parity01.img.
as long as i run the container the same amount of times as requested mounts, ill end up with the required mounts inside the container. i can then run the container every time with everything mounting properly. once i reboot my pc, ill have to start the process all over again.