Question

I'm sure this has been asked before but I have no clue what to search for

I am trying to create a custom Linux image (for the Raspberry Pi) - I am currently manipulating the filesystem of the .img but I've discovered it's not as simple as dropping in the binary :( if only...

What is the accepted way to "pre-install" a package on a disk image where you can only manipulate the filesystem and ideally not run it first? Am I best to boot up, install, and then create the image from that, or is there a way of doing it beforehand in the same way you can change configuration settings etc?

Was it helpful?

Solution

Usually, when I have to change something in a disk image, I do the following:

sudo mount --bind /proc /mnt/disk_image/proc
sudo mount --bind /sys /mnt/disk_image/sys
sudo mount --bind /dev /mnt/disk_image/dev

These action are needed as this folder are create during boot process, mounting them in your system image will emulate a full boot. Then, you can chroot on it safely:

sudo chroot /mnt/disk_image

You're now able to issue commands in the chroot environment:

sudo apt-get install chromium

Of course, change /mnt/disk_image to the path where you have mounted your filesystem. apt-get will only works on Debian based system, change it according to your distribution.

You could find problem connecting to the internet and it can be cause by DNS configuration. The best thing you can do, is to copy your /etc/resolv.conf file in the remote filesystem as this file is usually changed by dhcp and it's empty on chroot environment.

This is the only solution that gives you full access to the command line of the system you're trying to modify.

OTHER TIPS

This is an untested idea:

The dpkg tool, which can install .deb packages, has a --root option which can set a different filesystem than the local / path.

From the man page:

   --instdir=dir
          Change default installation directory which refers to the
          directory where packages are to be installed. instdir  is
          also  the  directory  passed  to chroot(2) before running
          package’s installation  scripts,  which  means  that  the
          scripts see instdir as a root directory.  (Defaults to /)

   --root=dir
          Changing root changes instdir  to  dir  and  admindir  to
          dir/var/lib/dpkg.

If you mount your image and pass its mountpoint as --root, it should work.

There are things like the Ubuntu Customization Kit which allow you to create your own version of the distro with your own packages.

Crunchbang even has a utility like this, which is the distro I have personally selected for experimenting with my Pi.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top