1 (edited by gparep 2020-09-21 17:07:05)

Topic: [SOLVED] GParted image file - can't format partition

First I want to thank the developers of GParted for an excellent tool!

Background:
OS: Xubuntu 20.04
Gparted: os supplied version, version 1.0.0
configuration --enable-libparted-dmraid --enable-online-resize
libparted 3.3

When I try to use GParted with an image file, GParted can not format the created partition. This seems to be because GParted uses the same naming scheme as when accessing partitions created when using device files, ie adding the partition number to the end of the device name.

Example:
$ fallocate -l 50M hd.img
$ sudo gparted hd.img

I then create a partition table (in this case mbr/msdos), create a partition, and set a partition type. Everything works except formatting the partition.
Error:
mkfs.fat: unable to open /[...]/hd.img1: No such file or directory

I know I can use loop devices to solve the problem, but I wonder if there is any way to solve it within GParted? Is there any command line switch to tell GParted that the file is not a device file but an image file? A very quick glance at the source code only revealed the possibility to supply device names at the command line.

2

Re: [SOLVED] GParted image file - can't format partition

Please see this open enhancement request Issue #49 "Open partitioned Disk Images".  In particular this quote explains why a partitionable device is required.

... GParted can't work with images of partitioned disks containing file systems. GParted needs to run file system specific tools to query usage, read labels, change labels, change UUIDs, check and resize those file systems. GParted has to provide a file or block device which provides access to exactly each partition within the disk image for those file system specific tools to use. This is why GParted can't work with images of partitioned disks without using a partitioned loop device over the top of an image.

Edit:
Creating a partitioned loop device is currently a manual task for expert users.

3

Re: [SOLVED] GParted image file - can't format partition

Thank you very much!

(Out of curiosity, would it, at least in theory, be possible to implement some of the features even when using os file system specific tools, for example mkfs.ext{2,3,4} as well as mkfs.fat supports supplying an offset for where to create the new filesystem?)

4

Re: [SOLVED] GParted image file - can't format partition

In theory it would be possible to modify every tool and library which GParted uses to interact with partitions and file systems.  However that would be a massive waste of effort and rightly rejected by the authors of all those tools.  Even for just the GParted code it is much simpler to create a loop device over a disk image rather than deal with passing the partition offset and length to every tool.