]>
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 "[^0-9]"; then
35 fsize
=$(stat -c '%s' $file)
37 fsmod
=$(expr $fsize % 1024)
38 if [ $fsmod -ne 0 ]; then
39 echo "File size of $file is not aligned by 1MB, please check."
44 fsMB
=$(expr $fsize / 1024 / 1024)
45 total
=$(expr $fsMB + $size)
47 magic
=$(hexdump -n3 -e '3/1 "%02X"' $file)
48 if [ "$magic" = "584653" ]; then
49 if which xfs_growfs
>/dev
/null
2>&1; then
52 echo 'xfs_growfs not found, please install xfsprogs first'
56 if which resize2fs
>/dev
/null
2>&1; then
59 echo 'resize2fs not found, please install e2fsprogs first'
65 echo "Extend dat file... (current is ${fsMB}MB, append ${size}MB, total ${total}MB)"
66 dd if=/dev
/zero bs
=1M count
=$size status
=none
>> "$file"
69 freeloop
=$(losetup -f)
70 losetup
$freeloop "$file"
72 if [ "$cmd" = "resize2fs" ]; then
73 echo "Extend ext filesystem by resize2fs ..."
74 echo "resize2fs $freeloop ${total}M"
76 resize2fs
$freeloop ${total}M
79 echo "Extend xfs filesystem by xfs_growfs ..."
82 mount
$freeloop $tmpdir
85 umount
$tmpdir && rm -rf $tmpdir
91 if [ $ret -eq 0 ]; then
92 echo "======= SUCCESS ========="
94 echo "======= FAILED ========="