Page 1 of 1

is there anything wrong with this unusual use of loop device?

Posted: Mon May 24, 2021 10:04 am
by BarryK

I want to mount a file, with ext4 filesystem, in a very unusual way. It works, but I wonder if I am breaking some rule.

I have a file, testdummy.ext4, in folder testdummy. I created a ext4 filesystem in it:

Code: Select all

# losetup /dev/loop2 testdummy/testdummy.ext4
# mke2fs -t ext4 -L "EASYSAVE" -m 0 -b 4096 -O encrypt /dev/loop2
# sync
# losetup -d /dev/loop2

To access the ext4 filesystem, I mounted it:

Code: Select all

# losetup /dev/loop2 testdummy/testdummy.ext4
# mount -t ext4 -o discard /dev/loop2 testdummy

So now the file testdummy.ext4 has disappeared:

Code: Select all

# ls testdummy
lost+found
# 

It works, I can read and write files.

Although I cannot see testdummy.ext4 anymore, /dev/loop2 is still connected to it, so it works. I suppose that /dev/loop2 is connected to the inode of testdummy.ext4, not the path, which is why it continues to work.

If I unmount /dev/loop2, I can once again see testdummy/testdummy.ext4

I am just wondering if I am doing something that works "accidentally" and is not really supposed to be done?

Ignore those "-O encrypt" and "-o discard", that is not relevant.


Re: is there anything wrong with this unusual use of loop device?

Posted: Tue May 25, 2021 5:01 am
by Jafadmin

Too many "testdummies" I think.

I would try testdummy-a, testdummy-b, etc .., and see what happens.


Re: is there anything wrong with this unusual use of loop device?

Posted: Tue Oct 12, 2021 8:01 am
by scsijon

no, as far as i've always understood it, that's the way it should work. With only one appearance of the directory structure available at any time, whether mounted in a /dev/loop or unmounted as a file.


Re: is there anything wrong with this unusual use of loop device?

Posted: Wed Oct 13, 2021 3:00 am
by Clarity

Hello @BarryK

I dont see anything wrong.

Question
Would 'fallocate ...' be a simpler options to achieving your result(s) desired ... and a little easier in its understanding? (A single command affording what you want.)

Hope this is helpful.
P.S. Barry or anyone: You may find this forum link also useful for image-iso loop mounts.


Re: is there anything wrong with this unusual use of loop device?

Posted: Thu Oct 14, 2021 6:01 am
by jamesbond
BarryK wrote: Mon May 24, 2021 10:04 am

I am just wondering if I am doing something that works "accidentally" and is not really supposed to be done?

This works and is a standard/supported feature. It is called as an "overmount".

If you want to make use of this feature, don't worry and just go and use it. I've been using it for years with "encfs" (with some sort of ROX GUI). An encfs-encrypted directory contains garbage when viewed. I can "open" it (which behind the scenes run encfs mount over the same directory), and then that directory now shows proper unencrypted files. When I'm done, I can "close" it (which behind the scenes I just run "umount") and the directory turns back to showing garbage.

In fact, this happens every time the system boots up, if you use initramfs. It is how "switch_root" works. Nothing is being switched, really, what really happens is that the new root (could be aufs' "new_root", or one of the disk partitions) is "overmounted" on root directory ("/").

So go ahead and use it. It's a supported feature.


Re: is there anything wrong with this unusual use of loop device?

Posted: Wed Nov 03, 2021 8:27 pm
by amigo

I used to use this in KISS linux as a way to have certain directories read-only. For instance, for /usr/bin, I'd create a filesystem image .iso, ext2 or whatever, place that in a read-write framework or as part of normal boot. I'd put the image under /usr/bin, then during bootup, look for such images(s) and mount them during early boot. I experimented with using a compressed ext2-comp image. That way I could save quite a lot of space in the overall image.
It's a clever, sneaky way to hide things in plain sight.

BTW, hello to all you guys -I've finally signed up here after all the murga-linux forum end-of-line. In the meantime, I've aged a bit, and probably won't be so cantankerous, as some might remember from me.


Re: is there anything wrong with this unusual use of loop device?

Posted: Wed Nov 03, 2021 10:57 pm
by Keef

Hello again amigo. I was wandering what you were up to. Cantankerous? Nah, that couldn't be you.


Re: is there anything wrong with this unusual use of loop device?

Posted: Thu Nov 04, 2021 1:28 pm
by amigo

Hi! I had kinda retired from programming after 10 years on the same projects. For years I had mostly coded during the cold months. But, when the lockdowns came in 2020, I re-visited a question from years earlier -would it be possible to use, or at least demonstrate neural networks from a shell script. Happy to say that it can, indeed, be done. I'll probably posting soon with a call for testers/users of some pretty interesting math stuff.


Re: is there anything wrong with this unusual use of loop device?

Posted: Fri Nov 05, 2021 12:04 pm
by BarryK

Welcome back, amigo!


Re: is there anything wrong with this unusual use of loop device?

Posted: Fri Nov 05, 2021 9:30 pm
by amigo

Thanks Barry. Bit of rain out there lately, I heard.


Re: is there anything wrong with this unusual use of loop device?

Posted: Sun Nov 07, 2021 6:01 pm
by snoring_cat

Barry,

would the following work for you

Code: Select all

dd if=/dev/zero of=testdummy.ext4 bs=1M count=1 seek=100
mkfs -t ext4 -L "EASYSAVE"  testdummy.ext4

mkdir /mnt/easysave
mount testdummy.ext4 /mnt/easysave

umount /mnt/easysave

This should quickly create a 100M testdummy.ext4 file with ext4 on it. Also note that when mounting, you do not have to explicitly use -t ext4.

Pease feel free to tweak any of the example values as you see fit. Other than encryption, I want to throw out that you could use a dynamically growing filesystem similar to qcow2 (Please refer to libqcow-utils package and "qcowmount" command).