You are not logged in.
Hello, I have been studying file systems lately and I want to implement my own FAT32 formatter (think `mkfs.fat -F 32`) before trying to create my own file system.
To play around with the existing tools I wanted to create a loop device with any file system and mount it but neither FAT32 or EXT4 would mount.
I ran these commands and got these results :
> dd if=/dev/zero of=test.img bs=1k count=100k
102400+0 records in
102400+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.294542 s, 356 MB/s > mkfs.ext4 test.img
mke2fs 1.47.1 (20-May-2024)
Discarding device blocks: done
Creating filesystem with 102400 1k blocks and 25584 inodes
Filesystem UUID: 5e5e4b58-d377-4fbf-bfe8-84d9f1e535db
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done > sudo losetup -f --show test.img
/dev/loop0 > file test.img
test.img: Linux rev 1.0 ext4 filesystem data, UUID=5e5e4b58-d377-4fbf-bfe8-84d9f1e535db (extents) (64bit) (large files) (huge files)
> fsck.ext4 test.img
e2fsck 1.47.1 (20-May-2024)
test.img: clean, 12/25584 files, 12113/102400 blocks > sudo mount /dev/loop0 /mnt/test
mount: /mnt/test: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error.
dmesg(1) may have more information after failed mount system call.I don't understand why it's not mounting as it seems like the test.img file is correctly formatted and dmesg doesn't give much more information either.
[ 2013.652394] loop0: detected capacity change from 0 to 204800
[ 2149.030620] EXT4-fs (loop0): mounted filesystem 5e5e4b58-d377-4fbf-bfe8-84d9f1e535db r/w with ordered data mode. Quota mode: none.
[ 2149.031064] EXT4-fs (loop0): unmounting filesystem 5e5e4b58-d377-4fbf-bfe8-84d9f1e535db.Offline
Try
mount test.img /mntJin, Jîyan, Azadî
Offline
Try
mount test.img /mnt
That mounted and is listed as /dev/loop0 in lsblk but I'm unsure why mounting the loopdev itself didn't work.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 100M 0 loop /mnt
nvme0n1 259:0 0 931.5G 0 disk
|-nvme0n1p1 259:1 0 1G 0 part /boot
`-nvme0n1p2 259:2 0 930.5G 0 part /Offline
You should be able to mount a loopdevice provided '/mnt/test' exists and the loop is free.
There is a filesystem on test.img that's mountable.
Tried you're steps but they just work
Could it be that 'loop0' was still occupied at the moment you tried it
No idea how to troubleshoot this further but you're correct in thinking it should have worked.
Offline
The mount command sets up the loop device itself, losetup is only useful when dealing with images with partitions, and even then mount can use an offset to deal with those.
See also https://man.archlinux.org/man/mount.8#L … CE_SUPPORT.
For losetup try this before the mount command:
partprobe /dev/loopXReplace X with the number returned from the `losetup -f` command (0 in your example).
Last edited by Head_on_a_Stick (2025-01-02 14:31:46)
Jin, Jîyan, Azadî
Offline
@Head_on_a_SticK, thanks, that's way easier for an image without partitions
Offline
The mount command sets up the loop device itself, losetup is only useful when dealing with images with partitions, and even then mount can use an offset to deal with those.
I didn't have any loop devices created before mounting so that's why I used losetup to create one with the first available ID.
For losetup try this before the mount command:
partprobe /dev/loopXReplace X with the number returned from the `losetup -f` command (0 in your example).
I got the same error, it looks to be specifically when trying to mount loop devices. But at least now I know I can mount images directly granted the file system is setup correctly on it so I should be able to start working on a FAT32 implementation
Offline