]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - INSTALL/ExtendPersistentImg.sh
4 echo 'Usage: ExtendPersistentImg.sh file size'
5 echo ' file persistent dat file'
6 echo ' size extend size in MB'
8 echo ' sh ExtendPersistentImg.sh ubuntu.dat 2048'
12 if [ -z "$1" -o "$1" = "-h" ]; then
23 if [ "$1" = "__vbash__" ]; then
26 if readlink
/bin
/sh
| grep -q bash
; then
29 exec /bin
/bash
$0 "__vbash__" "$@"
37 if [ ! -f "$file" ]; then
38 echo "$file not exist."
42 if echo $size | grep -q "^-"; then
49 if echo $size | grep -q "[^0-9]"; then
54 fsize
=$(stat -c '%s' $file)
56 fsmod
=$(expr $fsize % 1024)
57 if [ $fsmod -ne 0 ]; then
58 echo "File size of $file is not aligned by 1MB, please check."
63 fsMB
=$(expr $fsize / 1024 / 1024)
65 if [ "$mode" = "Extend" ]; then
66 total
=$(expr $fsMB + $size)
68 if [ $fsMB -le $size ]; then
69 echo "File size of $file is less than ${size}MB."
72 total
=$(expr $fsMB - $size)
76 magic
=$(hexdump -n3 -e '3/1 "%02X"' $file)
77 if [ "$magic" = "584653" ]; then
78 if [ "$mode" = "Shrink" ]; then
79 echo "Shrink is not supported for XFS filesystem."
83 if which xfs_growfs
>/dev
/null
2>&1; then
86 echo 'xfs_growfs not found, please install xfsprogs first'
90 if which resize2fs
>/dev
/null
2>&1; then
93 echo 'resize2fs not found, please install e2fsprogs first'
98 if [ "$mode" = "Extend" ]; then
99 echo "$mode dat file... (current is ${fsMB}MB, append ${size}MB, total ${total}MB)"
100 dd if=/dev
/zero bs
=1M count
=$size status
=none
>> "$file"
103 echo "$mode dat file... (current is ${fsMB}MB, reduce ${size}MB, finally ${total}MB)"
107 freeloop
=$(losetup -f)
108 losetup
$freeloop "$file"
110 if [ "$cmd" = "resize2fs" ]; then
111 echo "$mode ext filesystem by resize2fs ..."
112 echo "resize2fs $freeloop ${total}M"
114 resize2fs
$freeloop ${total}M
117 echo "$mode xfs filesystem by xfs_growfs ..."
119 mount
$freeloop $tmpdir
122 umount
$tmpdir && rm -rf $tmpdir
127 if [ $ret -eq 0 -a "$mode" = "Shrink" ]; then
128 echo "truncate persistent file ..."
129 truncate
"$file" -s ${total}M
134 if [ $ret -eq 0 ]; then
135 echo "======= SUCCESS ========="
137 echo "======= FAILED ========="