Raspberry Pi

Headless Setup : with Static IP, and without rpi-imager or DHCP

Bernard Karmilowicz


Notes:


1. Download the compressed image file:

$ wget https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2023-12-11/2023-12-11-raspios-bookworm-armhf-lite.img.xz

2. Determine the SHA256 checksum of the downloaded file, and compare it to the "integrity hash" of the file published at raspberrypi.com:

$ sha256sum 2023-12-11-raspios-bookworm-armhf-lite.img.xz

3. If the checksums match, then decompress the image file:

$ unxz 2023-12-11-raspios-bookworm-armhf-lite.img.xz

4. Image file information:

$ ls -l 2023-12-11-raspios-bookworm-armhf-lite.img
-rw-r--r-- 1 root root 2537553920 Dec 10 20:31 2023-12-11-raspios-bookworm-armhf-lite.img

5. Determine the sector size (in bytes) and partition offsets (in sectors) in the image file:

# fdisk -l 2023-12-11-raspios-bookworm-armhf-lite.img
Units: sectors of 1 * 512 = 512 bytes   <-- 512 will therefore be used when calculating offsets in bytes.
Device                                      Boot   Start     End Sectors  Size Id Type
2023-12-11-raspios-bookworm-armhf-lite.img1         8192 1056767 1048576  512M  c W95 FAT32 (LBA)       (this is the Linux "boot" partition)
2023-12-11-raspios-bookworm-armhf-lite.img2      1056768 4956159 3899392  1.9G 83 Linux                 (this is the Linux "root" partition)

6. Using the sector size and partition "start" locations show above; Calculate the offsets (in bytes) to the start of each of the two partitions:

- first  ("boot") partition offset: (512 *    8192) =   4194304
- second ("root") partition offset: (512 * 1056768) = 541065216

7. Using the calculated "boot" partition offset; Mount the image file's "boot" partition, and [1] temporarily enable the ssh daemon, [2] specify the user "fred" (who will be created upon "firstboot"), and [3] specify the parameters for eth0:

# mount -v -o offset=4194304 -t vfat 2023-12-11-raspios-bookworm-armhf-lite.img /mnt
# touch /mnt/ssh
# echo -n 'fred:$6$Bt0s/9vohKr3AoE/$5AGXvO7Dl12kTT4d0WWcFPoKdPOBLF3lbqu5MvjAGo9DS4Sry16CXfH4wJdlCiUmyjm9l6kePdDq.IJMdSrXd.' > /mnt/userconf
# vi /mnt/cmdline.txt  (append "ip=192.168.3.5::192.168.3.11:255.255.255.0:bedrock:eth0:off" to the list of kernel arguments)
# umount /mnt

8. Using the calaulated "root" partition offset; Mount the image file's "root" partition, and edit the network configuration files:

# mount -v -o offset=541065216 -t ext4 2023-12-11-raspios-bookworm-armhf-lite.img /mnt
    vi /mnt/etc/hostname                                ("bedrock")
    vi /mnt/etc/hosts                                   ("192.168.3.5 bedrock")
    vi /mnt/etc/resolv.conf                             ("nameserver 9.9.9.9")
    vi /mnt/etc/NetworkManager/NetworkManager.conf      ("managed=false" under the [ifupdown] section)
    vi /mnt/etc/network/interfaces                      ( add the following five lines: )
                                                                auto eth0
                                                                iface eth0 inet static
                                                                        address 192.168.3.5
                                                                        gateway 192.168.3.11
                                                                        netmask 255.255.255.0
# umount /mnt

9. Insert a SD card (that may be completely overwritten) into a computer from which the modified image file is visible.


10. Copy the modified image file to the SD card (/dev/mmcblk0):

# dd bs=512 if=2023-12-11-raspios-bookworm-armhf-lite.img of=/dev/mmcblk0 conv=fsync
# sync

11. Move the SD card to the Raspberry Pi, power-on the Raspberry Pi, and wait (perhaps 10 minutes) for the "firstboot" processes to finish running.


12. ssh to the Raspberry Pi, and change the password:

$ ssh -l fred 192.168.3.5  (password is "FreeUkraine")
$ passwd  (something other than "FreeUkraine" or "raspberry")

13. Remove the userconf file created during step 7 above:

$ sudo rm /userconf

14. Remove the kernel argument (i.e. "ip=192.168.3.5::192.168.3.11:255.255.255.0:bedrock:eth0:off") appended during step 7 above:

$ sudo vi /boot/firmware/cmdline.txt

15. Enable ssh for subsequent boots:

$ sudo systemctl enable ssh

16. Update raspbian's package-list, get/install the distro's updated/added packages, remove the older package (/var/cache/apt/*.deb) files, and reboot:

$ sudo apt update ; sudo apt full-upgrade ; sudo apt autoremove ; sudo apt clean
$ sudo reboot

17. ssh to the Raspberry Pi, and continue configuring the system:

$ ssh -l fred 192.168.3.5
$ sudo raspi-config

Last updated: 2024-04-12

background image