最新消息:

新电脑+旧系统:教你在不同机器间转移Linux

linux admin 2313浏览 0评论

科技发展得如此之快,如果你发现自己频繁地更换电脑或电脑配件,大可不必觉得奇怪。比如你可能想买个全新的笔记本,或者换掉你那不能再烂的硬盘。这些情况下,如果你能非常轻松地把你的操作系统移植到新电脑或新硬盘上面去,一切就太完美了。

但是如果你用的是Windows这将会是一个不小的挑战,尤其是要重新激活系统的时候。而Linux的话就会相对无压力很多了。事实上有很多种方法来移植Linux,但我现在只打算推荐我认为最简单的一种。

全新安装

最常见的“移植”方法就是在你的新电脑上重新安装Linux然后把你的文件都复制过去。虽然这是最普遍的做法,但仅在你无法在一个电脑上连接两块硬 盘的情况下我才推荐你这么做,无论你打算把系统移到新电脑还是新硬盘。当备份你的个人文件时,你应该着重看一下 /home ,/etc ,/opt,/root,/var 这几个文件夹。桌面用户应该主要看看/home 目录因为那里有他所有的个人文件。而服务器用户应该重点检查下/etc和/var,因为那有配置文件和托管数据等。

记录安装包

ubuntu_packages_list
基于debian的发行版都可以很轻易地列出系统上已安装的包的列表并把它们写入文件中。这个列表可以用于新系统以便重新安装它们。你只需要在终端里输入

sudo dpkg –get-selections > /home/[your user name]/packagelist.txt

(这里要把 [your user name] 改成你的用户名),就可以创建这个列表文件了。然后把这个文件复制到新系统中,再在终端里输入

sudo dpkg –set-selections < /home/[your user name]/packagelist.txt

这样就标记了所有之前系统已安装的包,但直到你运行

sudo apt-get -u dselect-upgrade

这些包才会被安装上去。它会从官方源里面安装这些包,一会儿功夫你熟悉的软件就都回来了。别忘了把你之前备份的文件恢复到相应文件夹里面,然后你的Linux“移植”计划就宣告成功了!

复制分区

ubuntu_gparted_copy_partition
如果你能够把两个硬盘连接到同一台机器上,就可以很轻松地把整个Linux分区复制到新硬盘过去。这个方法使得移植完成后系统更能保持它原有的样子,因为 你不必重新安装系统和所需要的包。除了要有两块通过某种方式成功连接到同一机器的硬盘,你还要有一个刻录了任一Linux发行版的DVD或者USB。
比如,一个刻录了Ubuntu ISO文件的DVD/USB 就相当不错。然后进入这个live环境,打开Gparted ,只要选中你要复制的分区,复制后粘贴到新的硬盘上就可以了。当复制到一个较大的硬盘时你可以在移植后再调整大小,但如果新硬盘容量较小,你必须在移动之 前先重新调整它的大小。一旦复制粘贴完成,接下来就需要按顺序输入一些命令来安装启动引导程序到新的硬盘上。在终端里输入:

sudo mount /dev/sdX# /mnt

sudo mount –bind /dev /mnt/dev

sudo mount –bind /proc /mnt/proc

sudo cp /etc/resolv.conf /mnt/etc/resolv.conf

sudo chroot /mntgrub-install /dev/sdX

你得把上面的 x 替换成新硬盘的驱动号,把 # 替换成新硬盘上新系统的分区号。这些信息都可以在Dash板的一些磁盘管理应用中找到。现在就把新硬盘安装回原来的机器,再启动你的Linux。进入你的系统后你需要运行

sudo update-grub

来保证GRUB 正确地识别各个硬盘上的各个系统。如果你的硬盘上有另外一个操作系统比如Windows,这一步尤为重要。

总结

希望这两个方法能让你很快很轻易很高效地移植Linux到新硬盘或新电脑上。如果你按照上面说的做了,应该是不会有什么问题的。出现了问题或者需要帮助的可以在这篇文章下面评论,我会尽我所能帮助你们。

你自己有移植过Linux吗?你觉得上面这些方法难不难?在评论里留言让我们知道吧!

 

原文链接: Danny Stieben 翻译: 极客范 钟益强

译文链接: http://www.geekfan.net/1860/

