]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/Ventoy2Disk.sh
5 if ! [ -f .
/tool
/ventoy_lib.sh
]; then
12 echo 'Usage: VentoyInstaller.sh OPTION /dev/sdX'
14 echo ' -i install ventoy to sdX (fail if disk already installed with ventoy)'
15 echo ' -u update ventoy in sdX'
16 echo ' -I force install ventoy to sdX (no matter installed or not)'
21 echo '***********************************************************'
22 echo '* Ventoy2Disk Script *'
23 echo '* longpanda admin@ventoy.net *'
24 echo '***********************************************************'
27 vtdebug
"############# Ventoy2Disk $0 ################"
30 if [ "$1" = "-i" ]; then
32 elif [ "$1" = "-I" ]; then
35 elif [ "$1" = "-u" ]; then
37 elif [ "$1" = "-s" ]; then
40 if ! [ -b "$1" ]; then
51 if [ -z "$MODE" ]; then
57 if [ -z "$SUDO_USER" ]; then
58 if [ "$USER" != "root" ]; then
59 vterr
"EUID is $EUID root permission is required."
66 vtdebug
"MODE=$MODE FORCE=$FORCE"
68 if ! [ -f .
/boot
/boot.img
]; then
69 if [ -d .
/grub
]; then
70 vterr
"Don't run me here, please download the released install package, and run there."
72 vterr
"Please run under the right directory!"
81 if [ "$file" != "xzcat" ]; then
82 if [ "$file" != "ventoy_lib.sh" ]; then
83 .
/xzcat
$file > ${file%.xz}
90 if ! check_tool_work_ok
; then
91 vterr
"Some tools can not run in current system. Please check log.txt for detail."
97 if ! [ -b "$DISK" ]; then
98 vterr
"Disk $DISK does not exist"
104 if [ -e /sys
/class
/block
/${DISK#/dev/}/start
]; then
105 vterr
"$DISK is a partition, please use the whole disk"
110 grep "^$DISK" /proc
/mounts
| while read mtline
; do
111 mtpnt
=$(echo $mtline | awk '{print $DISK}')
112 vtdebug
"Trying to umount $mtpnt ..."
113 umount
$mtpnt >/dev
/null
2>&1
116 if grep "$DISK" /proc
/mounts
; then
117 vterr
"$DISK is already mounted, please umount it first!"
123 if [ "$MODE" = "install" ]; then
124 vtdebug
"install ventoy ..."
126 if ! fdisk
-v >/dev
/null
2>&1; then
127 vterr
"fdisk is needed by ventoy installation, but is not found in the system."
132 version
=$(get_disk_ventoy_version $DISK)
133 if [ $?
-eq 0 ]; then
134 if [ -z "$FORCE" ]; then
135 vtwarn
"$DISK already contains a Ventoy with version $version"
136 vtwarn
"Use -u option to do a safe upgrade operation."
137 vtwarn
"OR if you really want to reinstall ventoy to $DISK, please use -I option."
144 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
145 disk_size_gb
=$(expr $disk_sector_num / 2097152)
147 if [ $disk_sector_num -gt 4294967296 ]; then
148 vterr
"$DISK is over 2TB size, MBR will not work on it."
155 parted
-s $DISK p
2>&1 | grep Model
156 echo "Size : $disk_size_gb GB"
160 vtwarn
"You will install Ventoy to $DISK."
161 vtwarn
"All the data on the disk $DISK will be lost!!!"
164 read -p 'Continue? (y/n)' Answer
165 if [ "$Answer" != "y" ]; then
166 if [ "$Answer" != "Y" ]; then
172 vtwarn
"All the data on the disk $DISK will be lost!!!"
173 read -p 'Double-check. Continue? (y/n)' Answer
174 if [ "$Answer" != "y" ]; then
175 if [ "$Answer" != "Y" ]; then
181 if [ $disk_sector_num -le $VENTOY_SECTOR_NUM ]; then
182 vterr
"No enough space in disk $DISK"
186 if ! dd if=/dev
/zero of
=$DISK bs
=1 count
=512 status
=none conv
=fsync
; then
187 vterr
"Write data to $DISK failed, please check whether it's in use."
191 format_ventoy_disk
$DISK
194 if ventoy_is_linux64
; then
195 cmd
=.
/tool
/mkexfatfs_64
197 cmd
=.
/tool
/mkexfatfs_32
202 # DiskSize > 32GB Cluster Size use 128KB
203 # DiskSize < 32GB Cluster Size use 32KB
204 if [ $disk_size_gb -gt 32 ]; then
210 $cmd -n ventoy
-s $cluster_sectors ${DISK}1
212 chmod +x .
/tool
/vtoy_gen_uuid
214 vtinfo
"writing data to disk ..."
215 dd status
=none conv
=fsync
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=446
216 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=2047 seek
=1
217 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start_sector
220 .
/tool
/vtoy_gen_uuid
| dd status
=none conv
=fsync of
=${DISK} seek
=384 bs
=1 count
=16
223 .
/tool
/vtoy_gen_uuid
| dd status
=none conv
=fsync of
=${DISK} skip
=12 seek
=440 bs
=1 count
=4
225 vtinfo
"sync data ..."
228 vtinfo
"esp partition processing ..."
230 if [ "$SECUREBOOT" != "YES" ]; then
233 vtdebug
"mounting part2 ...."
235 if mount
${DISK}2 .
/tmp_mnt
; then
236 vtdebug
"mounting part2 success"
242 rm -f .
/tmp_mnt
/EFI
/BOOT
/BOOTX64.EFI
243 rm -f .
/tmp_mnt
/EFI
/BOOT
/grubx64.efi
244 rm -f .
/tmp_mnt
/EFI
/BOOT
/MokManager.efi
245 mv .
/tmp_mnt
/EFI
/BOOT
/grubx64_real.efi .
/tmp_mnt
/EFI
/BOOT
/BOOTX64.EFI
252 vtinfo
"Install Ventoy to $DISK successfully finished."
256 vtdebug
"update ventoy ..."
258 oldver
=$(get_disk_ventoy_version $DISK)
259 if [ $?
-ne 0 ]; then
260 vtwarn
"$DISK does not contain ventoy or data corupted"
262 vtwarn
"Please use -i option if you want to install ventoy to $DISK"
268 curver
=$(cat ./ventoy/version)
270 vtinfo
"Upgrade operation is safe, all the data in the 1st partition (iso files and other) will be unchanged!"
273 read -p "Update Ventoy $oldver ===> $curver Continue? (y/n)" Answer
274 if [ "$Answer" != "y" ]; then
275 if [ "$Answer" != "Y" ]; then
281 PART2
=$(get_disk_part_name $DISK 2)
283 dd status
=none conv
=fsync
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=440
285 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=2047 seek
=1
287 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
288 part2_start
=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
289 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start
293 if [ "$SECUREBOOT" != "YES" ]; then
296 vtdebug
"mounting part2 ...."
298 if mount
${DISK}2 .
/tmp_mnt
; then
299 vtdebug
"mounting part2 success"
305 rm -f .
/tmp_mnt
/EFI
/BOOT
/BOOTX64.EFI
306 rm -f .
/tmp_mnt
/EFI
/BOOT
/grubx64.efi
307 rm -f .
/tmp_mnt
/EFI
/BOOT
/MokManager.efi
308 mv .
/tmp_mnt
/EFI
/BOOT
/grubx64_real.efi .
/tmp_mnt
/EFI
/BOOT
/BOOTX64.EFI
315 vtinfo
"Update Ventoy to $DISK successfully finished."