]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - IMG/cpio/ventoy/loop/openwrt/ventoy-disk.sh
1.1.07 release
[Ventoy.git] / IMG / cpio / ventoy / loop / openwrt / 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 if is_ventoy_hook_finished; then
23 exit 0
24 fi
25
26 vtlog "####### $0 $* ########"
27
28 VTPATH_OLD=$PATH; PATH=$BUSYBOX_PATH:$VTOY_PATH/tool:$PATH
29
30 check_mkdev_node() {
31 for i in $(ls /sys/class/block/); do
32 if ! [ -e /dev/$i ]; then
33 blkdev_num=$(sed 's/:/ /g' /sys/class/block/$i/dev)
34 vtlog "mknod -m 0666 /dev/$i b $blkdev_num"
35 mknod -m 0666 /dev/$i b $blkdev_num
36 fi
37 done
38 }
39
40 check_insmod() {
41 if [ -f "$1" ]; then
42 vtlog "insmod $1"
43 insmod "$1" >> $VTOY_PATH/log 2>&1
44 else
45 vtlog "$1 not exist"
46 fi
47 }
48
49 wrt_insmod() {
50 kbit=$1
51 kv=$(uname -r)
52
53 vtlog "insmod $kv $kbit"
54
55 check_insmod /ventoy_openwrt/$kv/$kbit/dax.ko
56 check_insmod /ventoy_openwrt/$kv/$kbit/dm-mod.ko
57 }
58
59 insmod_dm_mod() {
60 if grep -q "device-mapper" /proc/devices; then
61 vtlog "device-mapper enabled by system 0"
62 return
63 fi
64
65 check_insmod /ventoy/modules/dax.ko
66 check_insmod /ventoy/modules/dm-mod.ko
67
68 if grep -q "device-mapper" /proc/devices; then
69 vtlog "device-mapper enabled by system 1"
70 return
71 fi
72
73 if [ -f /ventoy_openwrt.xz ]; then
74 tar xf /ventoy_openwrt.xz -C /
75 rm -f /ventoy_openwrt.xz
76 fi
77
78 if uname -m | egrep -q "amd64|x86_64"; then
79 wrt_insmod 64
80 else
81 wrt_insmod generic
82 if lsmod | grep -q 'dm-mod'; then
83 vterr "insmod generic failed"
84 else
85 wrt_insmod legacy
86 fi
87 fi
88 }
89
90 insmod_dm_mod
91
92 check_mkdev_node
93 sleep 1
94
95 while [ -n "Y" ]; do
96 vtusb_disk=$(get_ventoy_disk_name)
97 if check_usb_disk_ready "$vtusb_disk"; then
98 vtlog "get_ventoy_disk_name $vtusb_disk ready"
99 break;
100 else
101 vtlog "get_ventoy_disk_name $vtusb_disk not ready"
102 sleep 2
103 check_mkdev_node
104 fi
105 done
106
107
108 vtdiskname=$(get_ventoy_disk_name)
109 if [ "$vtdiskname" = "unknown" ]; then
110 vtlog "ventoy disk not found"
111 PATH=$VTPATH_OLD
112 exit 0
113 fi
114
115 ventoy_udev_disk_common_hook "${vtdiskname#/dev/}2" "noreplace"
116
117 blkdev_num=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.*\([0-9][0-9]*\).*/\1:\2/')
118 vtDM=$(ventoy_find_dm_id ${blkdev_num})
119 echo -n $vtDM > /ventoy/vtDM
120
121 ventoy_create_dev_ventoy_part
122 mdev -s
123 check_mkdev_node
124
125
126 mkdir /ventoy_rdroot
127 mount /dev/ventoy2 /ventoy_rdroot
128
129 PATH=$VTPATH_OLD
130
131 set_ventoy_hook_finish