]>
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
25 if [ ! -f "$file" ]; then
26 echo "$file not exist."
30 if echo $size | grep -q "^-"; then
37 if echo $size | grep -q "[^0-9]"; then
42 fsize
=$(stat -c '%s' $file)
44 fsmod
=$(expr $fsize % 1024)
45 if [ $fsmod -ne 0 ]; then
46 echo "File size of $file is not aligned by 1MB, please check."
51 fsMB
=$(expr $fsize / 1024 / 1024)
53 if [ "$mode" = "Extend" ]; then
54 total
=$(expr $fsMB + $size)
56 if [ $fsMB -le $size ]; then
57 echo "File size of $file is less than ${size}MB."
60 total
=$(expr $fsMB - $size)
64 magic
=$(hexdump -n3 -e '3/1 "%02X"' $file)
65 if [ "$magic" = "584653" ]; then
66 if [ "$mode" = "Shrink" ]; then
67 echo "Shrink is not supported for XFS filesystem."
71 if which xfs_growfs
>/dev
/null
2>&1; then
74 echo 'xfs_growfs not found, please install xfsprogs first'
78 if which resize2fs
>/dev
/null
2>&1; then
81 echo 'resize2fs not found, please install e2fsprogs first'
86 if [ "$mode" = "Extend" ]; then
87 echo "$mode dat file... (current is ${fsMB}MB, append ${size}MB, total ${total}MB)"
88 dd if=/dev
/zero bs
=1M count
=$size status
=none
>> "$file"
91 echo "$mode dat file... (current is ${fsMB}MB, reduce ${size}MB, finally ${total}MB)"
95 freeloop
=$(losetup -f)
96 losetup
$freeloop "$file"
98 if [ "$cmd" = "resize2fs" ]; then
99 echo "$mode ext filesystem by resize2fs ..."
100 echo "resize2fs $freeloop ${total}M"
102 resize2fs
$freeloop ${total}M
105 echo "$mode xfs filesystem by xfs_growfs ..."
107 mount
$freeloop $tmpdir
110 umount
$tmpdir && rm -rf $tmpdir
115 if [ $ret -eq 0 -a "$mode" = "Shrink" ]; then
116 echo "truncate persistent file ..."
117 truncate
"$file" -s ${total}M
122 if [ $ret -eq 0 ]; then
123 echo "======= SUCCESS ========="
125 echo "======= FAILED ========="