losetup -f
losetup /dev/loop0 disk.img
e2fsck -f /dev/loop0
resize2fs /dev/loop0 6G
resize2fs 1.40-WIP (14-Nov-2006)
Resizing the filesystem on /dev/loop0 to 1572864 (4k) blocks.
The filesystem on /dev/loop0 is now 1572864 blocks long.
e2fsck -f /dev/loop0
losetup -d /dev/loop0
losetup /dev/loop0 disk.img
fsck -n /dev/loop0
fsck 1.40-WIP (14-Nov-2006)
e2fsck 1.40-WIP (14-Nov-2006)
/dev/loop0: clean, 112769/786432 files, 458389/1572864 blocks
eddard:/xens/domains/beta.osor.eu# tune2fs -O ^has_journal /dev/loop0
tune2fs 1.40-WIP (14-Nov-2006)
eddard:/xens/domains/beta.osor.eu# e2fsck -f /dev/loop0
e2fsck 1.40-WIP (14-Nov-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/loop0: 112769/786432 files (0.6% non-contiguous), 425587/1572864 blocks
For example, to create a 2GB sparse file-backed virtual block device (actually only consumes 1KB of disk):
# dd if=/dev/zero of=vm1disk bs=1k seek=2048k count=1
Make a file system in the disk file:
# mkfs -t ext3 vm1disk
(when the tool asks for confirmation, answer `y')
Populate the file system e.g. by copying from the current root:
# mount -o loop vm1disk /mnt
# cp -ax /{root,dev,var,etc,usr,bin,sbin,lib} /mnt
# mkdir /mnt/{proc,sys,home,tmp}
Tailor the file system by editing /etc/fstab, /etc/hostname, etc. Don't forget to edit the files in the mounted file system, instead of your domain 0 filesystem, e.g. you would edit /mnt/etc/fstab instead of /etc/fstab. For this example put /dev/sda1 to root in fstab.
Now unmount (this is important!):
# umount /mnt
In the configuration file set:
disk = ['file:/full/path/to/vm1disk,sda1,w']