Although the Linux system can be directly backed up using tar, cpio, dd, and other methods, if the system is running, the backup system cannot be completely clean. Therefore, you can use the rescue's skip mode to back up the operating system and recreate initrd. img and grub to clone Linux instances across hardware platforms. The following uses RHEL6.2 as an example for testing. This method can also be used to back up Windows systems.
Build a Linux rescue Environment
- Create a local rescue Environment
- # Cp-rp/mnt/RHEL6/images // boot // copy the images directory from the system disk to the corresponding directory.
- # Vi/etc/grub. conf // Add the following content to the grub. conf file:
- Title RHEL6_rescue
- Kernel/boot/images/pxeboot/vmlinuz rescue
- Initrd/boot/images/pxeboot/initrd. img
- Create a PXE-based rescue Environment
For more information about how to set up the PXE environment, see "DHCP + TFTP + PXE automatic network boot to install Linux OS". For more information, see: You can also start the environment by using a system disk and select to enter the rescue environment.
Backup/clone Linux
- # Mkdir/source/backup
- # Mdadm-As/dev/md0 // if the system partition is created on RAID
- # Lvm vgscan // if the system partition is created on LVM
- # Lvm vgchange-a y/dev/Lrhel6
- # Mount/dev/Lrhel6/root/source // mount all system directories according to the actual system conditions
- # Mount/dev/Lrhel6/home/source/home
- # Mount/dev/sda1/source/boot
- # Mount/dev/Lrhel6/backup
- # Tar zcvf/backup/OS. tgz/source // back up a clean System File
Restore/migrate Linux
Start the system to enter the rescue Skip Mode
- # Fdisk/dev/sdb // partition the Newly Added Disk
- # Mkdir/backup/dest
- # Mount/dev/sda2/backup
- # Mount/dev/sdb2/dest
- # Tar zxvf/backup/OS. tgz/dest
- # Vi/dest/etc/grub. conf // edit the grub configuration file as needed
- # Vi/dest/etc/fstab // edit the fstab file based on the actual situation
- # Rm-rf/dest/etc/mtab // Delete the mtab file. After logging on to the system, the mtab file is automatically created.
- # Exit
- Reboot
- Restart the system to enter the rescue Continue mode, re-produce initramfs, and install grub
- # Chroot/mnt/sysimage
- # Cd/boot
- # Mkinitrd-f initramfs-$ (uname-r). img $ (uname-r) // regenerate the initramfs File
- # Grub-install -- recheck -- no-floppy/dev/sda
- If the prompt "cocould not find device" is displayed, exit the root partition and reinstall grub, and specify the path of the root partition.
- # Exit
- # Cp/mnt/sysimage/sbin/grub/sbin
- # Grub-install -- recheck -- no-floppy -- root-directory =/mnt/sysimage/dev/sda
- # Exit
- # Exit
- Reboot