{{Note|Before you decide that your Arch Linux doesn't mount your USB device, be sure to check all available ports. Since some might not share the same controller, and will then not be able to mount the device.}}

+

A lightweight solution to automount drives using udev, '''for single-user systems''', is the following: create a file named {{ic|/etc/udev/rules.d/automount.rules}} with the following content:

and a file (executable by root) named {{ic|/usr/lib/udev/domount}} with (set the variables on top to the correct values):

+

+

{{bc|<nowiki>

+

#!/bin/sh

+

+

#edit the following variables to suit your needs

+

MYUID=1000 # your user uid

+

MYGID=100 # your user gid

+

MYLOGIN=al # your login

+

TERM=lxterminal # your terminal emulator

+

MYSHELL=zsh # your shell

+

export DISPLAY=:0 # your X display

+

+

+

TMPFILE=/run/automount.$RANDOM

+

DIR=$(grep -v '#' /etc/fstab | grep $* | awk '{print $2;}')

+

if [ -z "$DIR" ]; then

+

LABEL=$(lsblk -no LABEL $*)

+

if [ -z "$LABEL" ]; then

+

UUID=$(lsblk -no UUID $*)

+

if [ -z "$UUID" ]; then

+

DIR=/run/media/"unknown"

+

else

+

DIR=/run/media/"$UUID"

+

fi

+

else

+

DIR=/run/media/"$LABEL

+

fi

+

fi

+

mkdir -p $DIR

+

+

cat > $TMPFILE << EOF

+

#!/bin/sh

+

echo "$* was mounted on $DIR. "

+

cd $DIR

+

$MYSHELL

+

EOF

+

chmod a+x $TMPFILE

+

+

/bin/mount -o uid=$MYUID,gid=$MYGID $* $DIR

+

su $MYLOGIN -c "$TERM -t 'Terminal - $* mounted on $DIR' -e $TMPFILE"

+

/bin/umount $DIR

+

+

sleep 1; rm -f $TMPFILE

+

</nowiki>}}

+

+

When a drive is inserted, it will be mounted, and a Terminal will pop-up. To umount the device, simply press Control+D in the terminal window. The mountpoint is looked for in {{ic|/etc/fstab}} or, if absent, generated from the label of the partition.

+

+

If the terminal doesn't appear as expected, that may because wrong options are used. For example, in XFCE4, we use "Terminal -T ''title'' -e ''script-file'' instead"

+

+

=== 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. 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 23:

Line 87:

# modprobe sd_mod (only for non SCSI kernels)

# modprobe sd_mod (only for non SCSI kernels)

−

===Mounting USB memory===

+

==== Identifying device ====

−

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:

+

First thing one need to access storage device is it's identifier assigned by kernel.

−

*if the partition you want to mount has a label search in {{Filename|/dev/disk/by-label}}

+

−

*look in {{Filename|/dev/disk/by-id/}} for devices starting with usb, the usable partitions will end with -part#

+

−

*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.}}

+

−

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

+

===== Using device node names ( /sd* ) =====

+

+

This is the simplest way, but assigned name depends on order of insertion. Ways to get node name:

+

+

* search in the output of {{ic|dmesg}} for the kernel device name, you can use {{ic|grep}} to help you find what you are looking for:

+

$ dmesg | grep -E "sd[a-z]"

+

* List all available partition tables:

+

# fdisk -l

+

+

{{Note|If you cannot find your device you can use lsusb to verify that it is indeed recognized by the system.}}

+

+

===== Using UUID =====

+

+

Every drive creates a [[Wikipedia:UUID|UUID]] (Universally Unique Identifier), these identifiers can be used to track individual drive no matter their device node (i.e. {{ic|/dev/sda}}).

At this point you should see a list of your system drives and a long strings of characters. These long strings are the UUIDs.

+

+

* Now connect your USB device and wait for a few seconds . . .

+

+

* Reexecute {{ic|blkid -o list -c /dev/null}}

+

Notice a new device and UUID? That is your USB storage.

+

+

{{Tip|If {{ic|blkid}} does not work as expected, You can look for the UUIDs in {{ic|/dev/disk/by-uuid/}}:

+

$ ls -lF /dev/disk/by-uuid/

+

}}

+

+

==== Mounting USB memory ====

+

+

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

# mkdir /mnt/usbstick

# 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):

+

===== 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

# mount '''device_node''' /mnt/usbstick

+

or

+

# mount -U '''UUID''' /mnt/usbstick

−

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.

+

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 doesn't 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]].}}

−

===Mounting the USB stick as normal user with mount ===

+

===== 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:

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

−

sudo mount -o rw,noauto,async,user,umask=1000 /dev/sda1 /mnt/usbstick

+

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

−

===Mounting the USB stick 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 {{Filename|/etc/fstab}} file:

+

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:

−

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

+

/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 '''/dev/sda1''' is replaced with the path to your own usbstick, see [[USB_Storage_Devices#Mounting_USB_memory|Mounting USB memory]].}}

+

{{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:

Now, any user can mount it with:

Line 60:

Line 189:

$ umount /mnt/usbstick

$ umount /mnt/usbstick

−

===Mounting the USB stick with flush option===

+

===== Poor copy performance to USB pendrive =====

−

+

−

The '''flush''' option for mounting vfat has been added since kernel 2.6.19 as a replacement to '''async'''. It basically makes data to flush more often, thus making copy dialogs or progress bars to stays up until things are on the disk. [http://forums.gentoo.org/viewtopic-t-537871.html]

+

−

/dev/sda1 /mnt/usbstick vfat rw,noauto,'''flush''',user 0 0

+

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

+

}}

+

And paste these at the end of your {{ic|/etc/sysctl.conf}}:

+

kernel.shmmax=134217728

+

vm.dirty_background_bytes = 4194304

+

vm.dirty_bytes = 4194304

+

Reboot. This also reduces the freezes of the KDE's panel.

Revision as of 20:54, 8 June 2013

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.

When a drive is inserted, it will be mounted, and a Terminal will pop-up. To umount the device, simply press Control+D in the terminal window. The mountpoint is looked for in /etc/fstab or, if absent, generated from the label of the partition.

If the terminal doesn't appear as expected, that may because wrong options are used. For example, in XFCE4, we use "Terminal -T title -e script-file instead"

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

Identifying device

First thing one need to access storage device is it's identifier assigned by kernel.

Using device node names ( /sd* )

This is the simplest way, but assigned name depends on order of insertion. Ways to get node name:

search in the output of dmesg for the kernel device name, you can use grep to help you find what you are looking for:

$ dmesg | grep -E "sd[a-z]"

List all available partition tables:

# fdisk -l

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

Using UUID

Every drive creates a UUID (Universally Unique Identifier), these identifiers can be used to track individual drive no matter their device node (i.e. /dev/sda).