dominikp
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 ...

http://blog.oddbit.com/2016/02/07/syste ... -mostly-f/

Unfortunately i fail at starting the container

Code: Select all

 $ sudo losetup -fP --show RPI0-custom.img
[sudo] password for dominik: 
/dev/loop0
$ 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
/home/dominik/dir/bin/bash
 $ ls /home/dominik/dir/bin/sh
/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).

pe78420
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,

Philippe
A french guy...

LittleMike
Posts: 2
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
/dev/loop0
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.

*EDIT*

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
sakaki
Posts: 264
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

LittleMike,

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

User avatar
rin67630
Posts: 379
Joined: Fri Mar 04, 2016 10:15 am

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

Sun Jun 30, 2019 12:09 pm

You know, it is so easy to have a headless reference Raspberry Pi (can be a cheap PiZero) with all your loved software that you keep up-to date and from which you copy the SD card each time you need another one...

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

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

Wed Jul 03, 2019 4:21 pm

sakaki wrote:
Thu Jun 20, 2019 7:17 pm
LittleMike,

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
Sorry, I didn't get an email notification you responded.

I'm running Raspberry Pi Desktop using the Live USB distro, running it with persistence.

I removed/redid everything a few times, so I'll have to go back to the start and try again (I gave up on it, honestly) but there was a boot directory and a bunch of others. No /usr/bin, but I was able to create one, and no /etc either, but I was able to create one. That's how I got as far as I did.

I'm wondering if it's less the Raspberry Pi Desktop being the issue and more that it's the Live USB that's the issue (along with the gnome bootloader). No syslinux file, I don't think.

MyDearDeveloper
Posts: 1
Joined: Sun Jul 07, 2019 4:27 pm

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

Sun Jul 07, 2019 4:33 pm

sakaki wrote: ↑

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
/dev/loop0
Thanks for this informative post i was struggling but this helped me

bmanske
Posts: 1
Joined: Fri Feb 14, 2014 1:44 am

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

Mon Aug 19, 2019 6:23 am

I'm going to resurrect this topic. I have decided to work on a project requiring the use of several raspberry pis and the thought of going through the setup for each one is hard to swallow. So I started looking for this topic.

First:
SET UP A HEADLESS RASPBERRY PI, ALL FROM ANOTHER COMPUTER’S COMMAND LINE
https://hackaday.com/2018/11/24/set-up- ... mand-line/

November 24 2018 this article proceeded this topic. I have to wonder why it was never brought up in this discussion.

Second: Peter Lorenzen deserves credit for this very efficient shell script
Trying to get to http://peter.lorenzen.us/linux/headless ... figuration it never responded. So I went to the way back machine to get the shell script.
https://web.archive.org/web/20190131013 ... figuration
Using the final snapshot of this page is where I started.

I don't know if I got the latest version of the code. I decided to build a VMware Debian 10 machine with the Cinnamon desktop. I don't know what he used. This script would no longer run. The website obviously changed as there is one more redirect now than was accounted for in his code. I had some problems with curl giving me decent results worked almost always from the command line when requesting the https URL and almost always failed when run from the shell script. The format of the redirect message had also changed to instead of doing an awk on the second http in the file I implemented a quick search for it. I also didn't like his defaults so some of those were changed. You get the picture, I really extended the length of the script by adding more error checking and comments. I've used features of bash prior to v4.0 to try to maintain compatibility.

Three: Going Forward
I want to replace the rsync command with code to look at where the file is being copied to and set the ownership and permissions without the need for getting all of the files set up in the right condition before hand. Adding a ability to specify an include file for configuration as the command line is getting long among other ideas.

HERE's THE QUESTION.
I don't want to just set up SSH I also want RealVNC server enabled. I use TightVNC on all of my local machines and have changed a RealVNC config file to allow the 2 to communicate so I know SED and AWK will get that for me in the script. Can someone point me to the source code for the rasberry pi config or just tell me how to do it? The source code would allow me to learn how to enable / disable other devices also.

I've been thinking about putting the project on GitHub. Any interest in this?

RonR
Posts: 430
Joined: Tue Apr 12, 2016 10:29 pm
Location: US

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

Thu Aug 22, 2019 1:36 am

bmanske wrote:
Mon Aug 19, 2019 6:23 am
Can someone point me to the source code for the rasberry pi config or just tell me how to do it?

If you're referring to 'raspi-config', it's a script located at: /usr/bin/raspi-config

Return to “General discussion”