-
Notifications
You must be signed in to change notification settings - Fork 2
/
umount-firmware
executable file
·27 lines (21 loc) · 888 Bytes
/
umount-firmware
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
#!/bin/sh
# check if firmware is mounted
if ! egrep -qs "^overlayfs:/firmware " /proc/mounts; then
echo "firmware is not mounted">&2
exit 1
fi
# search /proc/mounts for firmware's virtual mtd devices
rootfs=$(grep " /firmware/rom " /proc/mounts | cut -d" " -f1 | cut -d/ -f3 | sed 's/block//')
rootfsdata=$(grep " /firmware/overlay " /proc/mounts | cut -d" " -f1 | cut -d/ -f3 | sed 's/block//')
# map the virtual mtd devices to the corresponding loop devices
rootfs_loop=$(egrep "^${rootfs}:" /proc/mtd | cut -d\" -f2)
rootfsdata_loop=$(egrep "^${rootfsdata}:" /proc/mtd | cut -d\" -f2)
# umount all mountpoints
umount /firmware/overlay
umount /firmware/rom
umount /firmware
# remove virtual mtd devices (only possible by unloading the block2mtd kernel module)
rmmod block2mtd
# remove the corresponding loop devices
losetup -d ${rootfs_loop}
losetup -d ${rootfsdata_loop}