I can see from /var/log/messages error messages and weird crashes that the disk in my laptop is on the way out. I plan to replace it but to do this I’d rather not have to install everything again.
My laptop has these partitions:
Windows Recovery (10GB)
Windows 7 (NTFS 96.6GB)
Linux /boot (ext4 100MB)
Linux LVM (encrypted, 143GB)
I need software that will allow me to create an image (or images) of all these partitions, save the image(s) to a USB hard drive and restore from those images once I’ve put the new, blank, hard drive into the laptop.
Does anyone know of software (either open source or commercial pay-ware) or a technique to do this? I’d prefer not to just dd everything as it will be very slow.
You dint need to mount LV partition do be able to create image of it. It only needs to be available to system (needs to be visible in **lvdisplay **command)
Here are some example instruction I am using for disk imaging than might help you:
1. Createing LVM snapshot backup of a partition
a. First create temporary LVM snapshot of a filesystem (you need to have some free space in volume group to be able to create snapshot). Snapshot will use assigned space to write changes made on original fileseystem while snapshot being used - existed. If snapshot space gets full it will be automaticaly dropped (see LVM dosumentation for more details). In this example we use 100M snapshot space for writing diferences on original filesystem during backup).
lvcreate -L100M -s -n backup-home /dev/VGLINUX/LVHOME
b. Next check what is the logical volume map of LVM source filesystem
lvdisplay
c. Next create compressed copy of a LVM filesystem to a file
dd if=/dev/VGLINUX/backup-home | gzip -c -9 | dd of=/some_path/home_bak_snapshot.img
d. Last remove filesystem snapshot
lvremove /dev/VGLINUX/backup-home
Recomendation: store backup file to safe location on safe media.
2. Restoring a LVM partition image
a. First check that destination filesystem exists on machine and its size is equal or greater than filesystem size in backup image
df -h /home
b. Next check what is the logical volume map of LVM destination filesystem
lvdisplay
c. Next unmount the destination filesystem (eg. under mountpoint /home)
umount /home
d. Next create filesystem restore
dd if=/some_path/home_bak_snapshot.img | gzip -d | dd of=/dev/VGLINUX/LVHOME
e. Next resize - expand restored filesystem to ful size defined in LVM definition
resize2fs -p /dev/VGLINUX/LVHOME
f. Last mount restored filesystem
mount -a
Recomendation: If you are restoreing root filesystem you must boot machine using RESCUE or LIVE CD (which supports LVM, dd backup, and gzip compression).
Boot from a live CD.
Manually “decrypt” with the “cryptsetup” command.
Manually mount the LVM volumes (except the swap volume). I mount those read only.
Use “tar zcf” to make a tar backup to an external USB drive.
For the actual commands that I use, see this blog post and scan down to the heading “Encrypting everything”.