]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/alpine/udev_disk_hook.sh
1.1.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 PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
23
24 wait_for_usb_disk_ready
25
26 vtdiskname=$(get_ventoy_disk_name)
27 if [ "$vtdiskname" = "unknown" ]; then
28 vtlog "ventoy disk not found"
29 PATH=$VTPATH_OLD
30 exit 0
31 fi
32
33 #
34 # longpanda:
35 # Alpine initramfs doesn't contain dm-mod or fuse module,
36 # and even the worse, the libpthread.so is not included too.
37 # So here we directly dump the modloop squashfs file from disk to rootfs.
38 # Fortunately, this file is not too big (< 100MB in alpine 3.11.3).
39 # After that:
40 # 1. mount the squashfs file
41 # 2. find the dm-mod module from the mountpoint and insmod
42 # 3. unmount and delete the squashfs file
43 #
44
45 MDEV="${vtdiskname#/dev/}2"
46
47 vtoydm -i -f $VTOY_PATH/ventoy_image_map -d /dev/${MDEV:0:-1} > $VTOY_PATH/iso_file_list
48
49 vtLine=$(grep '[-][-] modloop-lts ' $VTOY_PATH/iso_file_list)
50 sector=$(echo $vtLine | awk '{print $(NF-1)}')
51 length=$(echo $vtLine | awk '{print $NF}')
52
53 echo -n "Mounting boot media, please wait ......"
54 vtoydm -e -f $VTOY_PATH/ventoy_image_map -d /dev/${MDEV:0:-1} -s $sector -l $length -o /vt_modloop
55 echo "done"
56
57 mkdir -p $VTOY_PATH/mnt
58 mount /vt_modloop $VTOY_PATH/mnt
59
60 KoModPath=$(find $VTOY_PATH/mnt/ -name 'dm-mod.ko*')
61 vtlog "KoModPath=$KoModPath"
62
63 if modinfo $KoModPath | grep -q 'depend.*dax'; then
64 vtlog "First install dax mod ..."
65 DaxModPath=$(echo $KoModPath | sed 's#md/dm-mod#dax/dax#')
66 vtlog "insmod $DaxModPath"
67 insmod $DaxModPath
68 fi
69
70 insmod $KoModPath
71
72 umount $VTOY_PATH/mnt
73 rm -f /vt_modloop
74
75 ventoy_udev_disk_common_hook "$MDEV" "noreplace"
76
77 # OK finish
78 set_ventoy_hook_finish