Migrate ubuntu to another disk

  1. connect new disk {diskB}
  2. use `fdisk -l` to find current disks info
  3. format {diskB} with `GPT` partition format.
  4. partition {diskB} to have exact partitions as old disk: 
    • / (the root) fileSystem: ex4
    • /boot (for booting files including `grub`) fileSystem: ex2, flags: boot, esp
    • fileSystem: unformatted, mount point: none, flags: bios_grub
  5. mount /boot of {diskB} to point /mnt and install grub
    • > $ sudo grub-install –target=i386-pc –root-directory=/mnt –recheck –debug /dev/sdb
    • mv /mnt/boot/* /mnt/
  6. use `mount {source path} {dest. path, like /mnt}` to mount new partitions and copy all files from the corresponding folders from old disk: cp -rf -a {source path} {dest. path}
    • /bin 系统可执行文件
    • /etc 系统核心配置文件
    • /opt 用户程序文件
    • /root root用户主目录
    • /sbin 系统可执行文件
    • /usr 程序安装目录
    • /var 系统运行目录
    • /boot
  7. create essential empty directories in {diskB}
    • /dev 主要存放与设备(包括外设)有关的文件
    • /proc 正在运行的内核信息映射
    • /sys 硬件设备的驱动程序信息
  8. modify etc/fstab file to mount new /, /boot/ in {diskB} and old disk
    • use `blkid` to check current partitions uuid
    • change fstab:
      • UUID={diskB’s `/` partition uuid}             /           ext4    errors=remount-ro     0       1
      • UUID={diskB’s `/boot` partition uuid}     /boot    ext4    defaults                      0       2
  9. update-grub (if still not work, try to grub-install /dev/{diskB}
  10. reboot!

grub rescue mode if grub directory is not found at booting:

use `ls (hd0,1~9)/{any files like ./grub ./lost+found}` to check what your boot index is.

grub rescue>root=(hd0,{diskB’s boot partition index, `2` for example.})

grub rescue>prefix=/boot/grub

grub rescue>set root=(hd0,2)

grub rescue>set prefix=(hd0,2)/boot/grub

grub rescue>insmod normal

grub rescue>normal // auto enter `normal` mode

// normal mode /////////

grub>linux /vmlinuz-xxx-xxx root=/dev/{diskB} ro

grub>initrd /initrd.img-xxx-xxx

grub>boot