]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh
add support for austrumi64-4.3.5.iso/slacko64-7.0.iso
[Ventoy.git] / IMG / cpio / ventoy / hook / debian / 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 ventoy_os_install_dmsetup() {
23
24 vtlog "ventoy_os_install_dmsetup $1 ..."
25
26 vt_usb_disk=$1
27
28 # dump iso file location
29 $VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list
30
31 # install dmsetup
32 LINE=$($GREP ' dmsetup.*\.udeb' $VTOY_PATH/iso_file_list)
33 if [ $? -eq 0 ]; then
34 install_udeb_from_line "$LINE" ${vt_usb_disk}
35 fi
36
37 # install libdevmapper
38 LINE=$($GREP ' libdevmapper.*\.udeb' $VTOY_PATH/iso_file_list)
39 if [ $? -eq 0 ]; then
40 install_udeb_from_line "$LINE" ${vt_usb_disk}
41 fi
42
43 # install md-modules
44 LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
45 if [ $? -eq 0 ]; then
46 LINTCNT=$($GREP -c ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
47 if [ $LINTCNT -gt 1 ]; then
48 vtlog "more than one pkgs, need to filter..."
49 VER=$($BUSYBOX_PATH/uname -r)
50
51 LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP $VER)
52 LINTCNT=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -c $VER)
53 if [ $LINTCNT -gt 1 ]; then
54 vtlog "Still more than one pkgs, use the first one..."
55 LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP -m1 $VER)
56 fi
57 fi
58 install_udeb_from_line "$LINE" ${vt_usb_disk}
59 fi
60
61 # insmod md-mod if needed
62 if $GREP -q 'device-mapper' /proc/devices; then
63 vtlog "device mapper module is loaded"
64 else
65 vtlog "device mapper module is NOT loaded, now load it..."
66
67 VER=$($BUSYBOX_PATH/uname -r)
68 KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
69 vtlog "KO=$KO"
70
71 insmod $KO
72 fi
73
74 vtlog "dmsetup install finish, now check it..."
75 if dmsetup info >> $VTLOG 2>&1; then
76 vtlog "dmsetup work ok"
77 else
78 vtlog "dmsetup not work, now try to load eglibc ..."
79
80 # install eglibc (some ubuntu 32 bit version need it)
81 LINE=$($GREP 'libc6-.*\.udeb' $VTOY_PATH/iso_file_list)
82 if [ $? -eq 0 ]; then
83 install_udeb_from_line "$LINE" ${vt_usb_disk}
84 fi
85
86 if dmsetup info >> $VTLOG 2>&1; then
87 vtlog "dmsetup work ok after retry"
88 else
89 vtlog "dmsetup still not work after retry"
90 fi
91 fi
92 }
93
94 if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
95 exit 0
96 fi
97
98 vtlog "==== $0 $* ===="
99
100 dmsetup_path=$(ventoy_find_bin_path dmsetup)
101 if [ -z "$dmsetup_path" ]; then
102 ventoy_os_install_dmsetup "/dev/${1:0:-1}"
103 fi
104
105 if ! $GREP -q 'device-mapper' /proc/devices; then
106 ventoy_os_install_dmsetup "/dev/${1:0:-1}"
107 fi
108
109 ventoy_udev_disk_common_hook $*
110
111 #
112 # Some distro default only accept usb partitions as install medium.
113 # So if ventoy is installed on a non-USB device, we just mount /cdrom here except
114 # for these has boot=live or boot=casper parameter in cmdline
115 #
116 VT_BUS_USB=""
117 if [ -n "$ID_BUS" ]; then
118 if echo $ID_BUS | $GREP -q -i usb; then
119 VT_BUS_USB="YES"
120 fi
121 else
122 if $BUSYBOX_PATH/ls -l /sys/class/block/${1:0:-1} | $GREP -q -i usb; then
123 VT_BUS_USB="YES"
124 fi
125 fi
126
127 if [ -n "$VT_BUS_USB" ]; then
128 vtlog "$1 is USB device"
129 echo /dev/$1 > /ventoy/list-devices-usb-part
130 else
131 vtlog "$1 is NOT USB device (bus $ID_BUS)"
132
133 if $EGREP -q 'boot=|casper' /proc/cmdline; then
134 vtlog "boot=, or casper, don't mount"
135 else
136 vtlog "No boot param, need to mount"
137 echo /dev/$1 > /ventoy/list-devices-usb-part
138 fi
139 fi
140
141
142 # OK finish
143 set_ventoy_hook_finish