]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/kaos/ventoy-disk.sh
c21c04c9d51fec27548d9f8972595ab641dd39ba
[Ventoy.git] / IMG / cpio / ventoy / hook / kaos / ventoy-disk.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 vtlog "######### $0 $* ############"
23
24 VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
25
26
27 ventoy_os_install_dmsetup_by_fuse() {
28 vtlog "ventoy_os_install_dmsetup_by_fuse $*"
29
30 mkdir -p $VTOY_PATH/mnt/fuse $VTOY_PATH/mnt/iso $VTOY_PATH/mnt/squashfs
31
32 vtoydm -p -f $VTOY_PATH/ventoy_image_map -d $1 > $VTOY_PATH/ventoy_dm_table
33 vtoy_fuse_iso -f $VTOY_PATH/ventoy_dm_table -m $VTOY_PATH/mnt/fuse
34
35 mount -t iso9660 $VTOY_PATH/mnt/fuse/ventoy.iso $VTOY_PATH/mnt/iso
36
37 sfsfile=$VTOY_PATH/mnt/iso/kdeos/x86_64/root-image.sqfs
38
39 mount -t squashfs $sfsfile $VTOY_PATH/mnt/squashfs
40
41 kVer=$(uname -r)
42 KoName=$(ls $VTOY_PATH/mnt/squashfs/lib/modules/$kVer/kernel/drivers/md/dm-mod.ko*)
43 vtlog "insmod $KoName"
44
45 if echo $KoName | grep -q '\.zst'; then
46 zstdcat $KoName > $VTOY_PATH/dm-mod.ko
47 insmod $VTOY_PATH/dm-mod.ko
48 else
49 insmod $KoName
50 fi
51
52 umount $VTOY_PATH/mnt/squashfs
53 umount $VTOY_PATH/mnt/iso
54 umount $VTOY_PATH/mnt/fuse
55 }
56
57
58 if is_ventoy_hook_finished; then
59 exit 0
60 fi
61
62 wait_for_usb_disk_ready
63
64 vtdiskname=$(get_ventoy_disk_name)
65 if [ "$vtdiskname" = "unknown" ]; then
66 vtlog "ventoy disk not found"
67 exit 0
68 fi
69
70 if grep -q 'device-mapper' /proc/devices; then
71 vtlog "device-mapper module exist"
72 else
73 ventoy_os_install_dmsetup_by_fuse $vtdiskname
74 fi
75
76 ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
77
78 blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
79 vtDM=$(ventoy_find_dm_id ${blkdev_num})
80 vtlog "blkdev_num=$blkdev_num vtDM=$vtDM ..."
81
82 while [ -n "Y" ]; do
83 if [ -b /dev/$vtDM ]; then
84 break
85 else
86 sleep 0.3
87 fi
88 done
89
90 if [ -n "$1" ]; then
91 vtlog "ln -s /dev/$vtDM $1"
92
93 if [ -e "$1" ]; then
94 vtlog "$1 already exist"
95 else
96 ln -s /dev/$vtDM "$1"
97 fi
98 else
99 vtLABEL=$($BUSYBOX_PATH/blkid /dev/$vtDM | $SED 's/.*LABEL="\([^"]*\)".*/\1/')
100 vtlog "vtLABEL is $vtLABEL"
101
102 if [ -z "$vtLABEL" ]; then
103 vtLABEL=$($SED "s/.*label=\([^ ]*\)/\1/" /proc/cmdline)
104 vtlog "vtLABEL is $vtLABEL from cmdline"
105 fi
106
107 if [ -e "/dev/disk/by-label/$vtLABEL" ]; then
108 vtlog "$1 already exist"
109 else
110 ln -s /dev/$vtDM "/dev/disk/by-label/$vtLABEL"
111 fi
112 fi
113
114 PATH=$VTPATH_OLD
115
116 # OK finish
117 set_ventoy_hook_finish