Update chroot

This commit is contained in:
Sathish Kumar
2023-02-07 07:28:15 +08:00
parent 3b7ca29033
commit d6c12d095f

View File

@@ -1,7 +1,6 @@
#!/bin/bash -ex #!/bin/bash -ex
ROOT="$PWD/rpi-root" ROOT="$PWD/rpi-root"
LOOP=12
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
echo "Usage: $0 <image> <exec>" echo "Usage: $0 <image> <exec>"
@@ -9,7 +8,8 @@ if [ $# -lt 1 ]; then
fi fi
IMAGE="$1" IMAGE="$1"
LOOP_DEV=/dev/loop${LOOP} LOOP_BOOT=
LOOP_ROOT=
EXEC= EXEC=
if [ $# -gt 1 ]; then if [ $# -gt 1 ]; then
@@ -26,25 +26,28 @@ fi
# Clean up on EXIT # Clean up on EXIT
function cleanup { function cleanup {
umount "$ROOT"/{dev/pts,dev,sys,proc,boot,mnt/host,} 2>/dev/null || true umount "$ROOT"/{dev/pts,dev,sys,proc,boot,mnt/host,} 2>/dev/null || true
losetup -d $LOOP_DEV 2>/dev/null || true losetup -d $LOOP_BOOT 2>/dev/null || true
losetup -d $LOOP_ROOT 2>/dev/null || true
rmdir "$ROOT" 2>/dev/null || true rmdir "$ROOT" 2>/dev/null || true
} }
trap cleanup EXIT trap cleanup EXIT
# set up image as loop device LOOP_BOOT=`losetup -f`
losetup $LOOP_DEV "$IMAGE" losetup -o 4194304 $LOOP_BOOT "$IMAGE"
partprobe $LOOP_DEV
LOOP_ROOT=`losetup -f`
losetup -o 48234496 $LOOP_ROOT "$IMAGE"
# check and fix filesystems # check and fix filesystems
fsck -f ${LOOP_DEV}p1 fsck -f $LOOP_BOOT
fsck -f ${LOOP_DEV}p2 fsck -f $LOOP_ROOT
# make dir # make dir
mkdir -p "$ROOT" mkdir -p "$ROOT"
# mount partition # mount partition
mount -o rw ${LOOP_DEV}p2 -t ext4 "$ROOT" mount -o rw $LOOP_ROOT -t ext4 "$ROOT"
mount -o rw ${LOOP_DEV}p1 "$ROOT/boot" mount -o rw $LOOP_BOOT "$ROOT/boot"
# mount binds # mount binds
mount --bind /dev "$ROOT/dev/" mount --bind /dev "$ROOT/dev/"