Difference between revisions of "USB storage devices"

From ArchWiki
Jump to: navigation, search
m (Maximizing performance: request merging with Maximizing Performance)
m (Corrected some grammatical errors)
 
(26 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 
[[Category:Storage]]
 
[[Category:Storage]]
[[es:USB Storage Devices]]
+
[[es:USB storage devices]]
[[it:USB Storage Devices]]
+
[[fr:Périphérique de stockage USB]]
[[ru:USB Storage Devices]]
+
[[it:USB storage devices]]
 +
[[ja:USB ストレージデバイス]]
 +
[[ru:USB storage devices]]
 +
{{Related articles start}}
 +
{{Related|Mount}}
 +
{{Related articles end}}
 +
 
 
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 device.
 
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 device.
  
Line 9: Line 15:
 
== Auto-mounting with udisks ==
 
== Auto-mounting with udisks ==
  
This is the easiest and most frequently used method. It is used by many [[Desktop environment|desktop environments]], but can be used separately too. See [[Udisks]] for details.
+
This is the easiest and most frequently used method. It is used by many [[desktop environments]], but can be used separately too. See [[Udisks]] for details.
  
 
== Manual mounting ==
 
== Manual mounting ==
Line 17: Line 23:
 
=== Getting a kernel that supports usb_storage ===
 
=== 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.
 
+
# modprobe usb-storage
+
# modprobe sd_mod      (only for non SCSI kernels)
+
 
+
{{Tip|In case of manually loading modules, you may also need to load the {{ic|sg}} module (SCSI generic driver).}}
+
  
 
=== Identifying device ===
 
=== Identifying device ===
  
First thing one need to access storage device is it's identifier assigned by kernel. See [[fstab#Identifying filesystems]] for details.
+
The first thing one needs to access a storage device is its identifier assigned by kernel. See [[fstab#Identifying filesystems]] for details.
  
 
{{Tip|To see which device is your USB device, you can compare the output of {{ic|lsblk -f}} (explained in the linked article) when the USB device is connected and when it is unconnected.}}
 
{{Tip|To see which device is your USB device, you can compare the output of {{ic|lsblk -f}} (explained in the linked article) when the USB device is connected and when it is unconnected.}}
Line 32: Line 33:
 
=== Mounting USB memory ===
 
=== Mounting USB memory ===
  
{{Merge|fstab#Writing to FAT32 as Normal User|This section assumes that the partition on USB storage uses FAT32 or NTFS filesystem, so we have two sections covering the same topic. Either merge everything here or in the linked section.}}
+
You need to create the directory in which you are going to mount the device:
  
You need to create the directory in which you are going to mount the device:
 
 
  # mkdir /mnt/usbstick
 
  # mkdir /mnt/usbstick
  
Line 40: Line 40:
  
 
Mount the device as root with this command (do not forget to replace '''device_node''' by the path you found):
 
Mount the device as root with this command (do not forget to replace '''device_node''' by the path you found):
 +
 
  # mount '''device_node''' /mnt/usbstick
 
  # mount '''device_node''' /mnt/usbstick
 +
 
or
 
or
 +
 
  # mount -U '''UUID''' /mnt/usbstick
 
  # mount -U '''UUID''' /mnt/usbstick
  
 
If {{ic|mount}} does not recognize the format of the device you can try to use the {{ic|-t}} argument, see {{ic|man mount}} for details.
 
If {{ic|mount}} does not recognize the format of the device you can try to use the {{ic|-t}} argument, see {{ic|man mount}} for details.
  
{{Note|If mounting your stick does not work you can try to repartition it, see [[Format a device]].}}
+
{{Note|
 +
* If mounting your stick does not work you can try to repartition it, see [[Format a device]].
 +
* See [https://gist.github.com/anonymous/a69093a51f83b53d9fc5] for example mount/unmount scripts using [[sudo]].
 +
}}
  
 
==== As normal user with mount ====
 
==== As normal user with mount ====
Line 56: Line 62:
 
==== As normal user with fstab ====
 
==== As normal user with fstab ====
  
If you want non-root users to be able to mount a USB memory stick via [[fstab]], add the following line to your {{ic|/etc/fstab}} file:
+
See [[Fstab#Writing to FAT32 as Normal User]] if you want normal user to do the mount/unmount action.
/dev/sda1 /mnt/usbstick vfat '''user''',noauto,noatime,flush 0 0
+
or better:
+
UUID=E8F1-5438 /mnt/usbstick vfat '''user''',noauto,noatime,flush 0 0
+
(see description of '''user''' and other options in the [[Fstab|main article]])
+
 
+
{{Note|Where {{ic|/dev/sda1}} is replaced with the path to your own usbstick, see [[USB_Storage_Devices#Mounting_USB_memory|Mounting USB memory]].}}
+
 
+
Now, any user can mount it with:
+
$ mount /mnt/usbstick
+
 
+
And unmount it with:
+
$ umount /mnt/usbstick
+
 
+
=== Maximizing performance ===
+
 
+
{{Merge|Maximizing Performance#Storage devices}}
+
 
+
You can try with other scheduler than CFQ like in [[SSD#Using_udev_for_one_device_or_HDD.2FSSD_mixed_environment|SSD#I/O Scheduler]] for a flash drive but its posible than your USB Storage Device where detected as rotational. Another posibility is the use of removable attribute.
+
 
+
== Unmounting devices mounted with udev or systemd/udev ==
+
 
+
Create an executable file (e.g. {{ic|/usr/local/bin/unmount.sh}}):
+
{{bc|<nowiki>
+
#!/bin/sh
+
 
+
# Global variables
+
TITLE="Unmount Utility"
+
COLUMNS=3 # TARGET,SOURCE,FSTYPE
+
#IFS=$'\n'
+
 
+
# Populate list of unmountable devices
+
deviceList=($(findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]"))
+
deviceCount=$((${#deviceList[@]} / $COLUMNS))
+
 
+
# Start of program output
+
echo $TITLE
+
 
+
# Display list of devices that can be unmounted
+
for ((device=0; device<${#deviceList[@]}; device+=COLUMNS))
+
do
+
  printf "%4s)  %-25s%-13s%-10s\n"\
+
    "$(($device / $COLUMNS))"\
+
    "${deviceList[$device]}"\
+
    "${deviceList[$(($device + 1))]}"\
+
    "${deviceList[$(($device + 2))]}"
+
done
+
 
+
printf "%4s)  Exit\n" "x"
+
 
+
# Get input from user
+
read -p "Choose a menu option: " input
+
 
+
# Input validation
+
if [ "$input" = "X" ] || [ "$input" = "x" ]
+
then
+
  echo "Exiting"
+
  exit 0
+
fi
+
 
+
if (( $input>=0 )) && (( $input<$deviceCount ))
+
then
+
  echo "Unmounting: ${deviceList[$(($input * $deviceCount))]}"
+
  sudo umount "${deviceList[$(($input * $deviceCount))]}"
+
  exit 0
+
else
+
  echo "Invalid menu choice"
+
  exit 1
+
fi
+
</nowiki>}}
+
 
+
{{Note|This script requires that you have sudo installed and that you have sudo rights.}}
+
 
+
== Troubleshooting ==
+
 
+
=== Poor copy performance to USB pendrive  ===
+
 
+
{{Merge|Maximizing Performance}}
+
 
+
{{Expansion|provide better description, or at least some reference}}
+
 
+
If you experienced slow copy speed to pendrive (mainly in KDE), then append these three lines in a [[systemd]] tmpfile:
+
 
+
{{hc|/etc/tmpfiles.d/local.conf|
+
w /sys/kernel/mm/transparent_hugepage/enabled - - - - madvise
+
w /sys/kernel/mm/transparent_hugepage/defrag - - - - madvise
+
w /sys/kernel/mm/transparent_hugepage/khugepaged/defrag - - - - 0
+
}}
+
 
+
See also [[Maximizing Performance#Tuning kernel parameters]].
+

Latest revision as of 19:52, 24 July 2016

Related articles

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 device.

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

Auto-mounting with udisks

This is the easiest and most frequently used method. It is used by many desktop environments, but can be used separately too. See Udisks for details.

Manual mounting

Note: Before you decide that Arch Linux does not mount your USB device, be sure to check all available ports. Some ports might not share the same controller, preventing you from mounting the device.

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.

Identifying device

The first thing one needs to access a storage device is its identifier assigned by kernel. See fstab#Identifying filesystems for details.

Tip: To see which device is your USB device, you can compare the output of lsblk -f (explained in the linked article) when the USB device is connected and when it is unconnected.

Mounting USB memory

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

# mkdir /mnt/usbstick

As root

Mount the device as root with this command (do not forget to replace device_node by the path you found):

# mount device_node /mnt/usbstick

or

# mount -U UUID /mnt/usbstick

If mount does not recognize the format of the device you can try to use the -t argument, see man mount for details.

Note:
  • If mounting your stick does not work you can try to repartition it, see Format a device.
  • See [1] for example mount/unmount scripts using sudo.

As normal user with mount

If you want non-root users to be able to write to the USB stick, you can issue the following command:

# mount -o gid=users,fmask=113,dmask=002 /dev/sda1 /mnt/usbstick

As normal user with fstab

See Fstab#Writing to FAT32 as Normal User if you want normal user to do the mount/unmount action.