]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/debian/udev_disk_hook.sh
1.0.06 release
[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 vt_usb_disk=$1
25
26 # dump iso file location
27 $VTOY_PATH/tool/vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vt_usb_disk} > $VTOY_PATH/iso_file_list
28
29 # install dmsetup
30 LINE=$($GREP ' dmsetup.*\.udeb' $VTOY_PATH/iso_file_list)
31 if [ $? -eq 0 ]; then
32 install_udeb_from_line "$LINE" ${vt_usb_disk}
33 fi
34
35 # install libdevmapper
36 LINE=$($GREP ' libdevmapper.*\.udeb' $VTOY_PATH/iso_file_list)
37 if [ $? -eq 0 ]; then
38 install_udeb_from_line "$LINE" ${vt_usb_disk}
39 fi
40
41 # install md-modules
42 LINE=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
43 if [ $? -eq 0 ]; then
44 install_udeb_from_line "$LINE" ${vt_usb_disk}
45 fi
46
47 # insmod md-mod if needed
48 if $GREP -q 'device-mapper' /proc/devices; then
49 vtlog "device mapper module is loaded"
50 else
51 vtlog"device mapper module is NOT loaded, now load it..."
52
53 VER=$($BUSYBOX_PATH/uname -r)
54 KO=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
55 vtlog "KO=$KO"
56
57 insmod $KO
58 fi
59
60 vtlog "dmsetup install finish, now check it..."
61 if dmsetup info >> $VTLOG 2>&1; then
62 vtlog "dmsetup work ok"
63 else
64 vtlog "dmsetup not work, now try to load eglibc ..."
65
66 # install eglibc (some ubuntu 32 bit version need it)
67 LINE=$($GREP 'libc6-.*\.udeb' $VTOY_PATH/iso_file_list)
68 if [ $? -eq 0 ]; then
69 install_udeb_from_line "$LINE" ${vt_usb_disk}
70 fi
71
72 if dmsetup info >> $VTLOG 2>&1; then
73 vtlog "dmsetup work ok after retry"
74 else
75 vtlog "dmsetup still not work after retry"
76 fi
77 fi
78 }
79
80 if is_ventoy_hook_finished || not_ventoy_disk "${1:0:-1}"; then
81 exit 0
82 fi
83
84 dmsetup_path=$(ventoy_find_bin_path dmsetup)
85 if [ -z "$dmsetup_path" ]; then
86 ventoy_os_install_dmsetup "/dev/${1:0:-1}"
87 fi
88
89 ventoy_udev_disk_common_hook $*
90
91 #
92 # Some distro default only accept usb partitions as install medium.
93 # So if ventoy is installed on a non-USB device, we just mount /cdrom here except
94 # for these has boot=live or boot=casper parameter in cmdline
95 #
96 if echo $ID_BUS | $GREP -q -i usb; then
97 vtlog "$1 is USB device"
98 else
99 vtlog "$1 is NOT USB device (bus $ID_BUS)"
100
101 if $EGREP -q 'boot=|casper' /proc/cmdline; then
102 vtlog "boot=, or casper, don't mount"
103 else
104 vtlog "No boot param, need to mount"
105 $BUSYBOX_PATH/mkdir /cdrom
106 $BUSYBOX_PATH/mount -t iso9660 $VTOY_DM_PATH /cdrom
107 fi
108 fi
109
110 # OK finish
111 set_ventoy_hook_finish