當前位置: 首頁>>技術問答>>正文


如何將整個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/zh-tw/article/1339.html,未經允許,請勿轉載。