个人工具

“UbuntuHelp:MoveMountpointHowto”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/MoveMountpointHowto}} {{Languages|UbuntuHelp:MoveMountpointHowto}} == MoveMountpointHowto == Tonight I had the undesirable experience of spending...)
 
 
(未显示同一用户的7个中间版本)
第1行: 第1行:
 
{{From|https://help.ubuntu.com/community/MoveMountpointHowto}}
 
{{From|https://help.ubuntu.com/community/MoveMountpointHowto}}
 
{{Languages|UbuntuHelp:MoveMountpointHowto}}
 
{{Languages|UbuntuHelp:MoveMountpointHowto}}
== MoveMountpointHowto ==
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconHandPointing.png It is sometimes necessary to move mount points, for any number of reasons.  Perhaps you keep separate partitions for each folder in the root of the filesystem, or maybe you need to store a large database, or perhaps you just want to change where your second hard disk or data partition mounts.
 +
== Who is this Guide For? ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconDisks.png This guide is for basic changing of mount points.  It will help you edit you file systems table configuration file, <code><nowiki>/etc/fstab</nowiki></code>, to achieve this.  Please refer to this link about [[UbuntuHelp:Fstab| fstab]]; we will not be covering details from that page here, so it is recommended reading to accompany this guide.
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=dont.png If you are using external disks, you do not usually want to create mount points in fstab, but rather let the hal daemon automount them for you.  In this case you can label the partitions instead - see [[UbuntuHelp:RenameUSBDrive|RenameUSBDrive]].
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=stop.png If you are looking to create a separate /home partition, I am currently in the process of writing a wiki page for doing this on systems that are already setup.  A link will be posted here when it is complete.  In the meantime, see these two links:
 +
* http://www.psychocats.net/ubuntu/separatehome
 +
* http://ubuntu.wordpress.com/2006/01/29/move-home-to-its-own-partition/
 +
== Getting Started ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png To change mount points, we must edit the fstab file (see link above), so let's open it and have it fork to the background with the & symbol.  For Ubuntu, open a terminal and run:
 +
<pre><nowiki>
 +
gksudo gedit /etc/fstab &
 +
</nowiki></pre>
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=important.png '''Remember, the following are examples.  Do not copy and paste them to your system; they will not work for you.'''
 +
== Basic Example ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png  Let's say we want to change a mount point from <code><nowiki>/media/disk2</nowiki></code> to <code><nowiki>/mnt/backup</nowiki></code>.  First, unmount the partition, delete the old mount point, and make the new mount point.
 +
<pre><nowiki>
 +
sudo umount /media/disk2
 +
sudo rmdir /media/disk2
 +
sudo mkdir /mnt/backup
 +
</nowiki></pre>
 +
You must know which partition you want to change, so find what you are looking for by cross referencing the contents of fstab with the output of this command:
 +
<pre><nowiki>
 +
sudo fdisk -l
 +
</nowiki></pre>
 +
The output may look something like this:
 +
<pre><nowiki>
 +
Disk /dev/sda: 80.0 GB, 80026361856 bytes
 +
255 heads, 63 sectors/track, 9729 cylinders
 +
Units = cylinders of 16065 * 512 = 8225280 bytes
 +
Disk identifier: 0x41ab2316
  
Tonight I had the undesirable experience of spending hours trying to figure out why after I moved my mount point it would no longer automount on reboot! It turns out the answer is extremely simple if you know it and painfully hidden if you don't.
+
  Device Boot      Start        End      Blocks  Id System
It will take you longer to read this wiki than it will to fix the problem. Its easiest to do this from a terminal so if you're not there yet, start by opening a terminal window.
+
/dev/sda1  *          1        5476    43985938+  7 HPFS/NTFS
 +
/dev/sda2            5477        9548    32708340  83  Linux
 +
/dev/sda3            9549        9729    1453882+  5  Extended
 +
/dev/sda5            9549        9729    1453851  82  Linux swap / Solaris
  
Now in my case I had created a partition '''~+/dev/hda6+~''' as mount point '''~+/usr/local/mysql+~''' because I was expecting a large database and wanted to be sure it had enough room devoted just to it. BUT it turns out that mysql likes its data in '''~+/var/lib/mysql+~'''! *UGH* So I needed to move the mount point.  This tutorial had not been written yet and is NOT covered in the mount man page so I spent hours trying to get my system to work properly.  The only indication that anything was even wrong was when it kept saying "mounting local file system failed" at Boot Time.
+
Disk /dev/sdb: 300.0 GB, 300069051904 bytes
So if that happens to you after reading this wiki, then you've skipped a step or made a typo!
+
255 heads, 63 sectors/track, 36481 cylinders
 +
Units = cylinders of 16065 * 512 = 8225280 bytes
 +
Disk identifier: 0x3d9c576e
  
Anticipate this job to take 5-10 minutes from start to finishMore if you have to read this and do it at the same time.
+
  Device Boot      Start        End      Blocks  Id  System
 
+
/dev/sdb1              1      36481  293033601    7  Linux
First thing I needed to do is stop mysql and save my data! You can skip this part if you're just moving a regular mount point.
+
</nowiki></pre>
 +
Locate the entry you want to changeLet's say you discover that the device is <code><nowiki>/dev/sdb1</nowiki></code>. Then you will change the line in fstab from something like
 
<pre><nowiki>
 
<pre><nowiki>
sudo /etc/init.d/mysql stop
+
/dev/sdb1 /media/disk2 ext3 defaults,errors=remount-ro  0  2 
sudo mv /var/lib/mysql /var/lib/mysql_temp
+
 
</nowiki></pre>
 
</nowiki></pre>
 
+
to
ok, now lets take at look at '''~+/etc/fstab+~'''
+
<pre><nowiki>
 +
/dev/sdb1 /mnt/backup ext3 defaults,errors=remount-ro  0  2 
 +
</nowiki></pre>
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png What's that?  It has <code><nowiki>UUID=<some_strange_number></nowiki></code> instead of a /dev location?  [[UbuntuHelp:UsingUUID| UUIDs]] are just newer way of identifying partitions - to view correspending /dev locations, you can run one of these commands:
 +
<pre><nowiki>
 +
sudo blkid
 +
ls -l /dev/disk/by-uuid</nowiki></pre>
 +
It is recommended that you keep the UUID instead of changing that column of fstab to a /dev location, but either will typically work.
 +
Now that you have changed fstab, save and close the file.  You can now remount everything in fstab, including the partition you changed, by running
 +
<pre><nowiki>
 +
sudo mount -a
 +
</nowiki></pre>
 +
== Advanced Example ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconExample48.png Some users have each directory in the root of the filesystem mounted on different partitions.  While this isn't generally recommended to beginners, this method has its purposes, which will not be covered here.
 +
Let's say your fstab file looks like this:
 
<pre><nowiki>
 
<pre><nowiki>
sudo nano -w /etc/fstab
 
 
 
# /etc/fstab: static file system information.
 
# /etc/fstab: static file system information.
 
#
 
#
第37行: 第83行:
 
/dev/hda8  none              swap        sw                          0  0   
 
/dev/hda8  none              swap        sw                          0  0   
 
/dev/hdc    /media/cdrom0    udf,iso9660  user,noauto                0  0   
 
/dev/hdc    /media/cdrom0    udf,iso9660  user,noauto                0  0   
/etc/fstab (END)
 
 
</nowiki></pre>
 
</nowiki></pre>
 
+
I have isolated 3 mount points that will be important and surrounded them with "#####".
Now while we're in here looking lets go ahead and make the changes we need to make.
+
So now, you want to change <code><nowiki>/dev/hda6</nowiki></code> from <code><nowiki>/usr/local/mysql</nowiki></code> to <code><nowiki>/var/lib/mysql</nowiki></code>.  First, unmount the partition, delete the old mount point, and make the new mount point.
 
+
 
<pre><nowiki>
 
<pre><nowiki>
move your cursor down to the line you want to change and make your change
+
sudo umount /usr/local/mysql
 
+
sudo rmdir /usr/local/mysql
# /etc/fstab: static file system information.
+
sudo mkdir -p /var/lib/mysql
#
+
</nowiki></pre>
# <file system> <mount point>  <type>  <options>      <dump>  <pass>
+
Your first idea would be to simply change the mount point so that the relevant portion of fstab looks as follows:
proc        /proc            proc        defaults                    0  0 
+
<pre><nowiki>
/dev/hda10  /                 ext3        defaults,errors=remount-ro  0  1 
+
/dev/hda6  /var/lib/mysql   ext3        defaults                    0  2   
/dev/hda1  /boot            ext3        defaults                    0  2 
+
/dev/hda5  /ftp              ext3        noexec,user_xattr          0  2 
+
/dev/hda7  /home            ext3        defaults                    0  2 
+
/dev/hda9  /tmp              ext3        defaults                    0  2 
+
/dev/hda12  /usr              ext3        defaults                    0  2 
+
/dev/hda6  /var/lib/mysql ext3        defaults                    0  2   
+
 
/dev/hda13  /var              ext3        defaults                    0  2   
 
/dev/hda13  /var              ext3        defaults                    0  2   
 
/dev/hda11  /var/www          ext3        defaults                    0  2   
 
/dev/hda11  /var/www          ext3        defaults                    0  2   
/dev/hda2  /share            ext3        defaults                    0  2 
 
/dev/hda8  none              swap        sw                          0  0 
 
/dev/hdc    /media/cdrom0    udf,iso9660  user,noauto                0  0 
 
/etc/fstab (END)
 
 
</nowiki></pre>
 
</nowiki></pre>
 
+
However, you have a problem.  If you reboot the computer, you will get an error like
Now notice that /var/lib/mysql comes '''~+BEFORE+~''' "/var"  This will never work!  This is why I had so many problemsAll the mount points in "/etc/fstab" must be in alphabetical order.  "Trunk" first then "limbs"So lets fix that while we're here.
+
<pre><nowiki>
 +
Mounting Local File System Failed
 +
</nowiki></pre>
 +
Why?  The main problem is that you are mounting <code><nowiki>/var/lib/mysql</nowiki></code> before <code><nowiki>/var</nowiki></code>As the original documenter of this page put it, the mount order must be like ''trunk first then limbs''You should mount the filesystem in alphabetical order, with subdirectories being mounted ''after'' their parent directories. You must move <code><nowiki>/dev/hda6</nowiki></code> down in the file, so that the relevant portion of the file now reads:
 
<pre><nowiki>
 
<pre><nowiki>
While your cusor is still on the line that you changed, hit ^k [CTRL]+K if your used to windows verbage.
 
Then move down to where it should be and hit ^u [CTRL]+u.
 
 
Now your work should look like this....
 
 
# /etc/fstab: static file system information.
 
#
 
# <file system> <mount point>  <type>  <options>      <dump>  <pass>
 
proc        /proc            proc        defaults                    0  0 
 
/dev/hda10  /                ext3        defaults,errors=remount-ro  0  1 
 
/dev/hda1  /boot            ext3        defaults                    0  2 
 
/dev/hda5  /ftp              ext3        noexec,user_xattr          0  2 
 
/dev/hda7  /home            ext3        defaults                    0  2 
 
/dev/hda9  /tmp              ext3        defaults                    0  2 
 
/dev/hda12  /usr              ext3        defaults                    0  2 
 
 
/dev/hda13  /var              ext3        defaults                    0  2   
 
/dev/hda13  /var              ext3        defaults                    0  2   
 
/dev/hda6  /var/lib/mysql    ext3        defaults                    0  2   
 
/dev/hda6  /var/lib/mysql    ext3        defaults                    0  2   
/dev/hda11  /var/www          ext3        defaults                    0  2
+
/dev/hda11  /var/www          ext3        defaults                    0  2  
/dev/hda2  /share            ext3        defaults                    0  2 
+
/dev/hda8  none              swap        sw                          0  0 
+
/dev/hdc    /media/cdrom0    udf,iso9660  user,noauto                0  0 
+
/etc/fstab (END)
+
 
</nowiki></pre>
 
</nowiki></pre>
 
+
== Having Problems? ==
Notice "/dev/hda6" its now been moved to where it should live.
+
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=query.png
a few more simple steps and we're done.
+
<ol><li>If your partition won't initially unmount, make sure all programs using data on that device are closed, including nautilus (the file browser), and try a lazy unmount:</li></ol>
  
 
<pre><nowiki>
 
<pre><nowiki>
Now hit ^x or [CTRL]+x, followed by two [ENTER]'s to save your work.
+
  sudo umount -l <foo></nowiki></pre>
</nowiki></pre>
+
In this case, <foo> is either the mount point or the /dev location.
 
+
<ol><li>If you get the error <code><nowiki>rmdir: failed to remove `test': Directory not empty</nowiki></code>, the partition is not unmounted correctly, see #1.
That being done lets do the final steps..
+
</li><li>Getting errors when you try to mount?  Be sure that you have created the new mount point and have spelled it correctly in the directory structure and in fstab.  Do not use mount points with spaces in the name - while this is possible, it is a pain to deal with and is not worth the trouble.  If you have this problem, it is creating issues in your fstab file because the parser thinks that whatever is coming after the space is the next column in fstab.
 
+
</li><li>Getting <code><nowiki>Mounting Local File System Failed</nowiki></code> at boot time?  Refer to the Advanced Example.</li></ol>
<pre><nowiki>
+
sudo mkdir -p /var/lib/mysql
+
sudo mount --move /usr/local/mysql /var/lib/mysql
+
sudo cp -rp /var/lib/mysql_temp/ /var/lib/mysql/
+
sudo mount -a
+
sudo /etc/init.d/mysql start
+
sudo rm -rf /usr/local/mysql
+
sudo rm -rf /var/lib/mysql_temp
+
</nowiki></pre>
+
  
That's it! You're done. Congratulations and enjoy your new mount point.
+
== Other Resources ==
 +
https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png
 +
* [[UbuntuHelp:Fstab|Fstab]]
 +
* [http://ubuntuforums.org/showthread.php?t=283131 How to fstab] - from the Ubuntu Forums
 +
* [[UbuntuHelp:MountingWindowsPartitions|MountingWindowsPartitions]]
 +
* [[UbuntuHelp:HowtoPartition|HowtoPartition]]
 +
* [[UbuntuHelp:InstallingANewHardDrive|InstallingANewHardDrive]]
 
----
 
----
[[category:CategoryDocumentation]] [[category:CategoryCleanup]]
 
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

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

IconsPage?action=AttachFile&do=get&target=IconHandPointing.png It is sometimes necessary to move mount points, for any number of reasons. Perhaps you keep separate partitions for each folder in the root of the filesystem, or maybe you need to store a large database, or perhaps you just want to change where your second hard disk or data partition mounts.

Who is this Guide For?

IconsPage?action=AttachFile&do=get&target=IconDisks.png This guide is for basic changing of mount points. It will help you edit you file systems table configuration file, /etc/fstab, to achieve this. Please refer to this link about fstab; we will not be covering details from that page here, so it is recommended reading to accompany this guide. IconsPage?action=AttachFile&do=get&target=dont.png If you are using external disks, you do not usually want to create mount points in fstab, but rather let the hal daemon automount them for you. In this case you can label the partitions instead - see RenameUSBDrive. IconsPage?action=AttachFile&do=get&target=stop.png If you are looking to create a separate /home partition, I am currently in the process of writing a wiki page for doing this on systems that are already setup. A link will be posted here when it is complete. In the meantime, see these two links:

Getting Started

IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png To change mount points, we must edit the fstab file (see link above), so let's open it and have it fork to the background with the & symbol. For Ubuntu, open a terminal and run:

gksudo gedit /etc/fstab &

IconsPage?action=AttachFile&do=get&target=important.png Remember, the following are examples. Do not copy and paste them to your system; they will not work for you.

Basic Example

IconsPage?action=AttachFile&do=get&target=example.png Let's say we want to change a mount point from /media/disk2 to /mnt/backup. First, unmount the partition, delete the old mount point, and make the new mount point.

sudo umount /media/disk2
sudo rmdir /media/disk2
sudo mkdir /mnt/backup

You must know which partition you want to change, so find what you are looking for by cross referencing the contents of fstab with the output of this command:

sudo fdisk -l

The output may look something like this:

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x41ab2316

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        5476    43985938+   7  HPFS/NTFS
/dev/sda2            5477        9548    32708340   83  Linux
/dev/sda3            9549        9729     1453882+   5  Extended
/dev/sda5            9549        9729     1453851   82  Linux swap / Solaris

Disk /dev/sdb: 300.0 GB, 300069051904 bytes
255 heads, 63 sectors/track, 36481 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x3d9c576e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       36481   293033601    7  Linux

Locate the entry you want to change. Let's say you discover that the device is /dev/sdb1. Then you will change the line in fstab from something like

/dev/sdb1	/media/disk2	ext3	defaults,errors=remount-ro  0  2  

to

/dev/sdb1	/mnt/backup	ext3	defaults,errors=remount-ro  0  2  

IconsPage?action=AttachFile&do=get&target=IconTip.png What's that? It has UUID=<some_strange_number> instead of a /dev location? UUIDs are just newer way of identifying partitions - to view correspending /dev locations, you can run one of these commands:

sudo blkid
 ls -l /dev/disk/by-uuid

It is recommended that you keep the UUID instead of changing that column of fstab to a /dev location, but either will typically work. Now that you have changed fstab, save and close the file. You can now remount everything in fstab, including the partition you changed, by running

sudo mount -a

Advanced Example

IconsPage?action=AttachFile&do=get&target=IconExample48.png Some users have each directory in the root of the filesystem mounted on different partitions. While this isn't generally recommended to beginners, this method has its purposes, which will not be covered here. Let's say your fstab file looks like this:

# /etc/fstab: static file system information.
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc        /proc             proc         defaults                    0  0  
/dev/hda10  /                 ext3         defaults,errors=remount-ro  0  1  
/dev/hda1   /boot             ext3         defaults                    0  2  
/dev/hda5   /ftp              ext3         noexec,user_xattr           0  2  
/dev/hda7   /home             ext3         defaults                    0  2  
/dev/hda9   /tmp              ext3         defaults                    0  2  
/dev/hda12  /usr              ext3         defaults                    0  2  
/dev/hda6   /usr/local/mysql  ext3         defaults                    0  2  
/dev/hda13  /var              ext3         defaults                    0  2  
/dev/hda11  /var/www          ext3         defaults                    0  2  
/dev/hda2   /share            ext3         defaults                    0  2  
/dev/hda8   none              swap         sw                          0  0  
/dev/hdc    /media/cdrom0     udf,iso9660  user,noauto                 0  0  

I have isolated 3 mount points that will be important and surrounded them with "#####". So now, you want to change /dev/hda6 from /usr/local/mysql to /var/lib/mysql. First, unmount the partition, delete the old mount point, and make the new mount point.

sudo umount /usr/local/mysql
sudo rmdir /usr/local/mysql
sudo mkdir -p /var/lib/mysql

Your first idea would be to simply change the mount point so that the relevant portion of fstab looks as follows:

/dev/hda6   /var/lib/mysql    ext3         defaults                    0  2  
/dev/hda13  /var              ext3         defaults                    0  2  
/dev/hda11  /var/www          ext3         defaults                    0  2  

However, you have a problem. If you reboot the computer, you will get an error like

Mounting Local File System Failed

Why? The main problem is that you are mounting /var/lib/mysql before /var. As the original documenter of this page put it, the mount order must be like trunk first then limbs. You should mount the filesystem in alphabetical order, with subdirectories being mounted after their parent directories. You must move /dev/hda6 down in the file, so that the relevant portion of the file now reads:

/dev/hda13  /var              ext3         defaults                    0  2  
/dev/hda6   /var/lib/mysql    ext3         defaults                    0  2  
/dev/hda11  /var/www          ext3         defaults                    0  2 

Having Problems?

IconsPage?action=AttachFile&do=get&target=query.png

  1. If your partition won't initially unmount, make sure all programs using data on that device are closed, including nautilus (the file browser), and try a lazy unmount:
 sudo umount -l <foo>

In this case, <foo> is either the mount point or the /dev location.

  1. If you get the error rmdir: failed to remove `test': Directory not empty, the partition is not unmounted correctly, see #1.
  2. Getting errors when you try to mount? Be sure that you have created the new mount point and have spelled it correctly in the directory structure and in fstab. Do not use mount points with spaces in the name - while this is possible, it is a pain to deal with and is not worth the trouble. If you have this problem, it is creating issues in your fstab file because the parser thinks that whatever is coming after the space is the next column in fstab.
  3. Getting Mounting Local File System Failed at boot time? Refer to the Advanced Example.

Other Resources

IconsPage?action=AttachFile&do=get&target=IconBook-small.png