1

[EDIT: simplified and corrected]

I would like to use the same method as Raspbian install which relies on dd deployment to a µSD. Meaning, from a minimal image file, deploy the "augmented" Raspbian system partitions with dd on a SD card, resulting into two partitions and their files.

Is there a way to augment (inject files) the image blob file?

(The augmented image file won't fit into RAM)

sugarman
  • 193
  • I think the easiest way is to install it i a fast SD card, do some tweaks and then clone it to an image file. Otherwise, to create an own operating system (maybe call it re-spin) is a rather big task. You could do it from scratch using an existing system in your computer. There are also some shortcuts, but I have no own experience from doing it in an RPi. – sudodus Jun 27 '20 at 19:05
  • thank you @sudodus, I will do the simple way for now. The only optimization I can think of is to use a 8GB µSD, so that the dd won't take very long. Otherwise, I studied 4 scenarios: dd with partitions, ramfs, whole disk 'dd' containing the required partitions, dd extended partition containing required partitions. None can work for several reasons. It is a bit too long to give details. – sugarman Jun 27 '20 at 20:25
  • actually, I would like to modify the blob image file, as you can do it for .iso files using a software. You can open the .iso and add/delete files. Would it be also possible with a dd image of the µSD card? – sugarman Jun 28 '20 at 07:08
  • If you don't want to work with the system on a real drive (µSD card), you might be able to work with it in a virtual machine with a virtual disk (for example using VirtualBox). I think it is possible to edit an image in a file directly, it the file system is writable, but I have not worked that way, and cannot give any detailed warnings and tips. – sudodus Jun 28 '20 at 07:13
  • @sudodus well, that would not be suited for my use case. I'm looking for an industrialized process, using few and swift steps. The process would be: start with a deployed Rasbian on a µSD card >---> dd to Desktop (one image file or partitions) >---> adding files to it on Desktop >---> 'dd' back to a new µSD : fully working augmented Raspbian – sugarman Jun 28 '20 at 08:46
  • I have seen some website suggesting to use losetup or kpartx to mount partititions with file systems in image files. It might work for you (but I have no own experience). Search the internet for linux mount disk image – sudodus Jun 28 '20 at 08:54
  • well done @sudodus! loop setup is a great deal of the solution! I could map both Rasbian partitions to loop partitions. Then I can add files, and dd back to an empty µSD. The only problem which remains si the loop disk size. I can't find a way to increase it. Decrease is documented otherwise. I will first write the answer and open a new question for loop size increase. – sugarman Jun 28 '20 at 20:27

2 Answers2

1

@sudodus helped me find the answer.

How to augment the image? -> mount the image file as loop disk/partitions. Use a mounting point. Add the files. For details: another loop question

How to use dd to write the augmented image to another µSD?

sudo dd bs=4M status=progress of=/dev/sdf if=/dev/loop1 conv=fsync

sugarman
  • 193
0
# losetup -fP image.img

-f will set it to the first loop device

-P will make a partition table

The device will be called /dev/loop0

  • Welcome to Stackexchange, and thanks for your first answer. However, it is not clear how your suggestion adds anything to the other answer. – berndbausch Mar 09 '21 at 02:14