Skip to content

Instantly share code, notes, and snippets.

@cinderblock
Last active September 27, 2021 00:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cinderblock/20952a653989e55f8a7770a0ca2348a8 to your computer and use it in GitHub Desktop.
Save cinderblock/20952a653989e55f8a7770a0ca2348a8 to your computer and use it in GitHub Desktop.
Scripts to setup a Raspberry Pi OS image **before** flashing to SD card
@dimitry-ishenko
Copy link

@cinderblock I just downloaded fresh copy of Raspbian Buster Lite, unpacked it and did this:

Here is my chroot:

user@laptop:~/download$ ll chroot/
total 76
drwxr-xr-x  2 root root 4096 Feb 13 10:56 bin/
drwxr-xr-x  3 root root 4096 May 19 10:55 boot/
drwxr-xr-x  4 root root 4096 Feb 13 10:51 dev/
drwxr-xr-x 79 root root 4096 Feb 13 11:09 etc/
drwxr-xr-x  3 root root 4096 Feb 13 10:55 home/
drwxr-xr-x 16 root root 4096 Feb 13 10:58 lib/
drwx------  2 root root 4096 Feb 13 11:09 lost+found/
drwxr-xr-x  2 root root 4096 Feb 13 10:51 media/
drwxr-xr-x  2 root root 4096 Feb 13 10:51 mnt/
drwxr-xr-x  3 root root 4096 Feb 13 10:55 opt/
drwxr-xr-x  2 root root 4096 Feb  8 21:47 proc/
drwx------  2 root root 4096 May 19 10:56 root/
drwxr-xr-x  4 root root 4096 Feb 13 10:51 run/
drwxr-xr-x  2 root root 4096 Feb 13 10:58 sbin/
drwxr-xr-x  2 root root 4096 Feb 13 10:51 srv/
drwxr-xr-x  2 root root 4096 Feb  8 21:47 sys/
drwxrwxrwt  2 root root 4096 Feb 13 11:09 tmp/
drwxr-xr-x 10 root root 4096 Feb 13 10:51 usr/
drwxr-xr-x 11 root root 4096 Feb 13 10:51 var/

Check to make sure bash inside chroot is indeed an ARM binary:

user@laptop:~/download$ file chroot/bin/bash 
chroot/bin/bash: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=3e5e2847bbc51da2ab313bc53d4bdcff0faf2462, stripped

Check if I am cheating and somehow have copied qemu-static-binary into the chroot:

user@laptop:~/download$ ll chroot/usr/bin/qemu-arm-static
ls: cannot access 'chroot/usr/bin/qemu-arm-static': No such file or directory

Finally, chroot:

user@laptop:~/download$ sudo chroot ./chroot/ /bin/bash
root@laptop:/#

Boom, we are in.

@cinderblock
Copy link
Author

@dimitry-ishenko I think I might have run into problems trying this on a VPS so maybe it's the weird execution environment? I was getting a number of warnings from qemu about unimplemented calls. Trying again on a bare metal machine (x86-64 Intel i7-4770) seems to work without copying.

I guess it could also be just that that kernel is still slightly older (but 4.15.0-101-generic isn't that old). /etc/os-release says Ubuntu18.04 but I thought I was stuck on 17 at some point...

@dimitry-ishenko
Copy link

@cinderblock IIRC unimplemented calls are due to older qemu-{arm,aarch64}-* binaries and are mostly harmless. I used to get them on my 18.04 box as well. Google the exact error message, that's how I've found the explanation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment