Posts: 7
Joined: Mon Dec 17, 2018 9:54 am

Re: STICKY: Making your own custom burn-n-boot Raspbian image

Tue Apr 30, 2019 2:07 pm

Im on Kubuntu 18.04 and i used this guide ... ... -mostly-f/

Unfortunately i fail at starting the container

Code: Select all

 $ sudo losetup -fP --show RPI0-custom.img
[sudo] password for dominik: 
$ sudo mount /dev/loop0
loop0    loop0p1  loop0p2  
$ sudo mount /dev/loop0p2 /home/dominik/dir
$ sudo mount /dev/loop0p1 /home/dominik/dir/boot
$ sudo systemd-nspawn -D /home/dominik/dir
Spawning container dir on /home/dominik/dir.
Press ^] three times within 1s to kill container.
execv(/bin/bash, /bin/sh) failed: No such file or directory
Container dir failed with error code 1.
$ ls /home/dominik/dir/bin
bash          cpio           gunzip      lsmod           pidof       stty                            unicode_start
bunzip2       dash           gzexe       machinectl      ping        su                              vdir
bzcat         date           gzip        mkdir           ping6       sync                            wdctl
bzcmp         dd             hciconfig   mknod           plymouth    systemctl                       which
bzdiff        df             hostname    mktemp          ps          systemd                         ypdomainname
bzegrep       dir            ip          modeline2fb     pwd         systemd-ask-password            zcat
bzexe         dmesg          journalctl  more            rbash       systemd-escape                  zcmp
bzfgrep       dnsdomainname  kbd_mode    mount           readlink    systemd-inhibit                 zdiff
bzgrep        domainname     kill        mountpoint      red         systemd-machine-id-setup        zegrep
bzip2         dumpkeys       kmod        mt              rm          systemd-notify                  zfgrep
bzip2recover  echo           less        mt-gnu          rmdir       systemd-tmpfiles                zforce
bzless        ed             lessecho    mv              rnano       systemd-tty-ask-password-agent  zgrep
bzmore        egrep          lessfile    nano            run-parts   tailf                           zless
cat           false          lesskey     nc              sed         tar                             zmore
chacl         fbset          lesspipe    nc.openbsd      setfacl     tempfile                        znew
chgrp         fgconsole      ln          nc.traditional  setfont     touch
chmod         fgrep          loadkeys    netcat          setupcon    true
chown         findmnt        login       netstat         sh          udevadm
chvt          fuser          loginctl    nisdomainname   sh.distrib  umount
con2fbmap     getfacl        ls          open            sleep       uname
cp            grep           lsblk       openvt          ss          uncompress
 $ ls /home/dominik/dir/bin/bash
 $ ls /home/dominik/dir/bin/sh
qemu-user-static is already the newest version (1:2.11+dfsg-1ubuntu7.12).
systemd-container is already the newest version (237-3ubuntu10.21).

Posts: 7
Joined: Wed Jun 12, 2019 10:28 pm

Re: STICKY: Making your own custom burn-n-boot Raspbian image

Wed Jun 12, 2019 11:07 pm

Hi HawaiianPi,

Very helpfull :D

Everything is ok with the raspbian_2018-11-15 release even when I tried to add or modify any file (ssh, config.txt, cmdline.txt, wpa_supplicant.conf, etc.)... To do that, I copied them from the windows explorer or after mounting the image on Debian via kpartx or loseup.

But I got a problem :(
On the latest raspbian image (2019-04-09), booting stucks when I tried to add of modify the same files!
Without modification (the raw image), booting is always successfull...

What's wrong!
Any ideas?

Many thanks in advance and best regards,

A french guy...

Posts: 1
Joined: Tue Jun 18, 2019 2:00 pm

Re: STICKY: Making your own custom burn-n-boot Raspbian image

Tue Jun 18, 2019 2:45 pm

sakaki wrote:
Tue Jan 29, 2019 4:02 pm
bertlea wrote:
Mon Jan 21, 2019 6:27 am
That sounds very useful to me! Is there a way that I can even use apt to install packages that is not in the original image myself? I assume I need to mount the image to an real Raspberry Pi to do that.... if it is even possible.

Right, so begin by installing systemd-container (this will give you the systemd-nspawn utility) and zerofree, if you don't already have them. This will not take long:

Code: Select all

[email protected]:~ $ sudo apt-get update
[email protected]:~ $ sudo apt-get install -y systemd-container zerofree
Then, assuming you have already downloaded the zipped image (from here), unpack, and then loop mount it:

Code: Select all

[email protected]:~ $ unzip raspbian_latest 
Archive:  raspbian_latest
  inflating: 2018-11-13-raspbian-stretch.img 
[email protected]:~ $ sudo losetup --show -P -f 2018-11-13-raspbian-stretch.img
Your reported loop device may differ (loop1, loop2 etc.) in which case modify the following instructions accordingly.
This losetup command should have created partition mappings automatically:

Code: Select all

[email protected]:~ $ ls /dev/loop0*
/dev/loop0  /dev/loop0p1  /dev/loop0p2
Yep, two partitions, as expected. Now mount them:

Code: Select all

[email protected]:~ $ sudo mkdir -p /mnt/raspbian
[email protected]:~ $ sudo mount -v /dev/loop0p2 /mnt/raspbian
mount: /dev/loop0p2 mounted on /mnt/raspbian.
[email protected]:~ $ sudo mount -v /dev/loop0p1 /mnt/raspbian/boot
mount: /dev/loop0p1 mounted on /mnt/raspbian/boot.
Now we can chroot in. We'll use systemd-nspawn to do this; it will take care of all the necessary behind-the-scenes bind-mounts etc.:

Code: Select all

[email protected]:~ $ sudo systemd-nspawn --directory=/mnt/raspbian
Spawning container raspbian on /mnt/raspbian.
Press ^] three times within 1s to kill container.
[email protected]:~#
Can this be done on the x86 Raspi image? The download is an iso, but I used dd to convert it to an img and tried the above steps. Most of it seemed to work, but whenever I get to the systemd-nspawn portion, it yells at me that there is no OS-tree. So I tried putting a /usr/bin and an /etc folder but then it tells me that it's mounted read-only.

My goal is to create a Live USB stick running Raspberry Pi Desktop that has some base packages installed and some minor configuration completed so that I have a "baseline" because I have a habit of breaking things and have needed to start all over from scratch each time as I learn and that's just gotten really annoying.


So I tried a different method of just extracting all the contents of the ISO to a folder and added the /etc and /usr/bin folders manually. Now when I try to run systemd-nspawn it tells me execv() failed, no such file or directory.

User avatar
Posts: 204
Joined: Sun Jul 16, 2017 1:11 pm

Re: STICKY: Making your own custom burn-n-boot Raspbian image

Thu Jun 20, 2019 7:17 pm


in principle this technique should be usable with an x86 (or x86_64) guest linux image, running under an x86 (or x86_64) host linux system, such as the Debian with Raspberry Pi Desktop OS, for example.

Could you provide some more details about your host system (e.g., is it running the RPi Desktop for PC, or some other Linux variant) and what you see at /mnt/raspbian (if you run e.g. "ls -l /mnt/raspbian"; assuming you are using the same paths as given in the instructions).

For disclosure, I have used the systemd-nspawn approach extensively on PCs running Gentoo and Arch (with Gentoo, Arch and vanilla Debian guests) but haven't actually used the "Debian with Raspberry Pi Desktop" image in either capacity to date.

Best, sakaki

Return to “General discussion”