Backup Linux OS

基本思路:先拷贝整个操作系统到目标硬盘,修改挂载的分区,在目标硬盘上安装引导。

Copying

  • Mount the destination partitions

    1
    sudo mount /dev/sdbX /mnt # mount sdbX for example
  • Copy the entire os to the destination partitions

    1
    rsync -avxHAX / /mnt

Configuration

  • Find the destination partition’s UUID

    1
    ls -l /dev/disk/by-uuid/
  • Change uuid in the file /mnt/etc/fstab

Install Grub

  • Bind some system directories needed by grub

    1
    2
    3
    4
    mount --bind /proc /mnt/proc
    mount --bind /sys /mnt/sys
    mount --bind /dev /mnt/dev
    mount --bind /run /mnt/run
  • Install grub on destination hard drive

    1
    2
    3
    chroot /mnt
    grub-install /dev/sdb
    update-grub2