How to install custom packages?
Hi,
I have a question, how to add to this installation custom packages or custom bash scripts?
I think the simplest option (which doesn't quite do what you want) is to expand the guestfish script create.gfs and copy the packages into a well-known location.
If you build the image on the Rock64 itself then you should be able to execute commands like pacman -U <package> from the guestfish script. This will do what you want.
If you, like me, want to build the image on a more powerful x86_64 machine, then it's a bit trickier.
From memory (so could be inaccurate), the issues arise because pacman in the image is built for aarch64 (ARM), and guestfish uses something called a supermin kernel as kernel, which is built for x86_64, so you basically can't run pacman out of the box. I never quite figured this out (it wasn't really worth the effort for what I needed), but I think it might be possible if you:
- use an aarch64 supermin kernel with guestfish
- use
binfmt_miscon thex86_64host to be able to transparently emulateaarch64code usingqemu.
Have a look at:
- https://libguestfs.org/guestfs-faq.1.html#broken-kernel-or-trying-a-different-kernel
- https://ownyourbits.com/2018/06/13/transparently-running-binaries-from-any-architecture-in-linux-with-qemu-and-binfmt_misc/
The ownyourbits article linked above is just something I found by searching the internet; it's long but the binfmt_misc thing isn't too bad in the end. I have a script hanging around that sets it up that looks something like this (sorry, I don't remember where I got it from, and I certainly don't recommend copy/pasting hexadecimal stuff off the internet if you don't understand or can't verify what it does):
#!/bin/bash
if [[ $UID != 0 ]]; then
echo "must be run as root/using sudo"
exit 1
fi
echo -1 > /proc/sys/fs/binfmt_misc/qemu-aarch64 || true
echo -1 > /proc/sys/fs/binfmt_misc/qemu-arm || true
echo ':qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64-static:OCF' > /proc/sys/fs/binfmt_misc/register
echo ':qemu-arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:OCF' > /proc/sys/fs/binfmt_misc/register
I never tried to cross-compile my own supermin kernel for aarch64.
Hope this helps. Let me know if you figure it out.