User avatar
HawaiianPi
Posts: 6001
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

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

Sat Apr 11, 2020 11:25 am

Rukbat wrote:
Thu Apr 09, 2020 9:05 pm
Ext2 Volume Manager allows you to mount the root image as a drive in Windows
...
So I did the command.txt and the cmdline.txt changes, added wpa_supplicant.conf...
None of those files require any Windows filesystem drivers to edit, so not sure what you're getting on about here.

Both cmdline.txt and config.txt are located in the small "boot" partition which is formatted with the FAT32 file system that Windows can read by default. You can also place a wpa_supplicant.conf and ssh file on that same FAT32 partition, and Raspbian will use them (ssh will be enabled and the ssh file will get deleted, and wpa_supplicant.conf will be moved to its correct location and used to connect to WiFi).

So you don't need to mount the root partition to edit those files, enable SSH, or connect to a WiFi network (it's all done on the FAT32 partition).

But congrats on figuring out how to mount a Linux file system in Windows. Personally, I find it simpler to use Linux, and the defiant tone of your post seems to indicate you missed the entire point of the thread, and the Raspberry Pi in general. Remaining steadfastly dependent on Windows will be a handicap when working with the Pi.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

jordana
Posts: 39
Joined: Thu Jan 02, 2020 3:26 pm

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

Fri May 15, 2020 9:26 pm

This post has made me thinking if I could burn-n-boot pihole onto a spare SD card and swap it in my RPI without the family noticing it. Since the lockdown the entire family is constantly hooked on the net so pihole has become a critical component of the peace at home.

The process was successful but not flawless. Here is my workflow with findings:
First I booted Debian with Raspberry Pi Desktop on my ThinkPad from persistent live USB.
Then started the workflow with writing newest Raspbian on an SD card with Imager.

Code: Select all

sudo fdisk -l 
gave me that the SD card is disk /dev/sda

Code: Select all

sudo mkdir /mnt/raspbian
sudo mount /dev/sda2 /mnt/raspbian
sudo mount /dev/sda1 /mnt/raspbian/boot
sudo systemd-nspawn -D /mnt/raspbian
and here I arrived at the first hiccup:
ERROR: ld.so: object '/usr/lib/arm-linux-gnueabihf/libarmmem-${PLATFORM}.so' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
I could get rid of this ERROR by commenting the only line in /etc/ld.so.preload that contained the shared object file that cannot open.

Code: Select all

apt update
apt -y upgrade
there was some hiccup:
System has not been booted with systemd as init system (PID 1). Can't operate
invoke-rc.d: could not determine current runlevel
Warning: using insecure memory!
but the upgrade eventually finished.

Code: Select all

curl -sSL https://install.pi-hole.net | bash
here I arrived some more hiccups
[✗] Checking apt-get for upgraded packages
Kernel update detected. If the install fails, please reboot and try again
SELinux not detected
Unsupported setsockopt level=270 optname=11
Unknown host QEMU_IFLA type: 50
Unknown host QEMU_IFLA type: 51
Unknown host RTA type: 25
when I tried to set-up static IP I got kicked out with:
RTNETLINK answers: Operation not permitted
but I could see the changed static IP in /etc/dhcpcd.conf
interface eth0
static ip_address=192.168.1.3/24
static routers=192.168.1.1
static domain_name_servers=8.8.8.8 8.8.4.4
so when run pihole install script again it did accept the static IP settings because:
Static IP already configured
then some more checks failed:
[✗] Check for existing repository in /etc/.pihole
[✗] Check for existing repository in /var/www/html/admin
but ultimately the install finished.
Removed webserver password and copied over dhcp config from running server:

Code: Select all

pihole -a -p
scp jordana@192.168.1.3:/etc/dnsmasq.d/02-pihole-dhcp.conf /etc/dnsmasq.d 
scp jordana@192.168.1.3:/etc/dnsmasq.d/04-pihole-static-dhcp.conf /etc/dnsmasq.d
then finished with some user management and enabled ssh:

Code: Select all

groups pi
useradd -m -G <all-pi-groups-comma-separated> jordana
passwd pi
passwd jordana
touch /boot/ssh
exit
finally umount and ejected the SD card

Code: Select all

sudo umount /mnt/raspbian/boot
sudo umount /mnt/raspbian
Popping the SD card into my RPI booted nicely and I could ssh with configured user but pihole was not running.
Not sure what is wrong but only repair seemed to fix it.

Code: Select all

pihole -r
While the repair process was reasonably fast so I only got angry looks for a minute or two I am wondering how could this workflow be improved so that pihole would just start after burn-n-boot without repair?

jordana
Posts: 39
Joined: Thu Jan 02, 2020 3:26 pm

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

Sat May 16, 2020 4:30 pm

I think I found the ultimate solution for making my own custom burn-n-boot Raspbian image with fully fledged pihole running on it.

Wrote Raspbian Lite with Imager this time on the SD card. Then installed qemu-system-arm on my live USB Debian and downloaded ready made kernel image and compiled device tree file from https://github.com/dhruvvyas90/qemu-rpi-kernel that can emulate my Raspberry Pi 1. Quick fdisk -l to find out disk name this time is /dev/sda and this single command has booted an entire virtual machine from the SD card:

Code: Select all

sudo qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda /dev/sda -dtb ~/Downloads/versatile-pb-buster.dtb -kernel ~/Downloads/kernel-qemu-4.19.50-buster -append 'root=/dev/sda2 panic=1' -no-reboot &
From the QEMU pop-up window just logged in we can jump right into the pihole install:

Code: Select all

sudo curl -sSL https://install.pi-hole.net | bash
Could configure the final static IP address and default gateway also as it will only be applied after reboot so could still pull static DHCP config file from host. After minimal password management shutdown the virtual machine.

Code: Select all

sudo scp jordana@10.0.2.2:04-pihole-static-dhcp.conf /etc/dnsmasq.d
pihole -a -p
passwd
sudo shutdown -h now
Dropped a new file named ssh into boot disk from File Manager before ejected it and that is it. Swapped in the new card into RPI and the family did not notice the change. Finished by expanding the filesystem with raspi-config, apt update/upgrade, enabling DHCP from web interface and confirmed it is all running OK.

bassamanator
Posts: 82
Joined: Wed Jun 10, 2020 7:04 am

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

Tue Jul 07, 2020 7:20 pm

This worked for me. Thanks!

My wpa_supplicant.conf didn't take though because the country was not set (it is set in the wpa_supplicant however).

What file must I edit to set the country code?
| Raspberry Pi 4-8GB | 2.0GHz | over_voltage@5 |
| Raspberry Pi OS 32bit |
| https://github.com/bassamanator/raspberrypi-scripts |

User avatar
HawaiianPi
Posts: 6001
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

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

Tue Jul 07, 2020 7:42 pm

bassamanator wrote:
Tue Jul 07, 2020 7:20 pm
My wpa_supplicant.conf didn't take though because the country was not set (it is set in the wpa_supplicant however).

What file must I edit to set the country code?
You can edit or create your own wpa_supplicant.conf file with your appropriate country code.

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
	ssid="WiFi SSID"
	psk="WPA/WPA2 passphrase"
}
Edit country=, ssid= and psk= with your information and save the file, then place it on the FAT32 "boot" partition of a Raspbian/RPiOS card (along with an "ssh" file, if needed), and the system will move it to its correct location and use it to connect to your WiFi when that card is booted.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

bassamanator
Posts: 82
Joined: Wed Jun 10, 2020 7:04 am

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

Mon Jul 13, 2020 5:58 am

HawaiianPi wrote:
Tue Jul 07, 2020 7:42 pm
You can edit or create your own wpa_supplicant.conf file with your appropriate country code.

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
	ssid="WiFi SSID"
	psk="WPA/WPA2 passphrase"
}
Edit country=, ssid= and psk= with your information and save the file, then place it on the FAT32 "boot" partition of a Raspbian/RPiOS card (along with an "ssh" file, if needed), and the system will move it to its correct location and use it to connect to your WiFi when that card is booted.
Well I copied a working wpa_supplicant.conf into the image and it contains the country code so I think perhaps the country code needs to be set elsewhere. The only way I could get wifi working on the custom image was by running raspi-config.

Part of my wpa_supplicant.conf

Code: Select all

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CA

network={
...
}
| Raspberry Pi 4-8GB | 2.0GHz | over_voltage@5 |
| Raspberry Pi OS 32bit |
| https://github.com/bassamanator/raspberrypi-scripts |

User avatar
HawaiianPi
Posts: 6001
Joined: Mon Apr 08, 2013 4:53 am
Location: Aloha, Oregon USA

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

Mon Jul 13, 2020 7:01 am

bassamanator wrote:
Mon Jul 13, 2020 5:58 am
Well I copied a working wpa_supplicant.conf into the image and it contains the country code so I think perhaps the country code needs to be set elsewhere.
Nope, I do it all the time with new cards by placing a pre-configured wpa_supplicant.conf on the FAT32 "boot" partition. Pi boots up and connects to my router without me having to do anything else. That, combined with having IP reservations in my router for most of my Pi computers makes it simple to use completely headless systems.

bassamanator wrote:
Mon Jul 13, 2020 5:58 am
The only way I could get wifi working on the custom image was by running raspi-config.
That's odd. Like I said, I have done this many times on multiple versions of Raspbian and now PiOS, and it always works for me. Something else you've done to your custom image must have affected WiFi.
My mind is like a browser. 27 tabs are open, 9 aren't responding,
lots of pop-ups...and where is that annoying music coming from?

tvoverbeek
Posts: 101
Joined: Mon Feb 04, 2013 9:50 am
Location: Fieberbrunn, Austria

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

Mon Jul 13, 2020 1:38 pm

bassamanator wrote: ↑
Mon Jul 13, 2020 6:58 am
The only way I could get wifi working on the custom image was by running raspi-config.
Do you by chance have disabled wifi with rfkill?
raspi-config unblocks wifi when it is blocked by rfkill

bassamanator
Posts: 82
Joined: Wed Jun 10, 2020 7:04 am

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

Sun Jul 19, 2020 8:12 am

HawaiianPi wrote:
Mon Jul 13, 2020 7:01 am
bassamanator wrote:
Mon Jul 13, 2020 5:58 am
Well I copied a working wpa_supplicant.conf into the image and it contains the country code so I think perhaps the country code needs to be set elsewhere.
Nope, I do it all the time with new cards by placing a pre-configured wpa_supplicant.conf on the FAT32 "boot" partition. Pi boots up and connects to my router without me having to do anything else. That, combined with having IP reservations in my router for most of my Pi computers makes it simple to use completely headless systems.

bassamanator wrote:
Mon Jul 13, 2020 5:58 am
The only way I could get wifi working on the custom image was by running raspi-config.
That's odd. Like I said, I have done this many times on multiple versions of Raspbian and now PiOS, and it always works for me. Something else you've done to your custom image must have affected WiFi.
I made many other changes as well, perhaps I broke something in the process. I'll try again soon but I'll only change the wpa file and see if that works. Thanks.
| Raspberry Pi 4-8GB | 2.0GHz | over_voltage@5 |
| Raspberry Pi OS 32bit |
| https://github.com/bassamanator/raspberrypi-scripts |

homeplayer
Posts: 4
Joined: Thu Apr 16, 2020 7:18 pm

More or less using windows

Thu Oct 08, 2020 12:27 pm

I have made a img, using windows and my Rpi 4,

I did not read this complete topic, so maybe it's bin writen up like I did.
Parts list;
  • Rpi that boots from USB
  • A USB SSD
  • A 8Gb Micro SD
.
Flashed RaspberryPi OS lite to ssd whit rasberry Pi Imager
unplug ssd from PC, and pluged back in.
on the boot drive create file ssh, and edit config.txt and cmdline.txt

Code: Select all

config.txt ---- DON'T use mine, use it as a reference, things i have added

# Disable Ethernet LEDs
dtparam=eth_led0=14
dtparam=eth_led1=14
# Disable the PWR LED
dtparam=pwr_led_trigger=none
dtparam=pwr_led_activelow=off
# Disable the Activity LED
dtparam=act_led_trigger=none
dtparam=act_led_activelow=off
#disable all we dont need
dtoverlay=disable-wifi
dtoverlay=disable-bt
gpu_mem=32

Code: Select all

cmdline.txt
remove te last part from the line,
make sure there will be only 1 line (No enter no next line)
Remove this --> " init=/usr/lib/raspi-config/init_resize.sh"

Next boot Rpi from your ssd,
First we need to create some more space on the disk. it's now 1.5G

Code: Select all

sudo fdisk /dev/sda
p – Print exiting partition table and take note of /dev/sda2 start (in my case it was 532480 but this is very important)
d and then 2 – to delete exiting partition /dev/sda2
np2 create new partition, set it primary, and its number 2
First sector – this is the magic number in my case it was 532480 and press enter.

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-8191, default 8191): +2.5G

Do you want to remove the signature? [Y]es/[N]o: n
w to save partition table q and exit fdisk
reboot the pi.

Code: Select all

sudo resize2fs /dev/sda2
If all went well we now have 2.5G

Now you have some more space to do the updates upgrades install your app's

I installed docker, docker-compose and mc
pub and private key's for secure login, set my hoste name and timezone.
If you are sure your done so no reboot's any more, then the last thing is edit

Code: Select all

sudo nano /boot/cmdline.txt
and add to the end init=/usr/lib/raspi-config/init_resize.sh again no enter no new line
save and

Code: Select all

sudo shutdown -h now
Now it is time to make the image,
if you made your pi bootable from usb, you must have a Micro SD with rpi os,
boot you pi from the Micro SD, hard drive not plugged in
connect your usb ssd to the pi.

Code: Select all

sudo parted /dev/sda unit s print
find the end sectors nummer last line of the output starts whit a 2 column end

Code: Select all

sudo dd if=/dev/sda of=/home/pi/clone.img count=your sector number
replace your sector number whit your number of sectors + 1

This will create a img about 2.6G in your home dir on your Micro SD..

I used WinSCP to copy the file from the Rpi to my windows machine

Return to “General discussion”