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 rm -rf $VTOY_PATH/sqfs
47 dmModPath="/lib/modules/$vtKerVer/kernel/drivers/md/dm-mod.$vtKoPo"
48 echo $dmModPath > $VTOY_PATH/fsextract
49 vtoy_unsquashfs -d $VTOY_PATH/sqfs -n -q -e $VTOY_PATH/fsextract $VTOY_PATH/fsdisk
52 if [ -e $VTOY_PATH/sqfs${dmModPath} ]; then
53 vtlog "success $VTOY_PATH/sqfs${dmModPath}"
54 insmod $VTOY_PATH/sqfs${dmModPath}
61 ventoy_os_install_dmsetup_by_fuse() {
62 vtlog "ventoy_os_install_dmsetup_by_fuse $*"
64 mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
66 vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
67 vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
69 mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
70 mount -t squashfs $VTOY_PATH/mnt/iso/antiX/linuxfs $VTOY_PATH/mnt/squashfs
72 KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$2/kernel/drivers/md/dm-mod.ko*)
73 vtlog "insmod $KoName"
76 umount $VTOY_PATH/mnt/squashfs
77 umount $VTOY_PATH/mnt/iso
78 umount $VTOY_PATH/mnt/fuse
82 ventoy_os_install_dmsetup() {
83 vtlog "ventoy_os_install_dmsetup"
85 if grep -q 'device
-mapper' /proc/devices; then
86 vtlog "device-mapper module already loaded"
92 if ventoy_os_install_dmsetup_by_unsquashfs $1 $vtKerVer; then
93 vtlog "unsquashfs success"
95 if modprobe fuse 2>>$VTLOG; then
96 ventoy_os_install_dmsetup_by_fuse $1 $vtKerVer
102 wait_for_usb_disk_ready
104 vtdiskname=$(get_ventoy_disk_name)
105 if [ "$vtdiskname" = "unknown" ]; then
106 vtlog "ventoy disk not found"
111 ventoy_os_install_dmsetup $vtdiskname
113 ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
115 if ! [ -e $VTOY_DM_PATH ]; then
116 blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1 \2/')
117 mknod
-m 0666 $VTOY_DM_PATH b
$blkdev_num