“UbuntuHelp:Mount/USB”的版本间的差异
来自Ubuntu中文
小 (新页面: {{From|https://help.ubuntu.com/community/Mount/USB}} {{Languages|UbuntuHelp:Mount/USB}} This page explains how to mount and unmount a USB removable drive. To provide users access to mount...) |
小 |
||
第1行: | 第1行: | ||
{{From|https://help.ubuntu.com/community/Mount/USB}} | {{From|https://help.ubuntu.com/community/Mount/USB}} | ||
{{Languages|UbuntuHelp:Mount/USB}} | {{Languages|UbuntuHelp:Mount/USB}} | ||
− | This page explains how to | + | This page explains how to use USB drives, like external hard disks and USB flash drives (aka USB sticks, thumb drives, pen drives, etc). The material here also applies to flash cards (like in your digital camera). |
− | + | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=stop.png%7D%7D If you are looking for help with internal hard drives, see these links: | |
− | + | * [[Fstab]] | |
+ | * [[MountingWindowsPartitions]] | ||
+ | * [[MountingWindowsPartitions/ThirdPartyNTFS3G]] | ||
+ | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png%7D%7D USB storage devices have the enormous advantage that for the most part they use a standard set of protocols. Thus, instead of needing individual drivers, as does much computer hardware, a standard driver permits access to the devices, making them very portable and able to easily work on many platforms. | ||
+ | == Automounting == | ||
+ | ==== Mounting ==== | ||
+ | By default, storage devices that are plugged into the system mount automatically and place an icon on your desktop, often called "disk" and as more drives are added, you can get "disk-1" and so on. | ||
+ | To change the automatic mount point and label of external drives, see [[RenameUSBDrive]]. | ||
+ | To have a program automatically start when you plug in a device, go to '''System->Preferences->Removable Drives and Media'''. For more complex scenarios, see [[UsbDriveDoSomethingHowto]]. | ||
+ | ==== Unmounting/Ejecting ==== | ||
+ | Before you disconnect the device, don't forget to unmount it. This can be done by right clicking the desktop icon and selecting "Unmount" (or in some cases, "Eject"). | ||
+ | == Automounting (Ubuntu Server) == | ||
+ | By default, disk drives do not automount in Ubuntu Server Edition. If you are looking for a lightweight solution that does not depend on HAL/DBUS, you can install "usbmount". | ||
+ | == Manually Mounting == | ||
+ | === Using mount === | ||
+ | ==== Get the Information ==== | ||
+ | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png%7D%7D Sometimes devices don't automount, in which case you should try to manually mount it. First, you must know what device we are dealing with and what filesystem it is formatted with. Most flash drives are FAT16 or FAT32 and most external hard disks are NTFS. | ||
<pre><nowiki> | <pre><nowiki> | ||
− | + | sudo fdisk -l | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</nowiki></pre> | </nowiki></pre> | ||
− | + | Find your device in the list, it is probably something like /dev/sdb1. For more information about filesystems, see [[LinuxFilesystemsExplained]]. | |
+ | ==== Create the Mount Point ==== | ||
+ | Now we need to create a mount point for the device, let's say we want to call it "external". You can call it whatever you want, just please don't use spaces in the name or it gets a little more complicated - use an underscore to separate words (like "my_external"). Create the mount point: | ||
<pre><nowiki> | <pre><nowiki> | ||
− | + | sudo mkdir /media/external | |
− | + | ||
− | + | ||
</nowiki></pre> | </nowiki></pre> | ||
− | + | ==== Mount the Drive ==== | |
+ | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D We can now mount the drive. Let's say the device is /dev/sdb1, the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point): | ||
<pre><nowiki> | <pre><nowiki> | ||
− | + | sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137 | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</nowiki></pre> | </nowiki></pre> | ||
− | + | The options following the "-o" allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don't use those extra options you ''may'' not be able to read and write the drive with your regular username. | |
+ | Otherwise if the device is formatted with NTFS, run: | ||
<pre><nowiki> | <pre><nowiki> | ||
− | + | sudo mount -t ntfs-3g /dev/sdb1 /media/external | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
</nowiki></pre> | </nowiki></pre> | ||
− | + | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconNote.png%7D%7D You must have the ntfs-3g driver installed. See [[MountingWindowsPartitions/ThirdPartyNTFS3G]] for more information. | |
− | + | ==== Unmounting the Drive ==== | |
− | === | + | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 mounted at /media/external, you can either unmount using the device or the mount point: |
− | + | <pre><nowiki> | |
− | + | sudo umount /dev/sdb1 | |
− | + | </nowiki></pre> | |
+ | or: | ||
+ | <pre><nowiki> | ||
+ | sudo umount /media/external | ||
+ | </nowiki></pre> | ||
+ | You cannot unmount from the desktop by right clicking the icon if the drive was manually mounted. | ||
+ | === Using pmount === | ||
+ | There is a program called <code><nowiki>pmount</nowiki></code> available in the [[Repositories/Ubuntu| repositories]] which allows unprivileged users to mount drives as if they were using sudo, even without an entry in [[Fstab| /etc/fstab]]. This is perfect for computers that have users without [[RootSudo]] access, like public terminals or thin clients. | ||
+ | pmount can be used with the same syntax as mount (but without sudo), or quite simply as follows: | ||
+ | <pre><nowiki> | ||
+ | pmount <device> [ label ] | ||
+ | </nowiki></pre> | ||
+ | Example: | ||
+ | <pre><nowiki> | ||
+ | pmount /dev/sdb1 flash_drive</nowiki></pre> | ||
+ | This will mount the device /dev/sdb1 at /media/flash_drive | ||
+ | If you leave off the ''label'' option, it will mount by default at /media/device | ||
+ | To unmount the device, use <code><nowiki>pumount</nowiki></code>, like so: | ||
+ | <pre><nowiki> | ||
+ | pumount <device> | ||
+ | </nowiki></pre> | ||
+ | Example: | ||
+ | <pre><nowiki> | ||
+ | pumount /dev/sdb1</nowiki></pre> | ||
+ | For more help, you can see the man pages for [[http://linux.die.net/man/1/pmount| pmount]] and [[http://linux.die.net/man/1/pumount| pumount]]. | ||
+ | == Unmounting Explained == | ||
+ | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconHint2.png%7D%7D Before disconnecting devices, you must unmount them first. This is similar to "Safely Remove" in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares. | ||
+ | '''Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system.''' There are no exceptions to this rule. Be safe - unmount your drives before disconnecting them! | ||
+ | == Other Useful Commands == | ||
+ | To see a list of your USB devices (the vendor and device ID's), run: | ||
+ | <pre><nowiki> | ||
+ | lsusb | ||
+ | </nowiki></pre> | ||
+ | To see all attached storage devices and their partitions, run: | ||
+ | <pre><nowiki> | ||
+ | sudo fdisk -l | ||
+ | </nowiki></pre> | ||
+ | To see information about currently mounted systems, simply run: | ||
+ | <pre><nowiki> | ||
+ | mount | ||
+ | </nowiki></pre> | ||
+ | == Troubleshooting == | ||
+ | Presented here are some common problems users encounter. | ||
+ | === Unclean LogFile === | ||
+ | If you are mounting drives formatted with NTFS (like most external USB hard disks are), you must first have the ntfs-3g driver installed. This is done automatically in newer versions of Ubuntu. You should also install ntfs-config and enable the mounting, which is not done automatically. For ntfs-3g and ntfs-config, see [[MountingWindowsPartitions/ThirdPartyNTFS3G]]. | ||
+ | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconFAQ.png%7D%7D When a drive is not Safely Removed from a Windows machine (or a forced shutdown occurs from Windows), you may get an error like this when you plug in your drive: | ||
+ | <pre><nowiki> | ||
+ | $LogFile indicates unclean shutdown (0, 0) | ||
+ | Failed to mount '/dev/sda1': Operation not supported | ||
+ | Mount is denied because NTFS is marked to be in use. Choose one action: | ||
− | === | + | Choice 1: If you have Windows then disconnect the external devices by |
− | * [[ | + | clicking on the 'Safely Remove Hardware' icon in the Windows |
− | + | taskbar then shutdown Windows cleanly. | |
− | + | ||
− | + | Choice 2: If you don't have Windows then you can use the 'force' option for | |
− | * [http:// | + | your own responsibility. For example type on the command line: |
+ | |||
+ | mount -t ntfs-3g /dev/sda1 /media/sda1/ -o force | ||
+ | </nowiki></pre> | ||
+ | The best option is Choice 1, but you can force the mount by running Choice 2 with sudo. Then to unmount the drive, you must do it manually from terminal (you can't right click the desktop icon): | ||
+ | <pre><nowiki> | ||
+ | sudo umount <mount_point> | ||
+ | </nowiki></pre> | ||
+ | After that the drive should automount normally again. | ||
+ | === User Privileges === | ||
+ | If your usb device doesn't appear on your desktop, you should check that your user has the correct privileges. Go to '''System->Administration->User and Groups''', choose the user, click on "Properties", then go to the "User Privileges" tab. You should have the "Access external storage devices automatically" option checked. | ||
+ | === Preferences === | ||
+ | If your usb device doesn't appear on your desktop, you should check that the automount action is enabled in the preferences: | ||
+ | * Navigate to "System" > "Preferences" > "Removable Drives and Media" | ||
+ | * Verify that all "Mount removable drives when..." are checked. | ||
+ | NOTE: This does not seem to apply to Hardy Heron. | ||
+ | === USB 2 Issues === | ||
+ | If you encounter problems using your USB device with USB 2 (i.e. 'high speed' mode), you can revert to the 'full speed' mode (slower) by unloading ehci_hcd. To do that, type in a terminal: | ||
+ | <pre><nowiki> | ||
+ | sudo rmmod ehci_hcd | ||
+ | </nowiki></pre> | ||
+ | before plugging in your device. | ||
+ | === Buffer I/O Errors === | ||
+ | If you see errors related to Buffer I/O when attaching a USB Storage device, there are two ways to work around it. First, try using varying max_sectors settings, as such: | ||
+ | <pre><nowiki> | ||
+ | sudo sh -c "echo 120 > /sys/block/sda/queue/max_sectors_kb" | ||
+ | </nowiki></pre> | ||
+ | Try values of 120, 64 and 32. | ||
+ | If this does not resolve the issue, then you may need an unusual_dev entry for your device. It would look something like this: | ||
+ | <pre><nowiki> | ||
+ | UNUSUAL_DEV(0x03eb , 0x2002, 0x0100, 0x9999, | ||
+ | "Generic", | ||
+ | "MusicDrive", | ||
+ | US_SC_DEVICE, US_PR_DEVICE, NULL, | ||
+ | US_FL_IGNORE_RESIDUE), | ||
+ | </nowiki></pre> | ||
+ | The vendor and device ID's can be obtained from the output of "lsusb". The entry would be placed in drivers/usb/storage/unusual_devs.h. If you cannot compile your own kernel, please file a bug report, and we'll attempt to compile a test module for you. | ||
+ | === Device become suddenly read only === | ||
+ | If your device changes suddenly to read only mode, and you see this kind of error: | ||
+ | <pre><nowiki> | ||
+ | [17183798.908000] FAT: Filesystem panic (dev sda1) | ||
+ | [17183798.908000] fat_get_cluster: invalid cluster chain (i_pos 0) | ||
+ | [17183798.908000] File system has been set read-only | ||
+ | </nowiki></pre> | ||
+ | This might be the sign of an unclean device. | ||
+ | You should check your device. Try [[TestingStorageMedia]] to do so. | ||
+ | === General tip === | ||
+ | When you encounter problems with USB devices, the first thing to do is to check the latest debug information generated from the kernel just after you plug in your device and/or just after you encounter the problem.<<BR>> | ||
+ | To do that, open a terminal and type : | ||
+ | <pre><nowiki> | ||
+ | dmesg | ||
+ | </nowiki></pre> | ||
+ | Check the latest messages, they should be related to your problem. | ||
+ | === Seeking Further Help === | ||
+ | The best place to get help with almost any Ubuntu problem is on the [[http://ubuntuforums.org/| Ubuntu Forums]]. The ''Absolute Beginner Talk'' section is best for beginners. | ||
+ | == Other Resources == | ||
+ | {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png%7D%7D Some other related material: | ||
+ | * [[RenameUSBDrive]] | ||
+ | * [[BootFromUSB]] | ||
+ | * [[UsbDriveDoSomethingHowto]] | ||
+ | * [[http://en.wikipedia.org/wiki/USB_flash_drive]] | ||
+ | * [[DebuggingUSBStorage]] | ||
---- | ---- | ||
− | [[category:CategoryHardware]] | + | [[category:CategoryHardware]] [[category:CategoryUsb]] |
− | [[category:CategoryUsb | + | |
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2008年10月19日 (日) 12:55的版本
![]() |
点击翻译: |
English |
请不要直接编辑翻译本页,本页将定期与来源同步。 |
This page explains how to use USB drives, like external hard disks and USB flash drives (aka USB sticks, thumb drives, pen drives, etc). The material here also applies to flash cards (like in your digital camera). {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=stop.png%7D%7D If you are looking for help with internal hard drives, see these links:
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconTip.png%7D%7D USB storage devices have the enormous advantage that for the most part they use a standard set of protocols. Thus, instead of needing individual drivers, as does much computer hardware, a standard driver permits access to the devices, making them very portable and able to easily work on many platforms.
目录
Automounting
Mounting
By default, storage devices that are plugged into the system mount automatically and place an icon on your desktop, often called "disk" and as more drives are added, you can get "disk-1" and so on. To change the automatic mount point and label of external drives, see RenameUSBDrive. To have a program automatically start when you plug in a device, go to System->Preferences->Removable Drives and Media. For more complex scenarios, see UsbDriveDoSomethingHowto.
Unmounting/Ejecting
Before you disconnect the device, don't forget to unmount it. This can be done by right clicking the desktop icon and selecting "Unmount" (or in some cases, "Eject").
Automounting (Ubuntu Server)
By default, disk drives do not automount in Ubuntu Server Edition. If you are looking for a lightweight solution that does not depend on HAL/DBUS, you can install "usbmount".
Manually Mounting
Using mount
Get the Information
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconGNOMETerminal.png%7D%7D Sometimes devices don't automount, in which case you should try to manually mount it. First, you must know what device we are dealing with and what filesystem it is formatted with. Most flash drives are FAT16 or FAT32 and most external hard disks are NTFS.
sudo fdisk -l
Find your device in the list, it is probably something like /dev/sdb1. For more information about filesystems, see LinuxFilesystemsExplained.
Create the Mount Point
Now we need to create a mount point for the device, let's say we want to call it "external". You can call it whatever you want, just please don't use spaces in the name or it gets a little more complicated - use an underscore to separate words (like "my_external"). Create the mount point:
sudo mkdir /media/external
Mount the Drive
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D We can now mount the drive. Let's say the device is /dev/sdb1, the filesystem is FAT16 or FAT32 (like it is for most USB flash drives), and we want to mount it at /media/external (having already created the mount point):
sudo mount -t vfat /dev/sdb1 /media/external -o uid=1000,gid=100,utf8,dmask=027,fmask=137
The options following the "-o" allow your user to have ownership of the drive, and the masks allow for extra security for file system permissions. If you don't use those extra options you may not be able to read and write the drive with your regular username. Otherwise if the device is formatted with NTFS, run:
sudo mount -t ntfs-3g /dev/sdb1 /media/external
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconNote.png%7D%7D You must have the ntfs-3g driver installed. See MountingWindowsPartitions/ThirdPartyNTFS3G for more information.
Unmounting the Drive
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=example.png%7D%7D When you are finished with the device, don't forget to unmount the drive before disconnecting it. Assuming /dev/sdb1 mounted at /media/external, you can either unmount using the device or the mount point:
sudo umount /dev/sdb1
or:
sudo umount /media/external
You cannot unmount from the desktop by right clicking the icon if the drive was manually mounted.
Using pmount
There is a program called pmount
available in the repositories which allows unprivileged users to mount drives as if they were using sudo, even without an entry in /etc/fstab. This is perfect for computers that have users without RootSudo access, like public terminals or thin clients.
pmount can be used with the same syntax as mount (but without sudo), or quite simply as follows:
pmount <device> [ label ]
Example:
pmount /dev/sdb1 flash_drive
This will mount the device /dev/sdb1 at /media/flash_drive
If you leave off the label option, it will mount by default at /media/device
To unmount the device, use pumount
, like so:
pumount <device>
Example:
pumount /dev/sdb1
For more help, you can see the man pages for [pmount] and [pumount].
Unmounting Explained
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconHint2.png%7D%7D Before disconnecting devices, you must unmount them first. This is similar to "Safely Remove" in Windows in that the device won't unmount until data is finished being written to the device, or until other programs are finished using it. This applies to all types of storage devices, including flash drives, flash cards, external hard drives, ipods and other media players, and even remote storage like Samba or NFS shares. Failure to unmount before disconnecting the device can result in loss of data and/or a corrupted file system. There are no exceptions to this rule. Be safe - unmount your drives before disconnecting them!
Other Useful Commands
To see a list of your USB devices (the vendor and device ID's), run:
lsusb
To see all attached storage devices and their partitions, run:
sudo fdisk -l
To see information about currently mounted systems, simply run:
mount
Troubleshooting
Presented here are some common problems users encounter.
Unclean LogFile
If you are mounting drives formatted with NTFS (like most external USB hard disks are), you must first have the ntfs-3g driver installed. This is done automatically in newer versions of Ubuntu. You should also install ntfs-config and enable the mounting, which is not done automatically. For ntfs-3g and ntfs-config, see MountingWindowsPartitions/ThirdPartyNTFS3G. {{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconFAQ.png%7D%7D When a drive is not Safely Removed from a Windows machine (or a forced shutdown occurs from Windows), you may get an error like this when you plug in your drive:
$LogFile indicates unclean shutdown (0, 0) Failed to mount '/dev/sda1': Operation not supported Mount is denied because NTFS is marked to be in use. Choose one action: Choice 1: If you have Windows then disconnect the external devices by clicking on the 'Safely Remove Hardware' icon in the Windows taskbar then shutdown Windows cleanly. Choice 2: If you don't have Windows then you can use the 'force' option for your own responsibility. For example type on the command line: mount -t ntfs-3g /dev/sda1 /media/sda1/ -o force
The best option is Choice 1, but you can force the mount by running Choice 2 with sudo. Then to unmount the drive, you must do it manually from terminal (you can't right click the desktop icon):
sudo umount <mount_point>
After that the drive should automount normally again.
User Privileges
If your usb device doesn't appear on your desktop, you should check that your user has the correct privileges. Go to System->Administration->User and Groups, choose the user, click on "Properties", then go to the "User Privileges" tab. You should have the "Access external storage devices automatically" option checked.
Preferences
If your usb device doesn't appear on your desktop, you should check that the automount action is enabled in the preferences:
- Navigate to "System" > "Preferences" > "Removable Drives and Media"
- Verify that all "Mount removable drives when..." are checked.
NOTE: This does not seem to apply to Hardy Heron.
USB 2 Issues
If you encounter problems using your USB device with USB 2 (i.e. 'high speed' mode), you can revert to the 'full speed' mode (slower) by unloading ehci_hcd. To do that, type in a terminal:
sudo rmmod ehci_hcd
before plugging in your device.
Buffer I/O Errors
If you see errors related to Buffer I/O when attaching a USB Storage device, there are two ways to work around it. First, try using varying max_sectors settings, as such:
sudo sh -c "echo 120 > /sys/block/sda/queue/max_sectors_kb"
Try values of 120, 64 and 32. If this does not resolve the issue, then you may need an unusual_dev entry for your device. It would look something like this:
UNUSUAL_DEV(0x03eb , 0x2002, 0x0100, 0x9999, "Generic", "MusicDrive", US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_IGNORE_RESIDUE),
The vendor and device ID's can be obtained from the output of "lsusb". The entry would be placed in drivers/usb/storage/unusual_devs.h. If you cannot compile your own kernel, please file a bug report, and we'll attempt to compile a test module for you.
Device become suddenly read only
If your device changes suddenly to read only mode, and you see this kind of error:
[17183798.908000] FAT: Filesystem panic (dev sda1) [17183798.908000] fat_get_cluster: invalid cluster chain (i_pos 0) [17183798.908000] File system has been set read-only
This might be the sign of an unclean device. You should check your device. Try TestingStorageMedia to do so.
General tip
When you encounter problems with USB devices, the first thing to do is to check the latest debug information generated from the kernel just after you plug in your device and/or just after you encounter the problem.<
>
To do that, open a terminal and type :
dmesg
Check the latest messages, they should be related to your problem.
Seeking Further Help
The best place to get help with almost any Ubuntu problem is on the [Ubuntu Forums]. The Absolute Beginner Talk section is best for beginners.
Other Resources
{{https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=IconBook-small.png%7D%7D Some other related material: