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 vtlog
"####### $0 $* ########"
24 VTPATH_OLD
=$PATH; PATH
=$BUSYBOX_PATH:$VTOY_PATH/tool
:$PATH
27 ventoy_os_install_dmsetup_by_unsquashfs
() {
28 vtlog
"ventoy_os_install_dmsetup_by_unsquashfs $*"
30 vtKoPo
=$(ventoy_get_module_postfix)
31 vtlog
"vtKoPo=$vtKoPo"
33 vtoydm
-i -f $VTOY_PATH/ventoy_image_map
-d $1 > $VTOY_PATH/iso_file_list
35 vtline
=$(grep '[-][-] linuxfs ' $VTOY_PATH/iso_file_list)
36 sector
=$(echo $vtline | awk '{print $(NF-1)}')
37 length=$(echo $vtline | awk '{print $NF}')
39 vtoydm -E -f $VTOY_PATH/ventoy_image_map -d $1 -s $sector -l $length -o $VTOY_PATH/fsdisk
41 dmModPath="/usr/lib/modules/$vtKerVer/kernel/drivers/md/dm-mod.$vtKoPo"
42 echo $dmModPath > $VTOY_PATH/fsextract
43 vtoy_unsquashfs -d $VTOY_PATH/sqfs -n -q -e $VTOY_PATH/fsextract $VTOY_PATH/fsdisk
45 if ! [ -e $VTOY_PATH/sqfs${dmModPath} ]; then
46 dmModPath="/lib/modules/$vtKerVer/kernel/drivers/md/dm-mod.$vtKoPo"
47 echo $dmModPath > $VTOY_PATH/fsextract
48 vtoy_unsquashfs -d $VTOY_PATH/sqfs -n -q -e $VTOY_PATH/fsextract $VTOY_PATH/fsdisk
51 if [ -e $VTOY_PATH/sqfs${dmModPath} ]; then
52 vtlog "success $VTOY_PATH/sqfs${dmModPath}"
53 insmod $VTOY_PATH/sqfs${dmModPath}
60 ventoy_os_install_dmsetup_by_fuse() {
61 vtlog "ventoy_os_install_dmsetup_by_fuse $*"
63 mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
65 vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
66 vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
68 mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
69 mount -t squashfs $VTOY_PATH/mnt/iso/antiX/linuxfs $VTOY_PATH/mnt/squashfs
71 KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
72 vtlog "insmod $KoName"
75 umount $VTOY_PATH/mnt/squashfs
76 umount $VTOY_PATH/mnt/iso
77 umount $VTOY_PATH/mnt/fuse
81 ventoy_os_install_dmsetup() {
82 vtlog "ventoy_os_install_dmsetup"
84 if grep -q 'device
-mapper' /proc/devices; then
85 vtlog "device-mapper module already loaded"
91 if ventoy_os_install_dmsetup_by_unsquashfs $1 $vtKerVer; then
92 vtlog "unsquashfs success"
94 if modprobe fuse 2>>$VTLOG; then
95 ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
101 wait_for_usb_disk_ready
103 vtdiskname=$(get_ventoy_disk_name)
104 if [ "$vtdiskname" = "unknown" ]; then
105 vtlog "ventoy disk not found"
110 ventoy_os_install_dmsetup $vtdiskname
112 ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
114 if ! [ -e $VTOY_DM_PATH ]; then
115 blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
116 mknod
-m 0666 $VTOY_DM_PATH b
$blkdev_num