陈敏之 莫文蔚腿长:如何把home目录迁移到独立分区

来源:百度文库 编辑:中财网 时间:2024/05/06 01:25:21

Having the “/home” directory tree on it’s own partition has several advantages, the biggest perhaps being that you can reinstall the OS (or even a different distro of Linux) without losing all your data. You can do this by keeping the /home partition unchanged and reinstalling the OS which goes in the “/” (root) directory, which can be on a seperate partition.

  有“ /home”目录树在它自己的分区具有几个方面的优势,最大的可能是,您可以重新安装操作系统(甚至是一个不同的发行版的Linux )而不丧失您的所有数据。为此,您可以保持/home分区不变,重新安装操作系统而不用在“ / ” (根)目录,它可以在一个单独的分区。

  But you, like me, did not know this when you first installed Ubuntu, and have not created a new partition for “/home” when you first installed Ubuntu. Despair not, it is really simple to move “/home” to its own partition.

  但是,你像我一样,不知道这当您第一次安装Ubuntu的,并没有建立一个新分区为“ /home”当你第一次安装Ubuntu Linux系统。没有绝望,这是很简单移动“ /home” ,以它自己的分区。

  First, create a partition of sufficient size for your “/home” directory. You may have to use that new hard drive, or adjust/resize the existing partition on your current hard-drive to do this. Let me skip those details.

  首先,创建一个分区有足够大的尺寸为您的“ /home”目录。您可能必须使用新的硬盘驱动器,或调整/调整现有分区您目前的硬盘做到这一点。让我跳过这些细节。

  Next, mount the new partition:

  下一步,安装新的分区:

  $mkdir /mnt/newhome

  $sudo mount -t ext3 /dev/hda5 /mnt/newhome

  (You have to change the “hda5″ in the above to the correct partition label for the new partition. Also, the above assumes that the new partition you created is formatted as an ext3 partition. Change the “ext3″ to whatever filesystem the drive is formatted to.)

  (你必须改变“ hda5 ”在上述正确的分区标签为新的分区。此外,上述假设你创建新的分区格式化为ext3分区。改变“ ext3 ”的任何文件的驱动器是格式。 )

  Now, Copy files over: Since the “/home” directory will have hardlinks, softlinks, files and nested directories, a regular copy (cp) may not do the job completely. Therefore, we use something we learn from the Debian archiving guide:

  现在,复制文件:自从“ /home”目录将hardlinks , softlinks ,档案和嵌套目录,定期副本(处长)可能无法完成的工作完全。因此,我们利用我们学习从Debian存档指南:

  $cd /home/

  $find . -depth -print0 | cpio –null –sparse -pvd /mnt/newhome/

  Make sure everything copied over correctly. You might have to do some tweaking and honing to make sure you get it all right, just in case.

  确保所有复制正确。您可能需要做一些调整和磨练,以确保您获得的所有权利,以防万一。

  Next, unmount the new partition:

  下一步,卸载新的分区:

  $sudo umount /mnt/newhome

  Make way for the new “home”

  让路给新的“家”

  $sudo mv /home /old_home

  Since we moved /home to /old_home, there is no longer a /home directory. So first we should recreate a new /home by:

  自从我们搬到/家/ old_home ,不再有/ home目录。所以首先我们应该重新建立一个新的/home的:

  sudo mkdir /home

  Mount the new home:

  挂载新的home

  $sudo mount /dev/hda5 /home

  (Again, you have to change “hda5″ to whatever the new partition’s label is.)

  (同样,你必须要改变新的分区“ hda5 ”的标签。 )

  Cursorily verify that everything works right.

  Cursorily确认一切运行正确。

  Now, you have to tell Ubuntu to mount your new home when you boot. Add a line to the “/etc/fstab” file that looks like the following:

  现在,你必须告诉Ubuntu挂载您的新home里,当您启动。添加一行“/ etc / fstab”看起来如下:

  /dev/hda5 /home ext3 nodev,nosuid 0 2

  (Here, change the partition label “hda5″ to the label of the new partition, and you may have to change “ext3″ to whatever filesystem you chose for your new “home”)

  (在这里,更改分区“ hda5 ”的标签从新的分区,您可能需要更改“ ext3 ”文件系统您选择的新“home” )

  Once all this is done, and everything works fine, you can delete the “/old_home” directory by using:

  一旦所有做到这一点,一切工作正常,您可以删除“ / old_home ”目录:

  $sudo rm -r /old_home

  Michael, Russ and Magnus posted this solution on the ubuntu-users mailing list a few months ago.

  UBUNTU分区调整、/home目录迁移成功

  UBUNTU当然是装在ext3分区里。因为安装系统时太菜。所以只分了一个ext3的区。所以许多重要的目录都放在了这个区上面。

  先看个图。这是我的硬盘。UBUNTU当然是装在ext3分区里。因为安装系统时太菜。所以只分了一个ext3的区。所以许多重要的目录都放在了这个区上面。后来才知道这样做不好。比如非常重要的保存个人设置的/home目录没有办法独立出来。于是想到了调整分区的方法。调整前是这样的:swap活动分区2G(后来才知道那对我1G的内存实在有点浪费),ext3分区为8.6G。

  

 

  这张图已经是调整后的图了。我来说一下调整的过程。用live CD启动电脑,让硬盘里的系统不被占用。先把swap分区删掉。释放出2G的空闲空间,再新建一个swap,大小与我的内存相当就可以了。但把这一个G的空间挂载为/home又有点捉襟见肘。反正给ubuntu的可用空间只有10个G多一点。而其它的分区都是NTFS的,装着XP系统。现在的ubuntu已经可以很好的支持NTFS分区格式。所以,现有的NTFS分区不必做任何的调整。10G的UBUNTU分区如果不够用,就可以把文档放到NTFS分区上。但同为ext3格式的/home则应该尽量大一点。想到/目录不用8.6个G那么大,只是装个系统而已,而且该装的软件也装得差不多了。只有/home目录在不断扩大。所以应该把/目录的容量调整一点到/home目录。现在我的/home目录经过整理后为350M.至少要从/目录调整一个G到/home目录。也是用liveCD启动进行操作。因为此时,硬盘的所有分区都处于释放状态,很方便做调整。在LIVE系统下启动分区管理器,可以很方便在调整分区的大小。先把/目录调整为7个G.这样就释放出1.6G的空闲空间。再把这部分空间加到/home目录上。

  实际操作用了30分钟左右全部完成。ubuntu的分区管理工具工作非常警慎。每进行一项重要调整后就要进行整个分区的完全检测一次。虽然用掉不少时间,但这是对自己和用户都负责的态度。

  最后,就是把图中sda9上的/home目录迁移到sda10分区上,并实现自动挂载。也是通过liveCD系统来完成的。不过注意一点,必须要有root权限。这个简单,虽然live系统的ROOT是随机的密码,到用户管理里改一下就可以了。有了ROOT,就可以很方便地把/home目录移动到sda10上。然后再改一下sda9分区里的/etc/fstab文件,把sda10自动挂载为/home。当然。别忘了sda9下也要有/home目录。目录为空就可以了。这样系统启动后自动就把sda10挂载到系统的/home目录下了。于是实现了/home目录存在于单独分区之上。