4

I am trying to update a custom initramfs init script to mount a squashfs image as the root file system. I have been testing the mounting of a squash image to a loop device in read only, mounting another empty file to another loop device in read-write, and using device mapper to create a rw snapshot of the ro loop device.

I've made it this far with my test script (running as root):

mkdir /tmp/squash_rw
dev=$(losetup -f)
losetup -r $dev /mcp_fs.sqsh
ovl=/overlay
newdevname=overlay
size=$(blockdev --getsz "$dev")
loop=$(losetup -f --show -- "$ovl")
printf '%s\n' "0 $size snapshot $dev $loop P 8" | dmsetup create "$newdevname"

I then use touch to test whether the new device mounts as rw but errors with a notice that it is a Read-Only device.

 # touch /tmp/squash_rw/test
touch: cannot touch '/tmp/squash_rw/test': Read-only file system

I am using a gentoo distribution and Linux kernel 3.10.6 with device mapper and squashfs modules included. Many references suggest to use a dracut initramfs but I am trying to get the init script I was provided by a vendor to work.

I have been stuck on this for a few days and would greatly appreciate any help anyone can provide.

After continuing to research and experiment, it appears as though the devmapper device I am making assumes the filesystem of the first device which is getting merged together. If I use the squashfs device, the devmapper device is readonly, if I use the rw image, then the devmapper device is rw but when mounted doesn't contain the content from the squash file.

  • You don't show where/how you mount the filesystem. You have the path /overlay in the code but your write fails in /tmp. – Chunko Feb 12 '17 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.