New Computer, Old OS: How To Migrate Linux Between Machines

linux move between desktopsTechnology is progressing forward at a pretty fast rate, so much so that it isn’t uncommon for you to find yourself buying a new computer or computer part. For example, you may want to buy a brand new laptop or replace a dying hard drive that your system is currently using. In cases like these, it would be great if you can simply move your operating system over to the new hard drive or system with as little fuss as possible.

While this may be a challenge if you’re using Windows, especially when it comes to the necessity of reactivating your copy, this is done a lot more easily if you’re running Linux. In fact, you even have a choice of a number of different ways, but I’m only going to recommend the ones that I find to be the easiest.

Fresh Install

The most common way for you to move your Linux installation over to a new hard drive is to simply reinstall Linux on the new system and copy over all of your files. Although this is the most common way of moving your system and files, I’d actually only recommend this if you cannot connect the two hard drives together to the same machine, no matter if you’re moving to a new hard drive or a new system. While backing up your files, you should look in the /home, /etc, /opt, /root, and /var folders for anything that you may want to keep. Desktop users may want to primarily look in the /home folder as that is where all your personal files are located, while server users should primarily check through /etc and /var for configuration files and hosted data.

Keep A List Of Installed Packages

linux move between desktops
Debian-based distributions have an easy way to list all installed packages on your system and write that list into a simple text file. This list can then be used on your new Linux installation to mark all packages that need to be installed again. To create the list, you’ll need to run the command sudo dpkg --get-selections > /home/[your user name]/packagelist.txt, while replacing [your user name] with the appropriate entry. To mark packages for reinstallation on the new system, copy the text file over to that system and run the command sudo dpkg --set-selections < /home/[your user name]/packagelist.txt.

This will mark all packages that you want back, but it won’t actually install them until you run the command sudo apt-get -u dselect-upgrade. This should install all packages from the official repos which you had on your old system, so a lot of familiar Linux software should reappear after some time to download and install. Don’t forget to also restore your backed up data to the appropriate folders, and ta-da! Your system should now be back to the way it was!

Copying Your Partitions

linux move between desktops
If you are able to connect the old and new hard drives (or the hard drive of the old system and the hard drive of the new system) to the same machine, you can easily copy the entire Linux partition(s) over to the new hard drive. This method will make it a lot easier to keep your Linux environment the way it is because you won’t have to freshly install the distribution and all needed packages. Besides having the two hard drives connected to the same machine in some fashion in which the computer recognizes them both, you’ll also need to have a DVD or USB drive which has the distribution live environment on it.

As an example, a burned or written copy of the Ubuntu ISO will do just fine — just remember to keep it the same as what you already have installed, including whether it’s 32-bit or 64-bit. Once you have the live environment from the DVD/USB running, you can open Gparted and simply copy the partition(s) you want to keep over to the new hard drive by “copying and pasting” it in the interface. When copying over to a larger drive, resizing after the move is possible, while when copying to a smaller drive, you must resize the partition before moving it. Once the partition(s) are copied over to the new hard drive to the point of satisfaction, you will need to run a few commands in order to install the correct bootloader onto the new hard drive. To get the GRUB bootloader in working order on the new hard drive, run:

sudo mount /dev/sdX# /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
sudo chroot /mnt
grub-install /dev/sdX

You’ll need to replace all instances of “X” in those commands for the new hard drive, and replace all instances of “#” for the partition number of the root Linux partition. All of this information can found via the Disks application as found from the Dash. Now go ahead and move the new hard drive into the correct machine and boot from it to load your distribution. Once inside your running Linux instance, you’ll need to run sudo update-grub to make sure that the GRUB bootloader correctly identifies the partitions on your system, across all hard drives. This is an especially important step if you have another partition or hard drive with another operating system on it such as Windows.

Conclusion

Hopefully with these two methods, you can quickly, easily, and efficiently move over your Linux installation to a new hard drive or system. Provided you follow the instructions correctly, it should work without fail. Those with questions or those needing help can comment on this article and I’ll try to assist them as best as I can.

Have you moved a Linux installation before? Do you find these instructions to be easy? Have you checked out our ultimate guide to Linux yet? Let us know in the comments!

转载请注明:jinglingshu的博客 » 新电脑+旧系统:教你在不同机器间转移Linux

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址