I'm adding my own answer.
I wanted to enable 'ssh' on startup, connect via Ethernet, and not use Windows or OSX.
I downloaded an image file, '2019-09-26-raspbian-buster-lite.img' and then attempted to edit it. However, I couldn't mount the file. The file contains file systems, but is not a file system itself. The file systems can be listed out with a call to 'fdisk'.
Code: Select all
/sbin/fdisk -l 2019-09-26-raspbian-buster-lite.img
Disk 2019-09-26-raspbian-buster-lite.img: 2.1 GiB, 2248146944 bytes, 4390912 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x6c586e13
Device Boot Start End Sectors Size Id Type
2019-09-26-raspbian-buster-lite.img1 8192 532479 524288 256M c W95 FAT32 (LBA)
2019-09-26-raspbian-buster-lite.img2 532480 4390911 3858432 1.9G 83 Linux
There are four useful things to note.
- First, each sector is 512 bytes.
- Second, there are two devices.
- Third, the start sector of each device is listed.
- Fourth, the file system type of each device is listed.
The individual offsets file systems can be loaded by providing mount an offset. The following code will create an empty directory and then mount the first device to it. The python code calculates the offset. The 'mount' command expects its offset in bytes, so we have to multiply the start sector by the amount of bytes in a sector. After this, you should now be able to 'cd' into the device and make changes. This first device is the boot device. To add 'ssh' support, create an empty file at the root of the device called 'ssh'.
Code: Select all
mkdir pi-1
mount -o offset=$(python -c 'print 8192*512,') 2019-09-26-raspbian-buster-lite.img pi-1
When you're done, you can unmount the file.
You can also mount the pi's file system and change values in there. You need to do this if you want to connect to your Pi over Ethernet. The code is almost identical, but the start sector has changed and I've created a new directory to mount to.
Code: Select all
mkdir pi-2
mount -o offset=$(python -c 'print 532480*512,') 2019-09-26-raspbian-buster-lite.img pi-2
To switch to Ethernet, change your '/etc/network/interfaces' file in 'pi-2' to look like this.
Code: Select all
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
Your 'interfaces' file doesn't have to look exactly like this. The main thing is that you need the last two lines.
After these changes, you should be able to copy your image to your SD card, plug it into your pi, and connect over 'ssh' and Ethernet. Give your pi a few minutes to boot before you start losing your mind. If you have 'nmap' installed and using 'nmap' isn't a crime, you can run the following code to find your open 'ssh' port.
That says, check if port 22 is open on every address that starts with 10.0.0 This will work as long as the machines on your local network all have addresses prefixed with 10.0.0, but your home network may look different. Try using 'ip a' to see what your current machine's IP address or use the first 3 parts of your router's IP address.
I hope this helps a little.