Resizing loop back fileystems

11.03.2006 at 21:40

I recently needed to resize an existing loop back fileystem which was created with dd after some research i came up with the following which worked fine for me.

First you need to get the current image size preferably in megabytes this can be done with

# du -m loop-back-image.img
300 loop-back-image.img

It says the size is 300mb, so here is how we can add another 100mb to it.

# dd if=/dev/zero of=loop-back-image.img bs=1M seek=300 count=100

seek=300 means that dd will start at this point which is the end, and count=100 tells dd to add 100mb to that point, so we end up with a total size of 400mb. Run resize2fs on the enlarged 400mb image, it will resize the ext2 filesystem on it to fill the image.

# resize2fs loop-back-image.img

If you want to reduce the loop back image size you first have to resize the filesystem on it.

# resize2fs loop-back-image.img 200M

Afterwards you can run 'dd' on the 300mb image to reduce it to 200mb.

# dd if=/dev/zero of=loop-back-image.img bs=1M seek=200 count=0

Again seek=200 says dd to start at 200mb and count=0 means that it should add nothing to that point so we end up with a total image size of 200mb.

Comments (0)

There are currently no comments available