i have installed ubuntu-21.10-preinstalled-desktop-arm64+raspi.img.xz. is it possible to edit /boot/config.txt from the file itself so that we need not boot into the pi and then edit the config.txt and reboot? why not just directly edit the config.txt from the file and boot into the pi with that custom image? note so far i have opened the .img file from the downloaded .img.xz file without extracting and have got 2 mounted volumes "system-boot" and "writable".
1 Answer
You can loop mount the image on a Linux machine then edit using normal tools.
The following is a script I use, but frankly is more work than just editing files.
#!/bin/bash
# 2020-01-19
# Mount partitions on an OS Image
# Assumes only 2 partitions boot & root exist in Image
BOOT_MOUNT='/mnt/SDA1'
ROOT_MOUNT='/mnt/SDA2'
# IMG='/mnt/Image/BusterBackup.img'
IMG="$1"
# echo $IMG
errexit()
{
echo ""
echo "$1"
echo ""
exit 1
}
if [[ "${IMG}" = "" ]]; then
errexit "Usage: $0 imagefile"
fi
if [ $(id -u) -ne 0 ]; then
errexit "$0 must be run as root user"
fi
# Check/create Mount Points
if [ ! -e $BOOT_MOUNT ]; then
mkdir $BOOT_MOUNT
fi
if [ ! -e $ROOT_MOUNT ]; then
mkdir $ROOT_MOUNT
fi
# Check Mount Points
if $(mountpoint -q $BOOT_MOUNT); then
errexit "Mountpoint $BOOT_MOUNT already in use"
fi
if $(mountpoint -q $ROOT_MOUNT); then
errexit "Mountpoint $ROOT_MOUNT already in use"
fi
# Loop mount all partitions on Image
LOOP="$(losetup --find --partscan --show ${IMG})"
if [ $? -ne 0 ]; then
errexit "Unable to create loop device"
fi
# echo $LOOP
SD1=$LOOP
SD2=$LOOP
SD1+="p1" # partition containing boot files
SD2+="p2" # partition containing OS files
# exit
# Mount Partitions 1 & 2
if ! $(mountpoint -q $BOOT_MOUNT); then
mount $SD1 $BOOT_MOUNT # mount partition containing boot files
fi
if ! $(mountpoint -q $ROOT_MOUNT); then
mount $SD2 $ROOT_MOUNT # mount root partition containing OS files
fi
echo "When finished, run:"
echo "sudo umount ${BOOT_MOUNT} ${ROOT_MOUNT}"
echo "sudo losetup -d ${LOOP}"
echo ""
-
didn't really work, it mounted everything as read only. had to edit the file as it was using everything except the actual /dev/loop* being used. Jan 5 at 14:55
/boot
is just where it is mounted on a booted Raspberry Pi OS system. Regardless the boot partition should be FAT32 - which can be read on any OS. If you really want to use Ubuntu you need to do it their way.