]>
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"
59 if ! [ -f .
/boot
/boot.img
]; then
60 if [ -d .
/grub
]; then
61 vterr
"Don't run me here, please download the released install package, and run there."
63 vterr
"Please run under the right directory!"
72 if [ "$file" != "xzcat" ]; then
73 if [ "$file" != "ventoy_lib.sh" ]; then
74 .
/xzcat
$file > ${file%.xz}
81 if ! check_tool_work_ok
; then
82 vterr
"Some tools can not run in current system. Please check log.txt for detail."
90 if ! [ -b "$DISK" ]; then
91 vterr
"Disk $DISK does not exist"
97 if [ -e /sys
/class
/block
/${DISK#/dev/}/start
]; then
98 vterr
"$DISK is a partition, please use the whole disk"
103 grep "^$DISK" /proc
/mounts
| while read mtline
; do
104 mtpnt
=$(echo $mtline | awk '{print $2}')
105 vtdebug
"Trying to umount $mtpnt ..."
106 umount
$mtpnt >/dev
/null
2>&1
109 if grep "$DISK" /proc
/mounts
; then
110 vterr
"$DISK is already mounted, please umount it first!"
116 if [ "$MODE" = "install" ]; then
117 vtdebug
"install ventoy ..."
119 if ! fdisk
-v >/dev
/null
2>&1; then
120 vterr
"fdisk is needed by ventoy installation, but is not found in the system."
125 version
=$(get_disk_ventoy_version $DISK)
126 if [ $?
-eq 0 ]; then
127 if [ -z "$FORCE" ]; then
128 vtwarn
"$DISK already contains a Ventoy with version $version"
129 vtwarn
"Use -u option to do a safe upgrade operation."
130 vtwarn
"OR if you really want to reinstall ventoy to $DISK, please use -I option."
137 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
138 disk_size_gb
=$(expr $disk_sector_num / 2097152)
140 if [ $disk_sector_num -gt 4294967296 ]; then
141 vterr
"$DISK is over 2TB size, MBR will not work on it."
148 parted
-s $DISK p
2>&1 | grep Model
149 echo "Size : $disk_size_gb GB"
153 vtwarn
"You will install Ventoy to $DISK."
154 vtwarn
"All the data on the disk $DISK will be lost!!!"
157 read -p 'Continue? (y/n)' Answer
158 if [ "$Answer" != "y" ]; then
159 if [ "$Answer" != "Y" ]; then
165 vtwarn
"All the data on the disk $DISK will be lost!!!"
166 read -p 'Double-check. Continue? (y/n)' Answer
167 if [ "$Answer" != "y" ]; then
168 if [ "$Answer" != "Y" ]; then
174 if [ $disk_sector_num -le $VENTOY_SECTOR_NUM ]; then
175 vterr
"No enough space in disk $DISK"
179 if ! dd if=/dev
/zero of
=$DISK bs
=1 count
=512 status
=none conv
=fsync
; then
180 vterr
"Write data to $DISK failed, please check whether it's in use."
184 format_ventoy_disk
$DISK
187 if ventoy_is_linux64
; then
188 cmd
=.
/tool
/mkexfatfs_64
190 cmd
=.
/tool
/mkexfatfs_32
195 # DiskSize > 32GB Cluster Size use 128KB
196 # DiskSize < 32GB Cluster Size use 32KB
197 if [ $disk_size_gb -gt 32 ]; then
203 $cmd -n ventoy
-s $cluster_sectors ${DISK}1
205 chmod +x .
/tool
/vtoy_gen_uuid
207 dd status
=none conv
=fsync
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=446
208 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=2047 seek
=1
209 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start_sector
212 .
/tool
/vtoy_gen_uuid
| dd status
=none conv
=fsync of
=${DISK} seek
=384 bs
=1 count
=16
215 .
/tool
/vtoy_gen_uuid
| dd status
=none conv
=fsync of
=${DISK} skip
=12 seek
=440 bs
=1 count
=4
220 vtinfo
"Install Ventoy to $DISK successfully finished."
224 vtdebug
"update ventoy ..."
226 oldver
=$(get_disk_ventoy_version $DISK)
227 if [ $?
-ne 0 ]; then
228 vtwarn
"$DISK does not contain ventoy or data corupted"
230 vtwarn
"Please use -i option if you want to install ventoy to $DISK"
236 curver
=$(cat ./ventoy/version)
238 vtinfo
"Upgrade operation is safe, all the data in the 1st partition (iso files and other) will be unchanged!"
241 read -p "Update Ventoy $oldver ===> $curver Continue? (y/n)" Answer
242 if [ "$Answer" != "y" ]; then
243 if [ "$Answer" != "Y" ]; then
249 PART2
=$(get_disk_part_name $DISK 2)
251 dd status
=none conv
=fsync
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=440
253 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=2047 seek
=1
255 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
256 part2_start
=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
257 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none conv
=fsync of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start
262 vtinfo
"Update Ventoy to $DISK successfully finished."