Go to ...


A Better Technical Repository

RSS Feed

Linux: Resize a linux image file

To resize your Debian IMG file – instructions are for people with linux computers or laptops:

Copy the ‘debian.img’ image file from your Phone’s SD card (in sdcard/debian) to your linux desktop.

Open a terminal on your linux computer and ‘su’ so you are root.

change directory to the desktop in unbuntu’s case it’s here, we do this so we can see whats going on easily:

cd /home/user/Desktop

create an empty image file: (the 3500999999 refers to the size – this one is 3.5 GB, basically take the first 4 digits and thats how many megabytes the image will be)

dd if=/dev/zero of=debian2.img seek=3500999999 bs=1 count=1

Your new image file is called debian2.img

Now do (you are still on your desktop linux machine here):

mkfs.ext2 -F debian2.img

Mount the 2 images (the old one and new empty one)

mkdir debian
mkdir debian2
mount -o loop debian.img debian
mount -o loop debian2.img debian2

Copy the contents of the old image into the new:

cd /home/user/Desktop/debian/

cp -r -f –preserve * /home/user/Desktop/debian2

Unmount files

umount debian
umount debian2

(sometimes this doesn’t work – so simply reboot)

e2fsck -F debian2

Once that’s done

Back to your linux computer desktop:

As root (su):

Delete the 2 folders debian and debian2

rm -r -f debian
rm -r -f debian2

delete your old image:

rm debian.img

rename the new image:

mv debian2.img debian.img

change permissions:

chmod a+x debian.img
chmod 777 debian.img

Then copy the newly created image into your phones /sdcard/debian folder (overwrite the original).

Finally on your phone boot debian shell as normal and at the localhost$ prompt do:

cd /var/lib/dpkg/updates

rm -r -f *


dpkg –configure -a (may take a few minutes, ignore the errors)

This gives you a 3.5GB image instead of the 720mb original image.