]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/alpine/udev_disk_hook.sh
1.0.07 release
[Ventoy.git] / IMG / cpio / ventoy / hook / alpine / udev_disk_hook.sh
1 #!/ventoy/busybox/sh
2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 3 of the
8 # License, or (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, see <http://www.gnu.org/licenses/>.
17 #
18 #************************************************************************************
19
20 . /ventoy/hook/ventoy-hook-lib.sh
21
22 if [ "$SUBSYSTEM" != "block" ] || [ "$DEVTYPE" != "partition" ]; then
23 exit 0
24 fi
25
26 if [ -b /dev/${MDEV:0:-1} ]; then
27 vtlog "/dev/${MDEV:0:-1} exist"
28 else
29 $SLEEP 2
30 fi
31
32 if is_ventoy_hook_finished || not_ventoy_disk "${MDEV:0:-1}"; then
33 exit 0
34 fi
35
36 PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
37
38 #
39 # longpanda:
40 # Alpine initramfs doesn't contain dm-mod or fuse module,
41 # and even the worse, the libpthread.so is not included too.
42 # So here we directly dump the modloop squashfs file from disk to rootfs.
43 # Fortunately, this file is not too big (< 100MB in alpine 3.11.3).
44 # After that:
45 # 1. mount the squashfs file
46 # 2. find the dm-mod module from the mountpoint and insmod
47 # 3. unmount and delete the squashfs file
48 #
49
50 vtoydm -i -f $VTOY_PATH/ventoy_image_map -d /dev/${MDEV:0:-1} > $VTOY_PATH/iso_file_list
51
52 vtLine=$(grep '[-][-] modloop-lts ' $VTOY_PATH/iso_file_list)
53 sector=$(echo $vtLine | awk '{print $(NF-1)}')
54 length=$(echo $vtLine | awk '{print $NF}')
55
56 vtoydm -e -f $VTOY_PATH/ventoy_image_map -d /dev/${MDEV:0:-1} -s $sector -l $length -o /vt_modloop
57
58 mkdir -p $VTOY_PATH/mnt
59 mount /vt_modloop $VTOY_PATH/mnt
60
61 KoModPath=$(find $VTOY_PATH/mnt/ -name 'dm-mod.ko*')
62 vtlog "insmod $KoModPath"
63 insmod $KoModPath
64
65 umount $VTOY_PATH/mnt
66 rm -f /vt_modloop
67
68 ventoy_udev_disk_common_hook "$MDEV" "noreplace"
69
70 # OK finish
71 set_ventoy_hook_finish