- Create a new mount directory rootfs
mkdir rootfs
- Mount rootfs.img to the created directory.
Before mounting, make a backup of the root file system image to prevent damage to the root file system that cannot be restored due to modification errors.
cp ubuntu.img ubuntu.img-bak
Mount the root filesystem image
sudo mount ubuntu.img rootfs/
ls rootfs/
Check if the mount is successful
- Mount
rootfs/
it to the host
using the mount scriptmnt.sh
to mount
Reference link: Ubuntu root file system custom
mnt.sh source code
#!/bin/bash
mnt() {
echo "MOUNTING"
sudo mount -t proc /proc ${2}proc
sudo mount -t sysfs /sys ${2}sys
sudo mount -o bind /dev ${2}dev
sudo mount -o bind /dev/pts ${2}dev/pts
# sudo mount /dev/sda1 ${2}
sudo chroot ${2}
}
umnt() {
echo "UNMOUNTING"
sudo umount ${2}proc
sudo umount ${2}sys
# sudo umount ${2}dev/sda1
sudo umount ${2}dev/pts
sudo umount ${2}dev
}
if [ "$1" == "-m" ] && [ -n "$2" ] ;
then
mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
then
umnt $1 $2
else
echo ""
echo "Either 1'st, 2'nd or both parameters were missing"
echo ""
echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
echo ""
echo "For example: ch-mount -m /media/sdcard/"
echo ""
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
Mount command:
sudo ./mnt.sh -m rootfs/
After the target file is mounted, it needs to be /
added. After the mount is successful, the terminal user will display asroot
- Modify the root file system image
At this point, you can modify the root file system in the operating environment of the host machine, and you can directly use the download command to install the commands required by the root file system, and the downloaded command will be directly installed in the root file system - Exit the root file system mirror mount
exit
- Uninstall the root file system image from the host
Uninstall command:
sudo ./mnt.sh -u rootfs/
- Unmount the root file system mirror mount point
sudo umount rootfs
After successfully unmounting the root file system image, the changes have been saved to the root file system image
Summary: This article mainly uses the chroot command to mount the root file system to the host for modification