2 #************************************************************************************
3 # Copyright (c) 2021, 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 mount
-t sysfs sys
/sys
32 usb_disk
=$(get_ventoy_disk_name)
34 if echo $usb_disk | egrep -q "nvme|mmc|nbd"; then
40 if [ -e "${vtpart2}" ]; then
48 vtdiskname
=$(get_ventoy_disk_name)
49 if [ "$vtdiskname" = "unknown" ]; then
50 vtlog
"ventoy disk not found"
55 ventoy_udev_disk_common_hook
"${vtdiskname#/dev/}2" "noreplace"
57 blkdev_num
=$($VTOY_PATH/tool/dmsetup ls | grep ventoy | sed 's/.*(\([0-9][0-9]*\),.
*\
([0-9][0-9]*\
).
*/\
1:\
2/')
58 vtDM=$(ventoy_find_dm_id ${blkdev_num})
59 echo -n $vtDM > /ventoy/vtDM
61 ventoy_create_dev_ventoy_part
64 vtlog "copy out the e2fsck program ..."
66 mkdir -p /lib /lib64 /usr/lib64 /sbin
68 mount -o ro /dev/ventoy3 /ventoy_rdroot >>$VTLOG 2>&1
69 cp -a /ventoy_rdroot/sbin/e2fsck /sbin/
70 cp -a /ventoy_rdroot/usr/lib64/libext2fs* /usr/lib64/
71 cp -a /ventoy_rdroot/usr/lib64/libcom_err* /usr/lib64/
72 cp -a /ventoy_rdroot/usr/lib64/libe2p* /usr/lib64/
73 cp -a /ventoy_rdroot/lib64/libblk* /lib64/
74 cp -a /ventoy_rdroot/lib64/libuuid* /lib64/
75 cp -a /ventoy_rdroot/lib64/libdl.* /lib64/
76 cp -a /ventoy_rdroot/lib64/libdl-* /lib64/
77 cp -a /ventoy_rdroot/lib64/libc.* /lib64/
78 cp -a /ventoy_rdroot/lib64/libc-* /lib64/
79 cp -a /ventoy_rdroot/lib64/libpthread* /lib64/
80 cp -a /ventoy_rdroot/lib64/ld-* /lib64/
84 vtlog "========================================="
85 vtlog "===== e2fsck -y -v /dev/ventoy1 ====="
86 e2fsck -y -v /dev/ventoy1 >>$VTLOG 2>&1
87 vtlog "===== e2fsck -y -v /dev/ventoy3 ====="
88 e2fsck -y -v /dev/ventoy3 >>$VTLOG 2>&1
89 vtlog "===== e2fsck -y -v /dev/ventoy8 ====="
90 e2fsck -y -v /dev/ventoy8 >>$VTLOG 2>&1
91 vtlog "========================================="
93 vtlog "proc devtmpfs ..."
95 mount -t devtmpfs dev /newdev
97 cp -a /dev/mapper/ventoy* /newdev/mapper/
98 cp -a /dev/ventoy* /newdev/
101 vtshortname="${vtdiskname#/dev/}"
102 mv /newdev/${vtshortname} /newdev/backup_${vtshortname}
103 cp -a /dev/ventoy /newdev/${vtshortname}
105 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
106 if [ -e /dev/ventoy${i} ]; then
107 if echo $vtdiskname | egrep -q "nvme|mmc|nbd"; then
113 if [ -e /newdev/${vtshortname}${vtpart} ]; then
114 mv /newdev/${vtshortname}${vtpart} /newdev/backup_${vtshortname}${vtpart}
117 cp -a /dev/ventoy${i} /newdev/${vtshortname}${vtpart}
119 if [ $i -eq 3 ]; then
120 [ -e /dev/${vtshortname}${vtpart} ] && rm -f /dev/${vtshortname}${vtpart}
121 cp -a /dev/ventoy${i} /dev/${vtshortname}${vtpart}
122 vt_root_dev="/dev/${vtshortname}${vtpart}"
123 vtlog "vt_root_dev=$vt_root_dev"
128 cp -a $VTLOG /newdev/ventoy.log
131 mount -o ro $vt_root_dev /ventoy_rdroot
132 mount -t devtmpfs dev /ventoy_rdroot/dev