]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh
update
[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 install_udeb_from_line "$LINE" ${vt_usb_disk}
47 fi
48
49 # insmod md-mod if needed
50 if $GREP -q 'device-mapper' /proc/devices; then
51 vtlog "device mapper module is loaded"
52 else
53 vtlog"device mapper module is NOT loaded, now load it..."
54
55 VER=$($BUSYBOX_PATH/uname -r)
56 KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
57 vtlog "KO=$KO"
58
59 insmod $KO
60 fi
61
62 vtlog "dmsetup install finish, now check it..."
63 if dmsetup info >> $VTLOG 2>&1; then
64 vtlog "dmsetup work ok"
65 else
66 vtlog "dmsetup not work, now try to load eglibc ..."
67
68 # install eglibc (some ubuntu 32 bit version need it)
69 LINE=$($GREP 'libc6-.*\.udeb' $VTOY_PATH/iso_file_list)
70 if [ $? -eq 0 ]; then
71 install_udeb_from_line "$LINE" ${vt_usb_disk}
72 fi
73
74 if dmsetup info >> $VTLOG 2>&1; then
75 vtlog "dmsetup work ok after retry"
76 else
77 vtlog "dmsetup still not work after retry"
78 fi
79 fi
80 }
81
82 if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
83 exit 0
84 fi
85
86 dmsetup_path=$(ventoy_find_bin_path dmsetup)
87 if [ -z "$dmsetup_path" ]; then
88 ventoy_os_install_dmsetup "/dev/${1:0:-1}"
89 fi
90
91 if ! $GREP -q 'device-mapper' /proc/devices; then
92 ventoy_os_install_dmsetup "/dev/${1:0:-1}"
93 fi
94
95 ventoy_udev_disk_common_hook $*
96
97 #
98 # Some distro default only accept usb partitions as install medium.
99 # So if ventoy is installed on a non-USB device, we just mount /cdrom here except
100 # for these has boot=live or boot=casper parameter in cmdline
101 #
102 VT_BUS_USB=""
103 if [ -n "$ID_BUS" ]; then
104 if echo $ID_BUS | $GREP -q -i usb; then
105 VT_BUS_USB="YES"
106 fi
107 else
108 if $BUSYBOX_PATH/ls -l /sys/class/block/${1:0:-1} | $GREP -q -i usb; then
109 VT_BUS_USB="YES"
110 fi
111 fi
112
113 if [ -n "$VT_BUS_USB" ]; then
114 vtlog "$1 is USB device"
115 else
116 vtlog "$1 is NOT USB device (bus $ID_BUS)"
117
118 if $EGREP -q 'boot=|casper' /proc/cmdline; then
119 vtlog "boot=, or casper, don't mount"
120 else
121 vtlog "No boot param, need to mount"
122 $BUSYBOX_PATH/mkdir /cdrom
123
124 if [ -b $VTOY_DM_PATH ]; then
125 vtlog "mount $VTOY_DM_PATH ..."
126 $BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom
127 else
128 vtlog "mount /dev/$1 ..."
129 $BUSYBOX_PATH/mount -t iso9660 /dev/$1 /cdrom
130 fi
131 fi
132 fi
133
134
135 # OK finish
136 set_ventoy_hook_finish