Ubuntu 9.10 uses ext4 filesystems by default and it’s usually a Good Thing to not mess with defaults early in the installation.
That precept worked up to the point where I wanted to make a full-partition backup before doing something potentially catastrophic… at which point I discovered that the current version of System Rescue CD has a version of partimage that doesn’t know about ext4 filesystems. While FSArchiver looks promising, all I really wanted was a quick-and-simple backup and (possibly) restoration.
So. Once again, dd to the rescue.
This being a fresh installation, there’s not much other data to contend with. In fact, the installation uses under 3 GB, but it’s in a 32 GB partition. Wouldn’t It Would Be Nice If we could back up just the 10% of useful data and skip the rest?
Reboot to System Rescue CD (hereinafter, SRC) and, while that’s happening, plug in a spare hard drive using a USB-to-SATA converter. That will be the “backup drive”.
Mount the backup drive (which appeared as /dev/sdf1 and will be different for you) at /mnt/backup, which is conveniently provided by SRC:
mount /dev/sdf1 /mnt/backup
Mount the partition to be backed up (which is /dev/sda8 and will be different for you) at /mnt/custom, another existing mount point.
mount /dev/sda8 /mnt/custom
Zero out all the unused space by creating one honkin’ big file, then erase it leaving all those highly compressible zeros behind:
dd bs=1M if=/dev/zero of=/mnt/custom/zero.bin sync rm /mnt/custom/zero.bin
Unmount the partition, make the backup, and save the MBR while you’re at it:
umount /mnt/custom dd bs=1M if=/dev/sda1 | gzip -c -3 > /mnt/backup/boxname-sda8-ext4-32GB.bin.gz dd bs=512 count=1 if=/dev/sda of=/mnt/backup/boxname-mbr.bin
The bs=1M option sets a decent blocksize for the read operations, which gets dd trundling along at a pretty good clip by reducing the per-read overhead.
The -c option tells gzip to pipe the output to stdout and not mess with the input file. The -3 says to not waste a lot of time trying to compress the data; much of the partition consists of raw binary executables, so there’s no point. The whole process will be limited by disk I/O speed, most likely.
As it happened, the partition squeezed down into about 1.8 GB worth of gzipped backup file.
Unmount the backup drive, reboot, and do risky things…
As it turned out, I actually had to restore the partition.
Once again, boot into SRC with the backup drive plugged in, mount the backup drive. Restoration is straightforward:
gunzip -c /mnt/backup/boxname-sda8-ext4-32GB.bin.gz | dd bs=1M of=/dev/sda8
Warning: if you bungle the target of that dd, you are so screwed.
You’re both saving and restoring from a specific partition (/dev/sda8, in my case) within the drive, not the whole drive (which would be /dev/sda). Pay attention to what’s on the screen, check twice, and have a full-drive backup lurking in your fireproof safe…