CD/DVD Filesystem Snapshot
This will work with other filesystems, not just ext2, so you may want to choose a filesystem that is similar to what you currently run (if you care). The idea is that instead of creating an ISO image that is very flexible (can be read by Windows), you create a filesystem image and burn it to disc. The advantage of this is that you can preserve filesystem properties such as permissions, ownership, etc. The disadvantage is that the straightforward approach (everything on one disk) only gives you about 4.5 G of space to work with (depending on the media size).
(1) Create a 2 GB image:
sudo dd if=/dev/zero of=snapshot.img bs=1024k count=2000 &
You can create a larger image size if you need it, and your burnable media can handle it.
(2) Format it using ext2
sudo mke2fs -m 0 -q -F -b 2048 snapshot.img 1>&2
Honestly, I can’t remember why I was redirecting output to stderr. Maybe I had a good reason for that. But suffice it to say, you simply want to use the file you created to make a file system. For example, instead of the above, you can use something like `mkfs -t xfs snapshot.img`
(3) Mount the image
sudo mount -t ext2 -o loop snapshot.img /mnt/snapshot
For the mount, you want to make sure to use whatever filesystem type you created the image with.
(4) Copy the data, preserving information
sudo rsync -avH --numeric-ids --progress --stats --delete --exclude /proc/ \ --exclude /sys/ --exclude /tmp/ --exclude /var/run/ --exclude /var/tmp/ \ --exclude /mnt/snapshot/ / /mnt/snapshot/
This is an example of copying the entire system (if it’s small enough to fit). In this example, you want to make sure you exclude the mount point for the snapshot, because otherwise you’ll have a recursive rsync that will go on forever. It’s definitely good to make sure you exclude /proc/ and /sys/ too. You could exclude /dev/ since today’s Linux just regenerates it on boot anyway. (If you were porting to other hardware you may want to do this to be “safe” but usually it’s safer to just keep a copy of it.) –progress and –stats are extraneous options, and if you’re a neat freak, you can use –delete-excluded too to make sure those directories are cleared out in case you accidentally copied things over.
(5) Unmount and burn using cdrecord
sudo umount /mnt/snapshot sudo cdrecord -v -eject dev=/dev/cdrom snapshot.img
You can alternatively use any burning software to apply the image directly to burnable media.
Now keep in mind, that when you want to mount this CD/DVD you will need to mount it by hand, as root, using the filesystem type you burned it with. It’s a good idea to write the fs type on the CD along with whatever else you’re going to call it so you know how to mount it later.
Filed under: Computer
« Making a Bootable Linux CD | Home












September 25th, 2006 at 11:59 pm
rsync –verbose –progress –stats –compress -a –delete -H –numeric-ids –exclude “#*#” –exclude “*~” –exclude “/proc/*” –exclude “/dev/*” –exclude “/var/cache/*” –exclude “/tmp/*” –exclude “/var/tmp/*” descartes:/ /mnt/backup/rsync/descartes/