backup from ext3 to vfat with qcow2 images

by Martin Monperrus

It's difficult to backup data if the target filesystem of your backup is vfat (e.g. on the external hard drive of your sister), and the source is ext3. The reason is that vfat has much less features compared to ext3 (e.g. the group information).

Here is a solution to make a complete backup from ext3 to vfat including file attributes and symlinks. It uses QEMU's qcow2 image files. Even if the software used is related to QEMU, it does not imply at all the execution of a virtual machine. The main advantage of qcow2 is that the actual size of the image is not related to the size of the contained filesystem, but to the size of the contained data.

# 1. load the nbd kernel
$ modprobe nbd

# 2. create the image
# note that the maximum possible size for a file on a FAT32 volume is 4 GB
$ qemu-img create -f qcow2 backup-file.qcow2 4G

# 3. recognizing the Qqcow2 image as a block device
# qemu-nbd is standard
# if you like the risk you can also try qemu-diskp of fuseqemu
$ qemu-nbd --connect=/dev/nbd0 backup.qcow2

# 4. create the partitions with your tool of choice
$ cfdisk /dev/nbd0

# 5. create a file system
$ mkfs.ext3 /dev/nbd0p1

# 6. mount the file system
$ mount -t ext3 /dev/nbd0p1 /media/backup

# 7. make the backup, for example with rsync
$ rsync /home /media/backup

# 8. umount
$ umount /media/backup

# 9. disconnect
$ qemu-nbd -d /dev/nbd0

Tagged as: