How to install apt packages into mounted system image (img file)
1
vote
1
answer
2730
views
I need to edit/prepare debian-based Raspbian system image for multiple Raspberry Pi devices.
Until now, my modifications consisted in adding or changing existing config files.
I wrote script like this (to mount partitions from img file):
IMGFILE='edited-raspbian.img'
MNTDIR='/mnt/'$IMGFILE'/'
LOOPDEVICE=$(sudo losetup -f)
sudo losetup -P $LOOPDEVICE $IMGFILE
PARTITIONS=$(sudo fdisk -l $LOOPDEVICE | grep $LOOPDEVICE'*p' | cut -d$' ' -f 1 | cut -d$'/' -f 3)
while IFS= read -r PARTITION; do
MNTDIRPART=$MNTDIR'/'${PARTITION: -2}
sudo mkdir -p $MNTDIRPART
sudo mount "/dev/$PARTITION" "$MNTDIRPART"
done <<< "$PARTITIONS"
After I run it I see and edit '/' and '/boot' partitions from image in directories:
/mnt/edited-raspbian.img/p1
/mnt/edited-raspbian.img/p2
---
My question is:
How can I install apt packages "into image"?
Can I just chroot to directory, where image
/
partition is mounted and run apt install
?
To simplify everything I can work on Raspberry Pi with Raspbian (normally I'm editing these images on latest Debian).
Asked by Kamil
(799 rep)
Jan 9, 2021, 04:54 PM
Last activity: Jan 9, 2021, 07:11 PM
Last activity: Jan 9, 2021, 07:11 PM