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_chromeos_ventoy_part 3
64 vtlog "copy out the e2fsck program ..."
67 cp -a /ventoy_rdroot/usr/lib64/$1 /usr/lib64/
68 cp -a /ventoy_rdroot/lib64/$1 /lib64/
72 mkdir -p /lib /lib64 /usr/lib64 /sbin
74 mount -o ro /dev/ventoy3 /ventoy_rdroot >>$VTLOG 2>&1
75 cp -a /ventoy_rdroot/sbin/e2fsck /sbin/
76 cp -a /ventoy_rdroot/sbin/dmsetup /sbin/
89 copy_lib libdevmapper*
95 copy_lib libgpg-error*
109 ln -s /lib64/libdevmapper.so.1.02 /lib64/libdevmapper.so.1.02.1
111 umount /ventoy_rdroot
113 vtlog "========================================="
114 vtlog "===== e2fsck -y -v /dev/ventoy1 ====="
115 e2fsck -y -v /dev/ventoy1 >>$VTLOG 2>&1
116 #vtlog "===== e2fsck -y -v /dev/ventoy3 ====="
117 #e2fsck -y -v /dev/ventoy3 >>$VTLOG 2>&1
118 vtlog "===== e2fsck -y -v /dev/ventoy8 ====="
119 e2fsck -y -v /dev/ventoy8 >>$VTLOG 2>&1
120 vtlog "========================================="
122 /sbin/dmsetup --version >>$VTLOG 2>&1
123 veritysetup --version >>$VTLOG 2>&1
125 vtlog "proc devtmpfs ..."
127 mount -t devtmpfs dev /newdev
129 cp -a /dev/mapper/ventoy* /newdev/mapper/
130 cp -a /dev/ventoy* /newdev/
132 if [ "$VTOY_VLNK_BOOT" = "01" ]; then
133 vtLine=$($VTOY_PATH/tool/vtoydump -f /ventoy/ventoy_os_param)
134 vtdiskname=${vtLine%%#*}
137 vtshortname="${vtdiskname#/dev/}"
138 mv /newdev/${vtshortname} /newdev/backup_${vtshortname}
139 cp -a /dev/ventoy /newdev/${vtshortname}
141 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
142 if [ -e /dev/ventoy${i} ]; then
143 if echo $vtdiskname | egrep -q "nvme|mmc|nbd"; then
149 if [ -e /newdev/${vtshortname}${vtpart} ]; then
150 mv /newdev/${vtshortname}${vtpart} /newdev/backup_${vtshortname}${vtpart}
153 cp -a /dev/ventoy${i} /newdev/${vtshortname}${vtpart}
155 if [ $i -eq 3 ]; then
156 [ -e /dev/${vtshortname}${vtpart} ] && rm -f /dev/${vtshortname}${vtpart}
157 cp -a /dev/ventoy${i} /dev/${vtshortname}${vtpart}
158 vt_root_dev="/dev/${vtshortname}${vtpart}"
159 vtlog "vt_root_dev=$vt_root_dev"
165 # if grep -q 'DM
=' /proc/cmdline; then
166 # vtlog "Boot verified image ..."
168 # dmP1=$(sed "s/.*\(0 [0-9]* verity\).*/\1/" /proc/cmdline)
169 # alg=$(sed "s/.*alg=\([^ ]*\).*/\1/" /proc/cmdline)
170 # hexdigest=$(sed "s/.*root_hexdigest=\([0-9a-fA-F][0-9a-fA-F]*\).*/\1/" /proc/cmdline)
171 # salt=$(sed "s/.*salt=\([0-9a-fA-F][0-9a-fA-F]*\).*/\1/" /proc/cmdline)
172 # hashstart=$(sed "s/.*hashstart=\([0-9][0-9]*\).*/\1/" /proc/cmdline)
175 # blocknum=$(expr $hashstart / 8)
176 # hashoffset=$(expr $hashstart \* 512)
178 # vtlog "veritysetup create vroot $vt_root_dev $vt_root_dev $hexdigest --data-block-size=4096 --hash-block-size=4096 --data-blocks=$blocknum --hash-offset=$hashoffset --salt=$salt --hash=$alg --no-superblock --format=0"
179 # veritysetup create vroot $vt_root_dev $vt_root_dev $hexdigest --data-block-size=4096 --hash-block-size=4096 --data-blocks=$blocknum --hash-offset=$hashoffset --salt=$salt --hash=$alg --no-superblock --format=0
183 # blkdev_num=$(dmsetup ls | grep vroot | sed 's/.*(\([0-9][0-9]*\),[^0-9]*\([0-9][0-9]*\).*/\1:\2/')
184 # vtDM=$(ventoy_find_dm_id ${blkdev_num})
185 # vtlog "blkdev_num=$blkdev_num vtDM=$vtDM"
187 # if [ -b /dev/$vtDM ]; then
188 # veritysetup status vroot >> $VTLOG 2>&1
189 # mount -o ro /dev/$vtDM /ventoy_rdroot
191 # mount -o ro $vt_root_dev /ventoy_rdroot
194 # vtlog "Boot normal image ..."
195 # mount -o ro $vt_root_dev /ventoy_rdroot
198 vtlog
"Boot normal image ..."
199 mount
-o ro
$vt_root_dev /ventoy_rdroot
201 cp -a $VTLOG /newdev
/ventoy.log
203 mount
-t devtmpfs dev
/ventoy_rdroot
/dev