linux home分区扩容,linux扩大home分区

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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值