First try :
Based on the method explained by @jamesbond (viewtopic.php?p=121957#p121957)
Code: Select all
#!/bin/sh
truncate -s $@
LOOPn="$(losetup -f)"
losetup -f -P $2
{
echo d
echo 2
echo n
echo p
echo 2
echo
echo
echo w
} | fdisk $LOOPn
resize2fs -f "$LOOPn"p2
losetup -d $LOOPn
Make sure the script is executable
Example of use :
If the script is named truncate-easy (EDIT : and in the same directory than the img file)
Code: Select all
./truncate-easy 3G easy-6.1.img
will increase the size of easy-6.1.img to 3G
The format of the size in the arguments is the same as the format for the truncate command.
There is no verification of the arguments, no test about the requested size (must be bigger than the initial size)
Remark: When used in the terminal fdisk ask wether to keep the ext2 signature of a recreated partition,but not when used in the script