当前位置: 首页>>技术问答>>正文


如何将整个Ubuntu系统移动(复制)到另一个硬盘?

, , ,

问题描述

我安装了Ubuntu的硬盘即将发生故障。我宁愿不失去3年的数据,定制和应用程序。我正在寻找一种方法来移动整个系统(包括SWAP,因为我不确定我是否可以将系统重新连接到新的SWAP分区)到另一个HDD。但不是完整的硬盘驱动器<只有包含Ubuntu的分区,到另一个硬盘上的分区。基本上我想做我能用Norton Ghost做我的Windows安装。我想过使用Clonezilla,但我想我会遇到GRUB问题(特别是尝试从不同于conf文件的UUID启动)。你知道怎么办?

PS,我的主目录是加密的,但这不是一个问题,因为我可以解决这个问题。

编辑:改变了解释,使其更清晰

最佳解决思路

我实际上最终使用Live CD中的Gparted。我复制了分区并将其粘贴到另一个硬盘上的未分配空间中。然后我使用blkid检查UUID并编辑了fstab文件。像魅力一样工作!

次佳解决思路

好吧,我刚用过usb stick + ubuntu live。

我将ubuntu 13.10从较大的hdd转移到较小的ssd,而clonezilla “said”由于目标分区小于源分区而无法以这种方式完成。

所以我开始ubuntu直播,安装了两个hdd(新磁盘,当然早先分区,不要忘记交换;)),只是:

cd /media/ubuntu/old-hdd-uuid/

然后:

sudo cp -R --preserve=all bin/ boot/ cdrom/ dev/ etc/ home/ lib/ lib32/ lib64/ media/ mnt/ opt/ proc/ root/ run/ sbin/ srv/ sys/ tmp/ usr/ var/ /media/ubuntu/new-hdd-uuid/

上面你可以看到它只是将所有目录从一个硬盘复制到另一个硬盘,递归地保留所有权限和内容。

cd /media/ubuntu/new-hdd-uuid/

然后我不得不在新磁盘的根目录中创建两个符号链接:

sudo ln -s boot/vmlinuz-x.xx.x-xx-generic vmlinuz
sudo ln -s boot/initrd.img-x.xx.x-xx-generic initrd.img

下一步是安装grub,所以:

sudo grub-install --boot-directory=boot/ /dev/sdxy

其中x – 设备,y – 分区号(如果不确定使用cfdisk或fdisk打印分区表…)

最后一步是,将旧硬盘的uuid从旧硬盘更改为uuid(这是欺骗grub配置,fstab或其他没有搜索和修复配置的最简单方法)

sudo tune2fs /dev/sdxy -U OLD-UUID

设备重新安装后将显示新的UUID。所以现在重新启动,如果一切正常,你的ubuntu应该开始……

第三种解决思路

你可以使用dd来做到这一点。有关完整信息,请查看该站点。

Clone a Hard Drive Using an Ubuntu Live CD

Warning dd is a very powerful low-level tool and even one little typo is sufficient to wipe out an entire disk. Please be very careful with its use and try to use a higher-level tool if at all possible.
Note also that this method only works if your target disk is the same size or larger


Cloning hard drives is a common maintenance task. Don’t bother burning a new boot CD or paying for new software – you can do it easily with your Ubuntu Live CD.

Not only can you do this with your Ubuntu Live CD, you can do it right out of the box – no additional software needed! The program we’ll use is called dd, and it’s included with pretty much all Linux distributions. dd is a utility used to do low-level copying – rather than working with files, it works directly on the raw data on a storage device.

您还可以使用:

Clonezilla, a free hard drive cloning software. Clonezilla runs from a live CD, and features a simple user interface. You’ll still need to be aware of what you’re doing, of course, but this tool can simplify your job immensely with its step-by-step breakdown.

You can download Clonezilla here

警告确保在开始之前查看Clonzilla的限制。

您还提到您已经使用Ghost for windows,您也可以使用Ghost for Linux

资料来源:http://www.howtogeek.com/howto/19141/clone-a-hard-drive-using-an-ubuntu-live-cd/

资料来源:http://www.makeuseof.com/tag/2-methods-to-clone-your-linux-hard-drive/

第四种思路

几年前我成功使用了这个工具到”clone”我的分区:G4L。一切都适用于一些post-installation更正,例如调整分区大小(我克隆了不同大小的HD分区)和grub重新安装(这很简单,你只需要一张活CD就可以在MBR中重新安装)。

您可以安全地忽略您的交换分区(您将能够在第二次重新调用它)或克隆它并稍后激活它,手动编辑/etc/fstab或从命令行。

在过去的几周里,我再次使用clonezilla进行克隆,并且所有内容都进行了相同的post-cloning校正。所以不要担心并试一试,原始高清上的任何内容都不会被触及!

编辑:

我找到了一封旧邮件,我描述了第一个克隆过程。我的行动如下:

  • 将我的新高清分区​​通过USB连接,就像旧的高清一样

  • 使用G4L以原始模式克隆分区

  • 使用Live CD启动并使用resize2fs调整分区大小

  • 断开HD与USB的连接并安装在SATA /PATA上。

  • 使用Live CD再次启动并安装新磁盘:

    mkdir disk
    mount /dev/sda1 disk        (where sda1 contains boot and root partitions)
    mount /dev/sda2 disk/boot   (if you have a different boot partition) 
    mount --bind /dev/ disk/dev/
    mount -t proc none disk/proc
    chroot disk /bin/bash
    grub-install /dev/sda       (to install GRUB on sda MBR)
    
  • 重启,检查交换

  • 请享用

第五种思路

@boywithaxe – 关于您对Mitch’s answer的意见,您确实可以通过dd if=/dev/sdb3 of=/dev/sda3复制相关分区。这实际上是最容易的部分。最棘手的部分是您还必须安装新复制的分区,以及其他几个分区并安装grub(grub-install /dev/sda)(并在重新启动之前添加交换分区(如果您正在克隆可引导分区)) 。使用这种方法也不需要resize2fs

我自己必须这样做,我使用了Boot repair after a Windows Upgrade on Ubuntu 14.04 (non-RAID)jasmines answer的组合。

所以,从liveCD启动后:

dd if=/dev/sdb3 of=/dev/sda3

完成后,那么

sudo mount /dev/sda3 /mnt 

其中sda3包含最近复制的引导和根分区)

sudo mount --bind /dev/ /mnt/dev/

sudo mount -t /proc none /mnt/proc

sudo chroot /mnt

sudo grub-install /dev/sda 

注意这是sda而不是sda3

update-grub

exit

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/1339.html,未经允许,请勿转载。