I would like to create a copy of my running Linux installation onto a USB 16 GB pen drive. The current system is a basic ATX PC used as a headless server on a remote location. I would like to have a backup option in case of a hard drive failure. Basically someone would shutdown the computer, plug in the USB containing the exact copy of the system and the system would boot and run off the USB drive for as long as needed, that is until I can get to the location with the new proper HDD replacement.
The current HDD is 120 GB. Used space is around 5 GB. So the questions are:
1. How to create a exact(bootable) copy of that, onto a smaller 16 GB usb drive?
2. How to copy everything back onto a bigger drive(i.e. 250 GB or 500 GB) when I do a new HDD install? Preferably expanding the file system back to the whole disk size, because the rest of the free space is used occasionally as time-lapse photography storage.
Here are some more details about the current disk configuration:
fdisk -l
Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xac46573c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 14594 116707328 8e Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 1979 MB, 1979711488 bytes
255 heads, 63 sectors/track, 240 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_home: 63.8 GB, 63837306880 bytes
255 heads, 63 sectors/track, 7761 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
df -BG
Filesystem 1G-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 3G 45G 5% /
tmpfs 1G 0G 1G 0% /dev/shm
/dev/sda1 1G 1G 1G 20% /boot
/dev/mapper/VolGroup-lv_home
59G 1G 55G 2% /home
Generic tool for low level work against hard drives
DISCLAIMER Playing with low-level tool may harm your system! Don't ask me for anything about potential damages you've made!
For this kind of jobs, I use a personal version of Debian-Live, built with all needed disk tools
Backing-up
There is few steps to backing your machine up:
parted
,sfdisk
,gparted
or othercfdisk
... Followed bymdadm
and/orlvm2
tools.Copying datas Copying datas could be done by following command:
tar -cpC /sourcePath . | tar -xpC /destPath
. For backing-up mounted partitions with sub-mount active, I use the following workaround (sample backing-up root directory/
):Make system bootable. This is more subtle: Assuming you've booted on Debian-Live you have to build your target structure,
chroot
into them, than rungrub-install
:Than (In the hope all work fine) I reboot.
Alternative multi-os using
partclone
There is an overall solution for backing whole partitions, but as you store byte-by-byte each partitions, you need a destination bigger or with same size as your source: (This could be stored on small USB key anyway).
The basis is quite same, built your own Debian live with all needed tools, but
partclone
.Than to store a whole multi-boot disk sharing WinXP and Linux on same disk (sample):
and so on...
to restore, you only have to invers the process:
Than... reboot... !