个人工具

“UbuntuHelp:Partitioning/Home/Moving”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
 
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/Partitioning/Home/Moving}}
 
{{From|https://help.ubuntu.com/community/Partitioning/Home/Moving}}
 
{{Languages|UbuntuHelp:Partitioning/Home/Moving}}
 
{{Languages|UbuntuHelp:Partitioning/Home/Moving}}
==== Why this guide is superior to the others ====
+
==== The Advantages of This Guide ====
If you don't care about this topic, just skip to the next section where the guide starts.
+
This guide was written simply because there were flaws in the other guides and it was worth recording these notes for future reference.  Community Documentation is an excellent way to help others at the same timeThis guide:
I wrote this guide simply because I found some flaws in the other guides that I read, and I wanted to record my findings for future reference.  I'm posting (and updating a bit) here for the benefit of others.  Here are the reasons I originally wrote this guide:
+
* Aims to keep the system usable and the data all safe.
* Partition and setup fstab first
+
* If the system unexpectedly loses power or goes into hibernate mode or anything at any point through this guide then it should still boot-up & work just fine. That's the main aim anyway.
* There are guides that use mount commands to do the initial partition mounting, and then setup fstab after you have moved your /home. If you mess up your fstab, then when you reboot, your system will lose track of your /home files. Setting up fstab first and using sudo mount -a to mount the partitions avoids this problem.
+
* Prepares Partitions and fstab first then only tweaks fstab at the end
 +
* People test and gain familiarity with the tools before the final crunch-test, another advantage of this guide. Some other guides use mount commands, then move the /home & then set-up fstab. However, if you mess up your fstab at that crunch-point then when you reboot your system will lose track of your /home files! Setting up fstab first and using "sudo mount -a" to mount the partitions checks the modified fstab works at a safe point in the process.  
 
* Use rsync to move the files
 
* Use rsync to move the files
* There is lot's of debate about which command to copy your files to the new /home partition.  This debate stems from a time in the past when cp was not able to do it properly (I think it skipped files?).  cp was not designed to be a powerful backup tool.  The fix, then, was to use a combo of find and cpio ([http://www.us.debian.org/doc/manuals/reference/ch-tips.en.html#s-archiving See section 8.3.5]).  cp has had improvements since, but why not use [[UbuntuHelp:rsync|rsync]], a tool that is designed for backups like moving your /home, and much more.  Rsync is not only able to copy over all the files, but is also able to maintain other characteristics of the file, like permissions, ownership, and timestamps.
+
* [[UbuntuHelp:rsync | Rsync]] is designed for backups of /home, and much more.  It is able to maintain other characteristics of the file, like permissions, ownership, and timestamps. There was a lot of debate about which command to copy your files to the new /home partition which stemmed from a time when cp was not able to do it properly (apparently it skipped files?).  Cp was not designed to be a powerful backup tool, rsync was.  The fix, then, was to use a combination of find and cpio ([http://www.us.debian.org/doc/manuals/reference/ch-tips.en.html#s-archiving See section 8.3.5]).
 
== The Guide ==
 
== The Guide ==
Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade/reinstall/use a different distro.  This works because /home has a subfolder for each user's settings and files.  Also, fresh installs for linux typically like to wipe whatever partition they are being installed to, hence the need to put /home on a different partition.   
+
Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro.  This works because /home has a sub-folder for each user's settings and files which contain all the data & settings of that user.  Also, fresh installs for linux typically like to wipe whatever partition they are being installed to so either the data & settings need to be backed-up elsewhere or else avoid the fuss each time by having /home on a different partition.   
 
=== Setup Partitions ===
 
=== Setup Partitions ===
This is beyond the scope of this page.  [[UbuntuHelp:HowtoPartition|Try here if you need help]].  Memorize or write down the location of the partition, something like /sda3 or /hda3.  Its been suggested to use either ext2 or ext3 over vfat.  Using vfat is not supported and may fail, since vfat does not support permissions.   
+
This is beyond the scope of this page.  [[UbuntuHelp:HowtoPartition|Try here if you need help]].  Memorize or write down the location of the partition, something like /sda3.  Its been suggested to use either ext2, ext3 or ext4 rather than vfat or ntfs.  Using vfat is not supported and may fail, since vfat does not support permissions.  Ntfs has an advantage of being journalised, like ext3 & ext4 but it can also be read easily by Windows. It is a lot less stable than ext3 or ext4 so it is really a question of stability compared with easy access for Windows. If you don't dual-boot with Windows or have plenty of hard-drive space then staying with very much safer ext3 or 4 is the obvious choice.
=== Setup Fstab ===
+
=== Find the uuid of the Partition ===
Use your favorite editor to edit fstab, like: gksu gedit /etc/fstab <<BR>>
+
The uuid reference to all partitions get to a [[UbuntuHelp:UsingTheTerminal#Starting_a_Terminal|| command-line]] to try this
Add a line for your partition; something like the following line:
+
 
<pre><nowiki>
 
<pre><nowiki>
UUID=????????  /media/home    ext3          nodev,nosuid      0      2
+
sudo blkid
# (identifier)  (location  )  (format)      (  some settings          ) 
+
 
</nowiki></pre>
 
</nowiki></pre>
You should replace the ?'s with the UUID of the intended /home partition.
+
Now you just need to note down (copy&paste into a text-file) the uuid of the partition that you have set-up ready to be the new /home partition. Some older releases of Ubuntu might not have the "blkid" command so this could be used instead
The UUID can be found with:
+
 
<pre><nowiki>
 
<pre><nowiki>
sudo vol_id -u <partition>
+
sudo vol_id -u <partition>
 +
</nowiki></pre>
 +
for example
 +
<pre><nowiki>
 +
sudo vol_id -u /dev/sda3
 +
</nowiki></pre>
 +
=== Setup Fstab ===
 +
These commands should;
 +
1. Create a backup of fstab. Replace "!DateToday" with today's date so you can find the right back-up easily if you do need to use it later.
 +
2. Open the standard text-editor to edit fstab. Note that Kubuntu uses "kate" & Xubuntu uses "mousepad" instead of "gedit" but you could use any text-editor you have installed if you prefer.
  
 +
<pre><nowiki>
 +
sudo cp /etc/fstab /etc/fstab.DateToday
 +
gksu gedit /etc/fstab
 
</nowiki></pre>
 
</nowiki></pre>
eg
+
and add these lines into it
 
<pre><nowiki>
 
<pre><nowiki>
  sudo vol_id -u /dev/sda3
+
# (identifier) (location, eg sda5)  (format, eg ext3 or ext4)      (some settings)
 +
UUID=????????  /media/home    ext3          nodev,nosuid      0      2
 
</nowiki></pre>
 
</nowiki></pre>
The Fstab location should be a temporary one - we are to mount the temporary location and copy the existing home to it.  (/media/home is assumed in the rest of the guide). If /media/home does not exist yet, then you should create it with the command:
+
Replace???????? with the UUID number of the intended /home partition.
 +
The Fstab location will be a temporary one - we are to mount the temporary location and copy the existing home to it.  (/media/home is assumed in the rest of the guide). If /media/home does not exist yet, then you should create it with the command:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mkdir /media/home
 
sudo mkdir /media/home
第37行: 第49行:
 
sudo mount -a
 
sudo mount -a
 
</nowiki></pre>
 
</nowiki></pre>
Check that you can copy files over, at least as root (ie with sudo).
 
 
=== Copy /home to the New Partition ===
 
=== Copy /home to the New Partition ===
 
<pre><nowiki>
 
<pre><nowiki>
第43行: 第54行:
 
</nowiki></pre>
 
</nowiki></pre>
 
The --exclude='/*/.gvfs' prevents rsync from complaining about not being able to copy .gvfs, but I believe it optional.  Even if rsync complains, it will copy everything else anyway.  ([http://ubuntuforums.org/showthread.php?t=791693 See here for discussion on this])
 
The --exclude='/*/.gvfs' prevents rsync from complaining about not being able to copy .gvfs, but I believe it optional.  Even if rsync complains, it will copy everything else anyway.  ([http://ubuntuforums.org/showthread.php?t=791693 See here for discussion on this])
=== Make the Switch ===
+
=== Check Copying Worked ===
Here is the point of no return. If the previous two steps worked, you should have no troubles.
+
The data in /home now exists in 2 places but we need to check that it looks about right. If it looks approximately the same then it is probably completely right.
Rename your /home directory:
+
=== A Sneaky Safety Manoeuvre ===
 +
So you now have 2 copies of your /home folder. The new one on the new partition and the old one still in the same partition it was always in. The problem is how to delete the right one!! Since we are still using the old /home 'just' rename your current /home folder:
 
<pre><nowiki>
 
<pre><nowiki>
 +
cd /
 
sudo mv /home /old_home
 
sudo mv /home /old_home
 
</nowiki></pre>
 
</nowiki></pre>
Re-create a /home directory with (this is because the next steps need the location to already exist):
+
Now re-create a new blank /home directory just in case it has all gone wrong!
 +
<pre><nowiki>
 +
cd /
 +
sudo mkdir /home/user
 +
</nowiki></pre>
 +
Now if things have gone wrong then the system will boot into what appears to be a fresh install with all your data missing. In fact, of course, there are still 2 copies of it all :)
 +
=== Make the Switch ===
 +
We now need to modify the fstab again to point to the new /home and mount it properly. So again on a command-line
 +
<pre><nowiki>
 +
gksu gedit /etc/fstab
 +
</nowiki></pre>
 +
and now edit the lines you added earlier to delete the /media part. This should make /media/home into /home as follows
 
<pre><nowiki>
 
<pre><nowiki>
sudo mkdir /home
+
# (identifier)  (location, eg sda5)  (format, eg ext3 or ext4)      (some settings)
 +
UUID=????????  /home   ext3          nodev,nosuid      0      2
 
</nowiki></pre>
 
</nowiki></pre>
~-''It seems that this guide fails at this point (under 9.04) because sudo fails as it can not find the config files it needs to check the users sudo permissions. This is because /home no longer exists. To fix this I needed to start a shell as root (su command and supply the root password) and create the new /home. - Roger Morton ''-~
 
Edit fstab so that your new home partition actually points to /home (ie. by changing /media/home to /home)
 
~-''gksudo would not launch gedit (for the same reason sudo failed above I suspect) so I was forced to use vi to edit my fstab. And I hate vi. - Roger Morton ''-~
 
 
and finally, remount the partition with:
 
and finally, remount the partition with:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo mount -a
 
sudo mount -a
 
</nowiki></pre>
 
</nowiki></pre>
~-''I recall that this failed too. I think because home is already mounted - even though we have renamed it. umount /home failed because /home was in use by the GUI. In the end I had to reboot and bring up the recovery console as root and fix the mess. So bottom line - I don't think this is such a good guide. Needs further work and testing. - Roger Morton''-~
+
Does it all still look fine? Can you still access your files & folders from the "Places" menu? Reboot to ensure that currently running programs use the /home that is on the new partition.
Reboot to ensure that currently running programs use the new /home
+
 
=== After a reboot ===
 
=== After a reboot ===
 
If everything is working, great, you can delete /old_home.  If things aren't working, you can undo by moving your /old_home back to /home, and delete the line you added to fstab.
 
If everything is working, great, you can delete /old_home.  If things aren't working, you can undo by moving your /old_home back to /home, and delete the line you added to fstab.

2010年5月19日 (三) 23:50的最新版本

The Advantages of This Guide

This guide was written simply because there were flaws in the other guides and it was worth recording these notes for future reference. Community Documentation is an excellent way to help others at the same time. This guide:

  • Aims to keep the system usable and the data all safe.
  • If the system unexpectedly loses power or goes into hibernate mode or anything at any point through this guide then it should still boot-up & work just fine. That's the main aim anyway.
  • Prepares Partitions and fstab first then only tweaks fstab at the end
  • People test and gain familiarity with the tools before the final crunch-test, another advantage of this guide. Some other guides use mount commands, then move the /home & then set-up fstab. However, if you mess up your fstab at that crunch-point then when you reboot your system will lose track of your /home files! Setting up fstab first and using "sudo mount -a" to mount the partitions checks the modified fstab works at a safe point in the process.
  • Use rsync to move the files
  • Rsync is designed for backups of /home, and much more. It is able to maintain other characteristics of the file, like permissions, ownership, and timestamps. There was a lot of debate about which command to copy your files to the new /home partition which stemmed from a time when cp was not able to do it properly (apparently it skipped files?). Cp was not designed to be a powerful backup tool, rsync was. The fix, then, was to use a combination of find and cpio (See section 8.3.5).

The Guide

Setting up /home on a separate partition is beneficial because your settings, files, and desktop will be maintained if you upgrade, (re)install Ubuntu or another distro. This works because /home has a sub-folder for each user's settings and files which contain all the data & settings of that user. Also, fresh installs for linux typically like to wipe whatever partition they are being installed to so either the data & settings need to be backed-up elsewhere or else avoid the fuss each time by having /home on a different partition.

Setup Partitions

This is beyond the scope of this page. Try here if you need help. Memorize or write down the location of the partition, something like /sda3. Its been suggested to use either ext2, ext3 or ext4 rather than vfat or ntfs. Using vfat is not supported and may fail, since vfat does not support permissions. Ntfs has an advantage of being journalised, like ext3 & ext4 but it can also be read easily by Windows. It is a lot less stable than ext3 or ext4 so it is really a question of stability compared with easy access for Windows. If you don't dual-boot with Windows or have plenty of hard-drive space then staying with very much safer ext3 or 4 is the obvious choice.

Find the uuid of the Partition

The uuid reference to all partitions get to a | command-line to try this

sudo blkid

Now you just need to note down (copy&paste into a text-file) the uuid of the partition that you have set-up ready to be the new /home partition. Some older releases of Ubuntu might not have the "blkid" command so this could be used instead

sudo vol_id -u <partition>

for example

sudo vol_id -u /dev/sda3

Setup Fstab

These commands should; 1. Create a backup of fstab. Replace "!DateToday" with today's date so you can find the right back-up easily if you do need to use it later. 2. Open the standard text-editor to edit fstab. Note that Kubuntu uses "kate" & Xubuntu uses "mousepad" instead of "gedit" but you could use any text-editor you have installed if you prefer.

sudo cp /etc/fstab /etc/fstab.DateToday
gksu gedit /etc/fstab

and add these lines into it

# (identifier)  (location, eg sda5)   (format, eg ext3 or ext4)      (some settings) 
UUID=????????   /media/home    ext3          nodev,nosuid       0       2 

Replace???????? with the UUID number of the intended /home partition. The Fstab location will be a temporary one - we are to mount the temporary location and copy the existing home to it. (/media/home is assumed in the rest of the guide). If /media/home does not exist yet, then you should create it with the command:

sudo mkdir /media/home

Now, mount the partition with:

sudo mount -a

Copy /home to the New Partition

sudo rsync -axS --exclude='/*/.gvfs' /home/. /media/home/.

The --exclude='/*/.gvfs' prevents rsync from complaining about not being able to copy .gvfs, but I believe it optional. Even if rsync complains, it will copy everything else anyway. (See here for discussion on this)

Check Copying Worked

The data in /home now exists in 2 places but we need to check that it looks about right. If it looks approximately the same then it is probably completely right.

A Sneaky Safety Manoeuvre

So you now have 2 copies of your /home folder. The new one on the new partition and the old one still in the same partition it was always in. The problem is how to delete the right one!! Since we are still using the old /home 'just' rename your current /home folder:

cd /
sudo mv /home /old_home

Now re-create a new blank /home directory just in case it has all gone wrong!

cd /
sudo mkdir /home/user

Now if things have gone wrong then the system will boot into what appears to be a fresh install with all your data missing. In fact, of course, there are still 2 copies of it all :)

Make the Switch

We now need to modify the fstab again to point to the new /home and mount it properly. So again on a command-line

gksu gedit /etc/fstab

and now edit the lines you added earlier to delete the /media part. This should make /media/home into /home as follows

# (identifier)  (location, eg sda5)   (format, eg ext3 or ext4)      (some settings) 
UUID=????????   /home    ext3          nodev,nosuid       0       2

and finally, remount the partition with:

sudo mount -a

Does it all still look fine? Can you still access your files & folders from the "Places" menu? Reboot to ensure that currently running programs use the /home that is on the new partition.

After a reboot

If everything is working, great, you can delete /old_home. If things aren't working, you can undo by moving your /old_home back to /home, and delete the line you added to fstab.

Technical Notes and Resources

Rsync was chosen over cp and find|cpio because it seemed to maintain permissions. http://ubuntu.wordpress.com/2006/01/29/move-home-to-its-own-partition/ http://ubuntuforums.org/showthread.php?t=46866