Difference between revisions of "USB storage devices"

From ArchWiki
Jump to: navigation, search
m
(reorganized, updated, added a link to Udev#Auto mounting USB devices)
Line 7: Line 7:
 
{{i18n_links_end}}
 
{{i18n_links_end}}
  
 +
==Introduction==
 
This document describes how to use the popular USB memory sticks with Linux. However, it is also valid for other devices such as digital cameras that act as if they were just a USB storage.
 
This document describes how to use the popular USB memory sticks with Linux. However, it is also valid for other devices such as digital cameras that act as if they were just a USB storage.
  
==Getting a kernel that supports usb_storage==
+
If you have an up-to-date system with the standard Arch kernel, [[udev]] and a modern [[Desktop Environment]] your device should just show up on your desktop, no need to open a console.
 +
 
 +
Otherwise see [[#Manual mounting]] below.
 +
 
 +
==Auto-mounting of USB devices==
 +
See [[Udev#Auto mounting USB devices]].
 +
 
 +
==Manual mounting==
 +
===Getting a kernel that supports usb_storage===
  
 
If you do not use a custom-made kernel, you are ready to go, for all Arch Linux stock kernels are properly configured. If you do use a custom-made kernel, ensure it is compiled with SCSI-Support, SCSI-Disk-Support and usb_storage. If you use the latest [[udev]], you may just plug your device in and the system will automatically load all necessary kernel modules. Older releases of udev would need hotplug installed too. Otherwise, you can do the same thing manually:
 
If you do not use a custom-made kernel, you are ready to go, for all Arch Linux stock kernels are properly configured. If you do use a custom-made kernel, ensure it is compiled with SCSI-Support, SCSI-Disk-Support and usb_storage. If you use the latest [[udev]], you may just plug your device in and the system will automatically load all necessary kernel modules. Older releases of udev would need hotplug installed too. Otherwise, you can do the same thing manually:
Line 16: Line 25:
 
  # modprobe sd_mod      (only for non SCSI kernels)
 
  # modprobe sd_mod      (only for non SCSI kernels)
  
==Mounting USB memory==
+
===Mounting USB memory===
 
+
After inserting the stick you can mount the device as root with
+
# mount -t vfat /dev/sda1 /mnt/usbstick
+
 
+
'''Note:''' /dev/sda1 is variable. If your hard drive is assigned to /dev/sda1, you'll probably use /dev/sdb1 instead. To find out for sure where your USB device is, search dmesg for /dev/sd*. Use lsusb to verify that your USB device is indeed recognized by the system, if there is an error.
+
 
+
The <code>-t</code> flag specifies the filesystem type. If the device is formatted as fat32 then use the vfat parameter. By default an <tt>sdx</tt> device is assumed to be formated as fat32, so this option may be omitted.
+
 
+
Note: the directory you mount the stick into must exist before you issue the mount command.
+
 
+
If you use [[KDE]] or [[GNOME]], they should show you the inserted device right on your desktop so you don't need to mount it manually.
+
 
+
'''Note:''' If you get an error message "Error org.freedesktop.DBus.Error.AccessDenied.", try adding your user account to the 'storage' group.
+
 
+
==Repartitioning the USB memory==
+
 
+
Sometimes the stick is separated in up to four partitions, and Linux can't read anything. To fix this you have to repartition the stick with <code>fdisk</code>. Make sure that there are no files left on the stick (if you used it before in Windows, Mac OS or anywhere else).
+
  
Type:
+
In order to mount the device you need to know the path to the device node, there are at least two ways of finding out:
# modprobe usb_storage
+
*if the partition you want to mount has a label search in {{Filename|/dev/disk/by-label}}
# fdisk /dev/sda
+
*search in the output of {{Codeline|dmesg}} for the kernel device name, you can use {{Codeline|grep}} to help you find what you are looking for: {{Codeline|<nowiki>dmesg | grep -e "sd[a-z]"</nowiki>}}
 +
{{Note|If you can't find your device you can use lsusb to verify that it is indeed recognized by the system.}}
  
Delete all available partitions (''d'' and partition number), create a new partition with ''n'' (I would suggest you use a single partition), press ''w'' to write everything and quit.
+
You also need to create the directory in which you are going to mount the device:
 +
# mkdir /mnt/usbstick
  
Create a filesystem on the stick:
+
Finally you can mount the device as root with this command (don't forget to replace '''device_node''' by the path you found):
  # mkfs.vfat /dev/sda1
+
  # mount '''device_node''' /mnt/usbstick
  
If you do not have mkfs.vfat on your system then use pacman to install dosfstools:
+
If {{Codeline|mount}} does not recognized the format of the device you can try to use the {{Codeline|-t}} argument, see {{Codeline|man mount}} for details.
# pacman -Sy dosfstools
+
  
Now you can mount or unmount it as mentioned above.
+
{{Note|If mounting your stick doesn't work you can try to repartition it, see [[Format a device]].}}
  
==Mounting the USB stick as normal user==
+
===Mounting the USB stick as normal user===
  
 
If you want non-root users to be able to mount a USB memory stick, add the following line to your /etc/fstab file:
 
If you want non-root users to be able to mount a USB memory stick, add the following line to your /etc/fstab file:

Revision as of 13:34, 31 October 2009

Template:I18n links start Template:I18n entry Template:I18n entry Template:I18n entry Template:I18n links end

Introduction

This document describes how to use the popular USB memory sticks with Linux. However, it is also valid for other devices such as digital cameras that act as if they were just a USB storage.

If you have an up-to-date system with the standard Arch kernel, udev and a modern Desktop Environment your device should just show up on your desktop, no need to open a console.

Otherwise see #Manual mounting below.

Auto-mounting of USB devices

See Udev#Auto mounting USB devices.

Manual mounting

Getting a kernel that supports usb_storage

If you do not use a custom-made kernel, you are ready to go, for all Arch Linux stock kernels are properly configured. If you do use a custom-made kernel, ensure it is compiled with SCSI-Support, SCSI-Disk-Support and usb_storage. If you use the latest udev, you may just plug your device in and the system will automatically load all necessary kernel modules. Older releases of udev would need hotplug installed too. Otherwise, you can do the same thing manually:

# modprobe usb-storage
# modprobe sd_mod      (only for non SCSI kernels)

Mounting USB memory

In order to mount the device you need to know the path to the device node, there are at least two ways of finding out:

Note: If you can't find your device you can use lsusb to verify that it is indeed recognized by the system.

You also need to create the directory in which you are going to mount the device:

# mkdir /mnt/usbstick

Finally you can mount the device as root with this command (don't forget to replace device_node by the path you found):

# mount device_node /mnt/usbstick

If Template:Codeline does not recognized the format of the device you can try to use the Template:Codeline argument, see Template:Codeline for details.

Note: If mounting your stick doesn't work you can try to repartition it, see Format a device.

Mounting the USB stick as normal user

If you want non-root users to be able to mount a USB memory stick, add the following line to your /etc/fstab file:

/dev/sda1 /mnt/usbstick vfat rw,noauto,async,user 0 0

Now, any user can mount it with:

$ mount /mnt/usbstick

And unmount it with:

$ umount /mnt/usbstick