Conversation

Jarkko Sakkinen

Edited 1 year ago
How would you partition a pre-created image file (let's say with dd or qemu-img), partition it, and format each partition with the file system of your choice without having privileged access to the system (e.g. no access to the loopback device)?

The only robust option I'm aware of is to create a #QEMU VM just for partitioning and formatting another image (i.e. it runs a script and shuts down immediately after that).

PS. In this scenario, a container, given more infrastructure required, would actually be worse and more heavy-weight option than a VM.

#partitioning
1
0
0
@jarkko I am not sure if next use of image files from host system could be robust (for example in respect to aligning image according to used virtual device sector sizes etc.). But for basic use I would use fdisk, gdisk, parted, ... for partitioning. mkfs.ext2, mkfs.vfat have offset option to setup filesystem at right location and fs-size or block_count argument to not span it to the end of image. BTRFS seems to be without these options, for example. Then there is option to format individual partitions images and concatenate them together. When feed trough dd conv=notrunc,sparse,nocreat even sparse image can be obtained. I have put my idea into google and got to link https://unix.stackexchange.com/questions/281589/how-to-run-mkfs-on-file-image-partitions-without-mounting . Problem is creation of the FS content in some cases. If it is possible to have root read only or with overlay then genromfs or sqush can be used to prepare partition content even with files...
1
0
1
@ppisa thanks! i was not aware that you can pass a file to parted, that was reallly useful nit here!
0
0
0