resizing a ext3 disk image

Took me a while to figure this out, so thought I’d put it here for others. This is useful for Xen setups, where you use a file for the disk image. AFAIK, you can only grow an image, not shrink it.

# dd if=/dev/zero bs=1M count=1024 >> disk.img
# e2fsck -f disk.img
# resize2fs disk.img
# e2fsck -f disk.img

This makes the disk image bigger, checks the image, resizes the file system, and then checks it again

5 thoughts on “resizing a ext3 disk image”

  1. Did not work for me on SLES11.

    # dd if=/dev/zero bs=1G count=100 >> disk0
    100+0 records in
    100+0 records out
    107374182400 bytes (107 GB) copied, 292.295 s, 367 MB/s
    # ls -l disk0
    -rw——- 1 root root 150323855360 Jun 14 17:25 disk0
    # e2fsck -f disk0
    e2fsck 1.41.1 (01-Sep-2008)
    e2fsck: Superblock invalid, trying backup blocks…
    e2fsck: Bad magic number in super-block while trying to open disk0

    The superblock could not be read or does not describe a correct ext2
    filesystem. If the device is valid and it really contains an ext2
    filesystem (and not swap or ufs or something else), then the superblock
    is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.