I'm trying to play around with OS development, and I started with a boot loader, where phase 0 loads phase 1 from a file (specified by inode) on an ext4 partition (specified by first LBA). Of course, I need something to boot from, so I grabbed QEMU. Now what?What has worked fine so far is this:truncate -s64M /tmp/SomeVolume/sbin/mke2fs -t ext4 -F /tmp/SomeVolumeyasm phase0.asmdd if=phase0 of=/tmp/SomeVolume conv=notruncI make a volume of about 64 MB, format it as ext4, and overwrite the first 1024 octets with phase0 (which is always 1024 bytes in size). This works fine.But now I want to make a properly partitioned file, to test it for more realistic scenarios. I know I could /sbin/cfdisk my volume file, but mke2fs doesn't have a parameter that lets me choose a span within the file.Now I'm aware of solutions using loop, but unfortunately, it doesn't seem to work for me (it seems I'm not able to change max_part in Debian jessie). There seems to be another module called nbd, but I don't have the server and client for that module installed. And it's getting a little ridiculous that I need root privileges for something that could clearly be done in userland.How can I do this as a user? Or should I just build the MBR/GPT-partitioned volume around the ext4-formatted file I created?
How can I partition a volume in a regular file without loop?
partition;ext4;loop device
The long way around. But for the fun of it:1. Create a temporary image:    $ truncate -s64MiB tmp.img2. Create two partitions using fdisk:Rather detailed, but OK.$ fdisk tmp.imgFirst partition:: n <Enter>: <Enter> (p): <Enter> (1): <Enter> (2048): +40M <Enter>Second partition:: n <Enter>: <Enter> (p): <Enter> (2): <Enter> (83968): <Enter> (131071)Print what we are about to write:: x: pNr AF  Hd Sec  Cyl  Hd Sec  Cyl     Start      Size ID 1 00  32  33    0  57  52    5       2048      81920 83 2 00  57  53    5  40  32    8      83968      47104 83Write and exit::w (Dont! forget ;-) )We have two partitions of 40 and 23 MiB:81920 * 512 / 1024 / 1024 = 40MiB47104 * 512 / 1024 / 1024 = 23MiB3. Create two file systems:truncate -s40MiB ext4.imgtruncate -s23MiB ext3.imgmke2fs -t ext4 -F -L part_ext4 ext4.imgmke2fs -t ext3 -F -L part_ext3 ext3.img4. Stitch it all together:Extract first 2048*512 bytes from temporary image:dd if=tmp.img of=disk.img bs=512 count=2048Combine them:cat ext4.img ext3.img >> disk.imgFine.