]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/hook/easystartup/disk_hook.sh
Merge branch 'master' of https://github.com/Ventoy/Ventoy
[Ventoy.git] / IMG / cpio / ventoy / hook / easystartup / disk_hook.sh
1 #!/ventoy/busybox/sh
2 #************************************************************************************
3 # Copyright (c) 2021, 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 VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
23
24 get_rhel_ver() {
25 if uname -m | grep -q '64'; then
26 machine='_X64'
27 fi
28
29 if grep -q '6[.]1' /etc/redhat-release; then
30 echo "RHAS6U1$machine"; return
31 fi
32
33 echo "RHAS6U1$machine"
34 }
35
36 install_dm_mod_ko() {
37 # dump iso file location
38 vtoydm -i -f $VTOY_PATH/ventoy_image_map -d ${vtdiskname} > $VTOY_PATH/iso_file_list
39
40 sysver=$(get_rhel_ver)
41 vtlog "sysver=$sysver"
42
43 LINE=$(grep "$sysver" -n -m1 $VTOY_PATH/iso_file_list | awk -F: '{print $1}')
44 vtlog "LINE=$LINE"
45
46 LINE=$(sed -n "$LINE,\$p" $VTOY_PATH/iso_file_list | grep -m1 'initrd.img')
47 vtlog "LINE=$LINE"
48
49 sector=$(echo $LINE | $AWK '{print $(NF-1)}')
50 length=$(echo $LINE | $AWK '{print $NF}')
51 vtlog "sector=$sector length=$length"
52
53 mkdir xxx
54 vtoydm -e -f $VTOY_PATH/ventoy_image_map -d ${vtdiskname} -s $sector -l $length -o ./xxx.img
55
56 cd xxx/
57 zcat ../xxx.img | cpio -idmu
58 ko=$(find -name dm-mod.ko*)
59 vtlog "ko=$ko ..."
60 insmod $ko
61
62 cd ../
63 rm -f xxx.img
64 rm -rf xxx
65 }
66
67 vtdiskname=$(get_ventoy_disk_name)
68 vtlog "vtdiskname=$vtdiskname ..."
69 if [ "$vtdiskname" = "unknown" ]; then
70 exit 0
71 fi
72
73 if grep -q 'device-mapper' /proc/devices; then
74 vtlog "device-mapper module check ko"
75 else
76 install_dm_mod_ko
77 fi
78
79 ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
80
81 blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
82 vtDM=$(ventoy_find_dm_id ${blkdev_num})
83 cp -a /dev/$vtDM /dev/ventoy
84 ln -s /dev/$vtDM /dev/root
85
86 PATH=$VTPATH_OLD
87
88 set_ventoy_hook_finish
89