I want to create a FAT12 filesystem on a simple file on linux (Example: ~/file), and perhaps use xxd to view what exactly happens when a filesystem is created. This is just out of curiosity
I believe that we can use the mkfs command or something similar to achieve this.
Can this be done? and how?
Yes, create a 16 or 32MB file and format it with mkfs.vfat
.
$ dd if=/dev/zero of=fat12.img bs=1M count=32
32+0 records in
32+0 records out
33554432 bytes (34 MB, 32 MiB) copied, 0.0212121 s, 1.6 GB/s
$ mkfs.vfat -F12 fat12.img
mkfs.fat 4.1 (2017-01-24)
$ file fat12.img
fat12.img: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 32, reserved sectors 32, root entries 512, Media descriptor 0xf8, sectors/FAT 32, sectors/track 32, heads 64, sectors 65536 (volumes > 32 MB), serial number 0xb1d9d2e8, unlabeled, FAT (12 bit)
$ mount -o loop fat12.img /mnt/
You can then perform I/O on the mount, observe the hexdump of the image file to observe the on-disk layout changes and correlate with the I/O.