-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount-image.sh
executable file
·53 lines (49 loc) · 1.2 KB
/
mount-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
# Copyright (C) 2021 <Jerry Vonau>
IMAGE=$1
echo "$1"
local_losetup(){
losetup -P -f $IMAGE
sleep 2
LOOP=`losetup | grep $IMAGE | awk -F " " '{ print $1 }'`
echo "loop is $LOOP"
sleep 2
mkdir -p /mnt/img
mount "$LOOP"p2 /mnt/img
if [ -d /mnt/img/boot/firmware ]; then
mount "$LOOP"p1 /mnt/img/boot/firmware
else
mount "$LOOP"p1 /mnt/img/boot
fi
mount --bind /dev /mnt/img/dev
mount --bind /sys /mnt/img/sys
mount --bind /proc /mnt/img/proc
mv /mnt/img/etc/resolv.conf /mnt/img/etc/resolv.conf.hold
touch /mnt/img/etc/resolv.conf
mount --bind /etc/resolv.conf /mnt/img/etc/resolv.conf
if [ $(uname -m) = "x86_64" ];then
cp /usr/bin/qemu-arm-static /mnt/img/usr/bin/
fi
}
local_losetup
echo "ENTERING CHROOT"
chroot /mnt/img
sync
if [ -d /mnt/img/boot/firmware ]; then
umount /mnt/img/boot/firmware
else
umount /mnt/img/boot
fi
if [ -f /mnt/img/usr/bin/qemu-arm-static ]; then
rm /mnt/img/bin/qemu-arm-static
fi
umount /mnt/img/etc/resolv.conf
rm /mnt/img/etc/resolv.conf
mv /mnt/img/etc/resolv.conf.hold /mnt/img/etc/resolv.conf
umount /mnt/img/proc
umount /mnt/img/sys
umount /mnt/img/dev/pts >> /dev/null
umount /mnt/img/dev
umount /mnt/img
losetup -d "$LOOP"
echo "$IMAGE unmounted"