]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/Ventoy2Disk.sh
6 echo 'Usage: VentoyInstaller.sh OPTION /dev/sdX'
8 echo ' -i install ventoy to sdX (fail if disk already installed with ventoy)'
9 echo ' -u update ventoy in sdX'
10 echo ' -I force install ventoy to sdX (no matter installed or not)'
15 echo '***********************************************************'
16 echo '* Ventoy2Disk Script *'
17 echo '* longpanda admin@ventoy.net *'
18 echo '***********************************************************'
21 vtdebug
"############# Ventoy2Disk ################"
23 if ! [ -e ventoy
/version
]; then
24 vterr
"Please run under the correct directory!"
28 if [ "$1" = "-i" ]; then
30 elif [ "$1" = "-I" ]; then
33 elif [ "$1" = "-u" ]; then
40 if ! [ -b "$2" ]; then
45 if [ -z "$SUDO_USER" ]; then
46 if [ "$USER" != "root" ]; then
47 vterr
"EUID is $EUID root permission is required."
53 vtdebug
"MODE=$MODE FORCE=$FORCE"
59 if [ "$file" != "xzcat" ]; then
60 if [ "$file" != "ventoy_lib.sh" ]; then
61 .
/xzcat
$file > ${file%.xz}
68 if ! check_tool_work_ok
; then
69 vterr
"Some tools can not run in current system. Please check log.txt for detail."
76 if ! [ -b "$DISK" ]; then
77 vterr
"Disk $DISK does not exist"
82 if [ -e /sys
/class
/block
/${DISK#/dev/}/start
]; then
83 vterr
"$DISK is a partition, please use the whole disk"
87 if grep "$DISK" /proc
/mounts
; then
88 vterr
"$DISK is already mounted, please umount it first!"
93 if [ "$MODE" = "install" ]; then
94 vtdebug
"install ventoy ..."
96 if ! fdisk
-v >/dev
/null
2>&1; then
97 vterr
"fdisk is needed by ventoy installation, but is not found in the system."
101 version
=$(get_disk_ventoy_version $DISK)
102 if [ $?
-eq 0 ]; then
103 if [ -z "$FORCE" ]; then
104 vtwarn
"$DISK already contains a Ventoy with version $version"
105 vtwarn
"Use -u option to do a safe upgrade operation."
106 vtwarn
"OR if you really want to reinstall ventoy to $DISK, please use -I option."
112 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
113 disk_size_gb
=$(expr $disk_sector_num / 2097152)
115 if [ $disk_sector_num -gt 4294967296 ]; then
116 vterr
"$DISK is over 2TB size, MBR will not work on it."
122 parted
-s $DISK p
2>&1 | grep Model
123 echo "Size : $disk_size_gb GB"
127 vtwarn
"You will install Ventoy to $DISK."
128 vtwarn
"All the data on the disk $DISK will be lost!!!"
131 read -p 'Continue? (y/n)' Answer
132 if [ "$Answer" != "y" ]; then
133 if [ "$Answer" != "Y" ]; then
139 vtwarn
"All the data on the disk $DISK will be lost!!!"
140 read -p 'Double-check. Continue? (y/n)' Answer
141 if [ "$Answer" != "y" ]; then
142 if [ "$Answer" != "Y" ]; then
148 if [ $disk_sector_num -le $VENTOY_SECTOR_NUM ]; then
149 vterr
"No enough space in disk $DISK"
153 if ! dd if=/dev
/zero of
=$DISK bs
=1 count
=512 status
=none
; then
154 vterr
"Write data to $DISK failed, please check whether it's in use."
158 format_ventoy_disk
$DISK
161 if ventoy_is_linux64
; then
162 cmd
=.
/tool
/mkexfatfs_64
164 cmd
=.
/tool
/mkexfatfs_32
169 # DiskSize > 32GB Cluster Size use 128KB
170 # DiskSize < 32GB Cluster Size use 32KB
171 if [ $disk_size_gb -gt 32 ]; then
177 $cmd -n ventoy
-s $cluster_sectors ${DISK}1
179 chmod +x .
/tool
/vtoy_gen_uuid
181 dd status
=none
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=446
182 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none of
=$DISK bs
=512 count
=2047 seek
=1
183 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start_sector
186 .
/tool
/vtoy_gen_uuid
| dd status
=none of
=${DISK} seek
=384 bs
=1 count
=16
189 .
/tool
/vtoy_gen_uuid
| dd status
=none of
=${DISK} skip
=12 seek
=440 bs
=1 count
=4
194 vtinfo
"Install Ventoy to $DISK successfully finished."
198 vtdebug
"update ventoy ..."
200 oldver
=$(get_disk_ventoy_version $DISK)
201 if [ $?
-ne 0 ]; then
202 vtwarn
"$DISK does not contain ventoy or data corupted"
204 vtwarn
"Please use -i option if you want to install ventoy to $DISK"
209 curver
=$(cat ./ventoy/version)
211 vtinfo
"Upgrade operation is safe, all the data in the 1st partition (iso files and other) will be unchanged!"
214 read -p "Update Ventoy $oldver ===> $curver Continue? (y/n)" Answer
215 if [ "$Answer" != "y" ]; then
216 if [ "$Answer" != "Y" ]; then
221 PART2
=$(get_disk_part_name $DISK 2)
223 dd status
=none
if=.
/boot
/boot.img of
=$DISK bs
=1 count
=440
225 .
/tool
/xzcat .
/boot
/core.img.xz
| dd status
=none of
=$DISK bs
=512 count
=2047 seek
=1
227 disk_sector_num
=$(cat /sys/block/${DISK#/dev/}/size)
228 part2_start
=$(expr $disk_sector_num - $VENTOY_SECTOR_NUM)
229 .
/tool
/xzcat .
/ventoy
/ventoy.disk.img.xz
| dd status
=none of
=$DISK bs
=512 count
=$VENTOY_SECTOR_NUM seek
=$part2_start
234 vtinfo
"Update Ventoy to $DISK successfully finished."