1
1
I am testing some filesystem driver code and would like to do so outside of the kernel. The simplest and safest method for doing this is from userspace. So, I have created a file of some length
dd if=/dev/zero of=testfs bs=10M count=50
Then I installed an MBR partitioning scheme using fdisk
fdisk testfs
I can setup a loop device to access my file in block emulated mode:
$ losetup /dev/loop0 testfs
At this point I am able to see this new emulated block device in the device list:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 46G 0 part /
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 4G 0 part [SWAP]
sr0 11:0 1 55.2M 0 rom
loop0 7:0 0 50M 0 loop
And this device has the follow partition table
$ fdisk -l /dev/loop0
Disk /dev/loop0: 52 MB, 52428800 bytes
96 heads, 25 sectors/track, 42 cylinders, total 102400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe7d5af9a
Device Boot Start End Blocks Id System
/dev/loop0p1 * 2048 102399 50176 7 HPFS/NTFS/exFAT
However, to create a fileyststem I need to mount the partition, not the "disk". Does the looping system not automatically mount the device's partitions, similar to the other block devices? I was able to create the filesystem by mounting the file through the loop at an offset
$ losetup -o $((2048*512)) /dev/loop0 testfs
But this solution is less than ideal since the behavior is slightly different than real block devices. Is there a way to "automount" partitions when doing through a loop device?