bigyellowdoc / 计算机使用 / Create a separate /home partition in Ub...

0 0

   

Create a separate /home partition in Ubuntu

2012-08-17  bigyellow...




Return to the Psychocats Ubuntu page

Create a separate /home partition in Ubuntu

This guide is for creating a separate /home partition if you already installed Ubuntu without a /home partition (i.e., /home is just a folder inside your / partition). If you have not yet installed Ubuntu but want to create a /home partition before installing (a very good idea, by the way), use this guide. If you want to know more about partition planning, read this.

There is also a text-only (command-line-driven) guide for this process here. I would recommend it to intermediate-to-advanced users. It's simple, and it works, but it also assumes you already have a new partition created for /home.

You must use a live CD for this process for two reasons:

  1. In order to resize your existing / partition, it needs to be unmounted. The only way to unmount it is for it not to be in use, which means you can't boot to your regular Ubuntu installation while resizing it... which means you need a live CD
  2. If you screw up your installation by accident, you can use the live CD to restore your old settings and, in the worst situation, at least recover your important files

I'm using the example of a Ubuntu live CD and GParted, but you can very well use QTParted on Knoppix or DiskDrake on PCLinuxOS.

Making the new partition
Boot up a live CD and in your live session, install GParted (and ntfsprogs, just in case you're carving a partition out of an existing NTFS partition... before resizing an NTFS partition, though, make sure you defragment it in Windows). You can use Synaptic Package Manager to install it (Don't know what Synaptic is? Look here, or if you prefer the command-line, go to the terminal and type in

sudo aptitude update && sudo aptitude install gparted ntfsprogs

Then, press Alt-F2 and type

gksudo gparted

In GParted, find the partition you want to resize in order to make room for your upcoming /home partition. In this case, I'm resizing /dev/hda5, but your partition may be different. Be sure to keep track of the names of your partitions--these names are very important (/dev/hda1, /dev/hdb1, /dev/sda2, etc.).

Right-click on the partition and choose the Resize/Move option.

Choose the new size you want.

Then, in the new empty space, right-click and select New.

Choose to create the partition as Filesystem ext3.

When you're satisfied with your new partition layout, click Apply

Once the changes have been applied, make note of the partition name of your new partition and then quit GParted.

Now, in my example, my original partition that I shrunk was /dev/hda5, and it created a new partition called /dev/hda7, and my /home folder lives on /dev/hda1. It's very important that you substitute in your own appropriate partition names for the ones I'm using--you most likely will have only two partitions you're dealing with--the one you shrunk and the newly created one.

Using the new partition
Now, back in the terminal, I'm going to mount /dev/hda1 and /dev/hda7:

sudo mkdir /old
sudo mount -t ext3 /dev/hda1 /old
sudo mkdir /new
sudo mount -t ext3 /dev/hda7 /new

Now we're going to back up the /home directory on the old partition and move it to the new partition:

cd /old/home
find . -depth -print0 | sudo cpio --null --sparse -pvd /new/
sudo mv /old/home /old/home_backup
sudo mkdir /old/home

Yes, one of those lines looks really complicated--please type it as is--or, if you're unsure of your typing skills, copy and paste it into the terminal. Believe me--the command is necessary.

Next, we're going to specify to use the new home partition as /home:

sudo cp /old/etc/fstab /old/etc/fstab_backup
sudo nano /old/etc/fstab

You'll then be taken to the nano text editor. Add in this line:

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

Then save (Control-X), confirm (Y), and exit (Enter)

After you reboot, you should be now using your new /home partition.

If you find that you are running out of room on your old partition and you're pretty confident everything is working as it should be, then go ahead and delete the backup of home:

sudo rm -rf /home_backup

What if it doesn't work?
You know, it really should work, but if you somehow messed up your /etc/fstab and didn't configure it correctly... well, that's why we have a live CD, so we can fix things.

Boot up the live CD, go to a terminal, and type:

sudo mkdir /recovery
sudo mount -t ext3 /dev/hda1 /recovery
sudo cp -R /recovery/home_backup /recovery/home
sudo cp /recovery/etc/fstab_backup /recovery/etc/fstab

Then, reboot.

Page updated 05/15/2007

Return to the Psychocats Ubuntu page

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。如发现有害或侵权内容,请点击这里 或 拨打24小时举报电话:4000070609 与我们联系。

    猜你喜欢

    0条评论

    发表

    请遵守用户 评论公约

    类似文章
    喜欢该文的人也喜欢 更多