3

I am trying to automate the creation of Raspberry Pi images under Docker virtual machine to run it in common CI systems like bitbucket-pipelines.

On physical system I am using "template" image, mount it't partitions to local directories, then populate it with script and unmount. To mount it I use script like following:

loopdevice=`losetup -f --show -P images/template.img`

echo $loopdevice > loopdevice

mkdir -p images/p1
mkdir -p images/p2
mkdir -p images/p3

mount ${loopdevice}p1 images/p1
mount ${loopdevice}p2 images/p2
mount ${loopdevice}p3 images/p3

(image contains 3 partitions, which are mounted to 3 directories).

Unfortunately, I can't use loopback devices inside Dcoker container if not priviledged and I can't make it priviledged inside Bitbucket pipelines. I see deadend here.

So, the question is: are there any Linux tools to manipulate filesystem image files without mounting them to loopback devices?

Dims
  • 3,181
  • 9
  • 49
  • 107
  • What filesystem type? Maybe you can mount it as [FUSE](https://en.wikipedia.org/wiki/Filesystem_in_Userspace) (e.g. `fuse2fs` for the ext family); although I'm not sure if you can easily specify an offset. – Kamil Maciorowski Feb 19 '21 at 21:42

2 Answers2

1
  1. There are tools to manipulate filesystems as you ask. One such is the mtools package, which does FAT filesystems. Another is e2tools, which does EXT2 and EXT3 filesystems. Both of these are available in debian linux, and probably many others.
  2. These tools will probably not deal with an image in a partition. This should not be a problem. Simply split your template into separate files for the partition table and partition contents (probably ahead of time), add your files into the filesystem images, and then cat the pieces together in the right order to produce the final disk image.
David G.
  • 1,314
  • 1
  • 4
  • 15
0

I use and recommend guestfish, which is a part of libguestfs, library for accessing and modifying VM disk images.

I've found OpenStack's documentation includes a useful description of tools that do not require privileges: Modify images — Virtual Machine Image Guide documentation

Note that if you are making many disjoint changes you may benefit from running a guestfish daemon process and using its remote control mode - this saves on the (not insignificant) start-up time.

See Remote control guestfish over a socket of the guestfish manual.

RobM
  • 482
  • 4
  • 9