]>
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 ################"
29 if [ "$1" = "-i" ]; then
31 elif [ "$1" = "-I" ]; then
34 elif [ "$1" = "-u" ]; then
42 if ! [ -b "$2" ]; then
48 if [ -z "$SUDO_USER" ]; then
49 if [ "$USER" != "root" ]; then
50 vterr
"EUID is $EUID root permission is required."
57 vtdebug
"MODE=$MODE FORCE=$FORCE"
63 if [ "$file" != "xzcat" ]; then
64 if [ "$file" != "ventoy_lib.sh" ]; then
65 .
/xzcat
$file > ${file%.xz}
72 if ! check_tool_work_ok
; then
73 vterr
"Some tools can not run in current system. Please check log.txt for detail."
81 if ! [ -b "$DISK" ]; then
82 vterr
"Disk $DISK does not exist"
88 if [ -e /sys
/class
/block
/${DISK#/dev/}/start
]; then
89 vterr
"$DISK is a partition, please use the whole disk"
94 grep "^$DISK" /proc
/mounts
| while read mtline
; do
95 mtpnt
=$(echo $mtline | awk '{print $2}')
96 vtdebug
"Trying to umount $mtpnt ..."
97 umount
$mtpnt >/dev
/null
2>&1
100 if grep "$DISK" /proc
/mounts
; then
101 vterr
"$DISK is already mounted, please umount it first!"
107 if [ "$MODE" = "install" ]; then
108 vtdebug
"install ventoy ..."
110 if ! fdisk
-v >/dev
/null
2>&1; then
111 vterr
"fdisk is needed by ventoy installation, but is not found in the system."
116 version
=$(get_disk_ventoy_version $DISK)
117 if [ $?
-eq 0 ]; then
118 if [ -z "$FORCE" ]; then
119 vtwarn
"$DISK already contains a Ventoy with version $version"
120 vtwarn
"Use -u option to do a safe upgrade operation."
121 vtwarn
"OR if you really want to reinstall ventoy to $DISK, please use -I option."
128 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
129 disk_size_gb
=$(expr $disk_sector_num / 2097152)
131 if [ $disk_sector_num -gt 4294967296 ]; then
132 vterr
"$DISK is over 2TB size, MBR will not work on it."
139 parted
-s $DISK p
2>&1 | grep Model
140 echo "Size : $disk_size_gb GB"
144 vtwarn
"You will install Ventoy to $DISK."
145 vtwarn
"All the data on the disk $DISK will be lost!!!"
148 read -p 'Continue? (y/n)' Answer
149 if [ "$Answer" != "y" ]; then
150 if [ "$Answer" != "Y" ]; then
156 vtwarn
"All the data on the disk $DISK will be lost!!!"
157 read -p 'Double-check. Continue? (y/n)' Answer
158 if [ "$Answer" != "y" ]; then
159 if [ "$Answer" != "Y" ]; then
165 if [ $disk_sector_num -le $VENTOY_SECTOR_NUM ]; then
166 vterr
"No enough space in disk $DISK"
170 if ! dd if=/dev
/zero of
=$DISK bs
=1 count
=512 status
=none conv
=fsync
; then
171 vterr
"Write data to $DISK failed, please check whether it's in use."
175 format_ventoy_disk
$DISK
178 if ventoy_is_linux64
; then
179 cmd
=.
/tool
/mkexfatfs_64
181 cmd
=.
/tool
/mkexfatfs_32
186 # DiskSize > 32GB Cluster Size use 128KB
187 # DiskSize < 32GB Cluster Size use 32KB
188 if [ $disk_size_gb -gt 32 ]; then
194 $cmd -n ventoy
-s $cluster_sectors ${DISK}1
196 chmod +x .
/tool
/vtoy_gen_uuid
198 dd status
=none conv
=fsync
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=446
199 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=2047 seek
=1
200 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start_sector
203 .
/tool
/vtoy_gen_uuid
| dd status
=none conv
=fsync of
=${DISK} seek
=384 bs
=1 count
=16
206 .
/tool
/vtoy_gen_uuid
| dd status
=none conv
=fsync of
=${DISK} skip
=12 seek
=440 bs
=1 count
=4
211 vtinfo
"Install Ventoy to $DISK successfully finished."
215 vtdebug
"update ventoy ..."
217 oldver
=$(get_disk_ventoy_version $DISK)
218 if [ $?
-ne 0 ]; then
219 vtwarn
"$DISK does not contain ventoy or data corupted"
221 vtwarn
"Please use -i option if you want to install ventoy to $DISK"
227 curver
=$(cat ./ventoy/version)
229 vtinfo
"Upgrade operation is safe, all the data in the 1st partition (iso files and other) will be unchanged!"
232 read -p "Update Ventoy $oldver ===> $curver Continue? (y/n)" Answer
233 if [ "$Answer" != "y" ]; then
234 if [ "$Answer" != "Y" ]; then
240 PART2
=$(get_disk_part_name $DISK 2)
242 dd status
=none conv
=fsync
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=440
244 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=2047 seek
=1
246 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
247 part2_start
=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
248 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start
253 vtinfo
"Update Ventoy to $DISK successfully finished."