2 #************************************************************************************
3 # Copyright (c) 2020, longpanda <admin@ventoy.net>
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.
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.
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/>.
18 #************************************************************************************
20 .
/ventoy
/hook
/ventoy
-hook-lib.sh
22 ventoy_os_install_dmsetup
() {
24 vtlog
"ventoy_os_install_dmsetup $1 ..."
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
32 LINE
=$($GREP ' dmsetup.*\.udeb' $VTOY_PATH/iso_file_list)
34 install_udeb_from_line
"$LINE" ${vt_usb_disk}
37 # install libdevmapper
38 LINE
=$($GREP ' libdevmapper.*\.udeb' $VTOY_PATH/iso_file_list)
40 install_udeb_from_line
"$LINE" ${vt_usb_disk}
44 LINE
=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list)
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 LINE
=$($GREP ' md-modules.*\.udeb' $VTOY_PATH/iso_file_list | $GREP $VER)
52 install_udeb_from_line
"$LINE" ${vt_usb_disk}
55 # insmod md-mod if needed
56 if $GREP -q 'device-mapper' /proc
/devices
; then
57 vtlog
"device mapper module is loaded"
59 vtlog
"device mapper module is NOT loaded, now load it..."
61 VER
=$($BUSYBOX_PATH/uname -r)
62 KO
=$($FIND /lib/modules/$VER/kernel/drivers/md -name "dm-mod*")
68 vtlog
"dmsetup install finish, now check it..."
69 if dmsetup info
>> $VTLOG 2>&1; then
70 vtlog
"dmsetup work ok"
72 vtlog
"dmsetup not work, now try to load eglibc ..."
74 # install eglibc (some ubuntu 32 bit version need it)
75 LINE
=$($GREP 'libc6-.*\.udeb' $VTOY_PATH/iso_file_list)
77 install_udeb_from_line
"$LINE" ${vt_usb_disk}
80 if dmsetup info
>> $VTLOG 2>&1; then
81 vtlog
"dmsetup work ok after retry"
83 vtlog
"dmsetup still not work after retry"
88 if is_ventoy_hook_finished
|| not_ventoy_disk
"${1:0:-1}"; then
92 vtlog
"==== $0 $* ===="
94 dmsetup_path
=$(ventoy_find_bin_path dmsetup)
95 if [ -z "$dmsetup_path" ]; then
96 ventoy_os_install_dmsetup
"/dev/${1:0:-1}"
99 if ! $GREP -q 'device-mapper' /proc
/devices
; then
100 ventoy_os_install_dmsetup
"/dev/${1:0:-1}"
103 ventoy_udev_disk_common_hook $
*
106 # Some distro default only accept usb partitions as install medium.
107 # So if ventoy is installed on a non-USB device, we just mount /cdrom here except
108 # for these has boot=live or boot=casper parameter in cmdline
111 if [ -n "$ID_BUS" ]; then
112 if echo $ID_BUS | $GREP -q -i usb
; then
116 if $BUSYBOX_PATH/ls -l /sys
/class
/block
/${1:0:-1} | $GREP -q -i usb
; then
121 if [ -n "$VT_BUS_USB" ]; then
122 vtlog
"$1 is USB device"
124 vtlog
"$1 is NOT USB device (bus $ID_BUS)"
126 if $EGREP -q 'boot=|casper' /proc
/cmdline
; then
127 vtlog
"boot=, or casper, don't mount"
129 vtlog
"No boot param, need to mount"
130 $BUSYBOX_PATH/mkdir /cdrom
132 if [ -b $VTOY_DM_PATH ]; then
133 vtlog
"mount $VTOY_DM_PATH ..."
134 $BUSYBOX_PATH/mount
-t iso9660
$VTOY_DM_PATH /cdrom
136 vtlog
"mount /dev/$1 ..."
137 $BUSYBOX_PATH/mount
-t iso9660
/dev
/$1 /cdrom
144 set_ventoy_hook_finish