移动/home目录至独立分区
2013-09-16 09:59
288 查看
原文: http://dpinglee.blog.163.com/blog/static/14409775320108185223169/
You can move any directory with this tips, and I just use this tip move my home directory to a independent
disk.
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.
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.
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.
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.)
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:
$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:
sudo mkdir /home
Mount the new home:
$sudo mount /dev/hda5 /home
(Again, you have to change “hda5″ to whatever the new partition’s label is.)
Cursorily verify that everything works right.
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:
/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”)
Once all this is done, and everything works fine, you can delete the “/old_home” directory by using:
$sudo rm -r /old_home
Michael, Russ and Magnus posted this solution on the ubuntu-users mailing list a few months ago.
总结一下:
1)新建一个有足够空间的分区给你要搬移的目录,比如/home
2) 新建一个目录,$mkdir /mnt/newhome
3)把新建的分区挂载到新建的目录下,$sudo mount -t ext3 /dev/hda5 /mnt/newhome
(这里假设了,新建的分区是ext3类型的,并且是在/dev/hda5)
4)把整个/home都拷贝过去,
$cd /home/
$find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/
5)卸载 $sudo umount /mnt/newhome
6)把原来的/home 改名,$sudo mv /home /old_home
7)新建一个/home,sudo mkdir /home
8) 把分区挂载过来,$sudo mount /dev/hda5 /home
9)在 “/etc/fstab” file里加上/dev/hda5 /home ext3 nodev,nosuid 0 2,让系统启动的时候就自动挂载。
10)把就的home删除,$sudo rm -r /old_home
(不必着急删除旧的home,试试没有问题之后在删除,以防出现问题)chj注释
==========================实践==========================
好吧, 在安装fedora17的时候 分区没有规划好,所以导致现在,更目录空间越来越小,进而导致一些奇怪的问题。
所以,决定重新分出一个分区,然后 将/home目录迁移过去。
首先: 在win7下,用acron disk 将F盘分出了20G。 结果,重启遇到error : unknown filesystem的问题。解决看这里
接下来将这个20G的分区格式化。$mkfs.ext4 /dev/sda6 (别写错了 sda后面的数字要确定好。)
然后按照上面文章步骤做就可以了。
总结:
通过迁移/home目录,学到了很多知识:
但是还是有疑问:
怎么在linux下给分区调整大小? parted命令能调整ntfs分区大小吗?
如果能在linux下直接调整分区大小,记得调整分区后更新grub。即$ grub2-mkconfig
这样就能在分区发生变化之后,保证正常启动了。
You can move any directory with this tips, and I just use this tip move my home directory to a independent
disk.
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.
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.
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.
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.)
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:
$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:
sudo mkdir /home
Mount the new home:
$sudo mount /dev/hda5 /home
(Again, you have to change “hda5″ to whatever the new partition’s label is.)
Cursorily verify that everything works right.
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:
/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”)
Once all this is done, and everything works fine, you can delete the “/old_home” directory by using:
$sudo rm -r /old_home
Michael, Russ and Magnus posted this solution on the ubuntu-users mailing list a few months ago.
总结一下:
1)新建一个有足够空间的分区给你要搬移的目录,比如/home
2) 新建一个目录,$mkdir /mnt/newhome
3)把新建的分区挂载到新建的目录下,$sudo mount -t ext3 /dev/hda5 /mnt/newhome
(这里假设了,新建的分区是ext3类型的,并且是在/dev/hda5)
4)把整个/home都拷贝过去,
$cd /home/
$find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/
5)卸载 $sudo umount /mnt/newhome
6)把原来的/home 改名,$sudo mv /home /old_home
7)新建一个/home,sudo mkdir /home
8) 把分区挂载过来,$sudo mount /dev/hda5 /home
9)在 “/etc/fstab” file里加上/dev/hda5 /home ext3 nodev,nosuid 0 2,让系统启动的时候就自动挂载。
10)把就的home删除,$sudo rm -r /old_home
(不必着急删除旧的home,试试没有问题之后在删除,以防出现问题)chj注释
==========================实践==========================
好吧, 在安装fedora17的时候 分区没有规划好,所以导致现在,更目录空间越来越小,进而导致一些奇怪的问题。
所以,决定重新分出一个分区,然后 将/home目录迁移过去。
首先: 在win7下,用acron disk 将F盘分出了20G。 结果,重启遇到error : unknown filesystem的问题。解决看这里
接下来将这个20G的分区格式化。$mkfs.ext4 /dev/sda6 (别写错了 sda后面的数字要确定好。)
然后按照上面文章步骤做就可以了。
总结:
通过迁移/home目录,学到了很多知识:
parted命令。 grub2 mkfs.ext4 df
但是还是有疑问:
怎么在linux下给分区调整大小? parted命令能调整ntfs分区大小吗?
如果能在linux下直接调整分区大小,记得调整分区后更新grub。即$ grub2-mkconfig
这样就能在分区发生变化之后,保证正常启动了。
相关文章推荐
- ubuntu将home目录迁移到独立分区(转)
- ubuntu将home目录迁移到独立分区
- linux 不改变目录结构移动 home 目录到新分区的操作方法
- 迁移Home目录到独立分区
- 迁移home目录到独立分区
- Ubuntu 16.04 /home 目录迁移到独立分区的方法
- Ubuntu 16.04 /home 目录迁移到独立分区的方法
- ubuntu在不重装系统情况下关于调整分区,或是从现有根目录划分/home等分区
- linux 不改变目录结构移动 home 目录到新分区
- home目录迁移至新分区
- windows7中把整个用户目录移动到其它分区中的方法
- Linux卸载home独立分区
- 【Ubuntu】将新的分区挂载到home目录
- linux下,如何迁移mysql数据库存放目录。利用软连接简单快捷实现移动到home数据盘下
- 文件迁移:将/home迁移到一个独立分区中
- 想对/home目录进行设置磁盘配额,但是/home不是独立的文件系统,怎么办?
- 把eclipse 3.4的插件移动到独立目录中
- 如何将现有的/home目迁移新的单独分区上,或者其它目录迁移到别的分区
- Linux环境下迁移/home家目录到其他分区
- 移动/home 分区到其它分区