如果您正在使用Ubuntu机器,则可以将运行中的系统复制到外部硬盘。
假设您已经对外部硬盘进行了分区。在这个示例中,我将使用2个分区:/和/home。
$ sudo mkdir -p /target
$ sudo mount /media/external-hdd/main /target
$ sudo sync
$ sudo cp -ax / /target
$ sudo mount /media/external-hdd/home /target/home
$ sudo cp -ax /home /target/home
cp -ax
不会跨越不同的文件系统,它会归档(保留权限,不遵循符号链接等)。
然后,您需要更新目标磁盘上的grub设置和fstab。您可以使用chroot
,但在此之前,您需要:
$ sudo mount -o bind /sys /target/sys
$ sudo mount -o bind /proc /target/proc
$ sudo mount -o bind /dev /target/dev
现在你已经准备好进行chroot操作了。
$ sudo chroot /target
# (now you are in the external HD as root)
现在,你需要更新fstab和grub中的UUID。为了获取UUID,你可以运行以下命令:
# blkid
然后,在/etc/fstab中用blkid获得的适当id替换UUID。
最后一步是更新引导配置并将引导加载程序安装在外部硬盘上。在我的情况下,我使用grub,所以我要编辑/boot/grub/menu.lst。
您需要将以“# kopt=root=UUID=... ro”开头的行替换为UUID内容,该UUID应指向根文件系统所在的分区。
# grub-install /device/name
# update-grub
在这里,/device/name 是外部硬盘。
然后,你可以退出 chroot 并卸载设备。
# ^D
$ sudo umount /target/sys
$ sudo umount /target/proc
$ sudo umount /target/dev
$ sudo umount /target/home
$ sudo umount /target/
而且磁盘应该已经准备好可以使用了。一旦你启动它,可能会运行
fsck
,因为它没有正确卸载(你是在拷贝内容时进行的操作)。