KaloyanP
Posts: 3
Joined: Tue Apr 10, 2018 10:57 am

How to pre-install packages on custom image (pi-gen)

Wed Dec 05, 2018 9:28 am

Hello,

I am looking to create a custom Pi image so I can deploy multiple devices quickly. I have looked into a few tutorials on using pi-gen, but I couldn't find one that shows how to install new packages or compile packages inside the image.

Ideally I am looking to preinstall certain utilities, such as vim, OpenVPN, Google MFA, etc, so that I can then generate individual images for my devices through a script that just populates certificates on the image.

Second, I would like to be able to do all compilation of packages such as OpenCV and GStreamer on a more powerful machine and then use the image on the Pi. I have tried doing this using Ansible, and its painful!

I have previously tried to do this via Ansible on each new device, but this is untenable as it extends image generation from a 10-15 minute SD card burning step to a several hour installation process.

Pi-gen project: https://github.com/RPi-Distro/pi-gen
Other help thread: viewtopic.php?t=187114
Tutorial on how to set up wifi and SSH: http://kmdouglass.github.io/posts/creat ... art-1.html

hommar
Posts: 171
Joined: Sat Mar 25, 2017 1:55 pm
Location: Russia, Yekaterinburg

Re: How to pre-install packages on custom image (pi-gen)

Wed Dec 05, 2018 10:46 am

Easy use rPi for it

(boot from mmcblk0)
0) dd original.img to sda
1) mount / as /mnt (sda2)
2) mount /boot as /mnt/boot (sda1)
3)

Code: Select all

mount -t proc proc /mnt/proc
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /sys /mnt/sys
4) chroot /mnt
5) apt update && apt install mc && apt autoclean
6) exit
7) umount all previous mount points
Last edited by hommar on Wed Dec 05, 2018 6:39 pm, edited 3 times in total.

KaloyanP
Posts: 3
Joined: Tue Apr 10, 2018 10:57 am

Re: How to pre-install packages on custom image (pi-gen)

Wed Dec 05, 2018 11:31 am

Thanks for your reply, hommar!

I am not sure I understand - are you suggesting that I chroot into the image from a Raspberry Pi? Does it matter what OS I `chroot` into the image from? If I `chroot` from a Mac or a Ubuntu 16.04 machine, will it usually work or are there any kernel-level differences that might break the process?

hommar
Posts: 171
Joined: Sat Mar 25, 2017 1:55 pm
Location: Russia, Yekaterinburg

Re: How to pre-install packages on custom image (pi-gen)

Wed Dec 05, 2018 12:04 pm

boot from raspbian-lite on rPi
If you can use other (non Arm) need use Qemu

but if boot from raspbian-lite on rPi do not need Qemu

PS I use my rPi only for make my raspbian-custom-for-russian-users bucouse this is easy

PPS He who makes no mistakes makes nothing.
need do it for undestend it

Paul Hutch
Posts: 370
Joined: Fri Aug 25, 2017 2:58 pm
Location: Blackstone River Valley, MA, USA
Contact: Website

Re: How to pre-install packages on custom image (pi-gen)

Wed Dec 05, 2018 3:06 pm

Here's what I do to create my custom starting point images.
  1. Configure one of the a stock Raspbian images the way I want it.
  2. Delete the DUID (DHCP Unique Identifier) file so that a new DUID is created when a new Pi boots

    Code: Select all

    sudo rm /etc/dhcpcd.duid
  3. Put the uSd card in another Pi
  4. Change to the directory where you want to store the new image
  5. Create the image file

    Code: Select all

    sudo dd bs=4M if=/dev/sdc of=temp.img status=progress
  6. (Optional)Process the image file through PiShrink to save space and allow it to fit on smaller uSD cards
    https://github.com/Drewsif/PiShrink

    Code: Select all

    sudo /home/pi/PiShrink/pishrink.sh temp.img my_custom_image_name_vXX.img
  7. Test the new image by burning it to a uSD card and booting up
  8. (Optional)If all is well delete the temporary image file (temp.img)

Return to “Advanced users”