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=`cat /etc/fstab | grep -v '#' | grep $* | awk '{print $2;}'`

+

if [ "x$DIR" = "x" ]; then

+

MYUUID=`blkid -o value -s UUID $*`

+

if [ "x$MYUUID" = "x" ]; then

+

MYUUID="unknown"

+

fi

+

DIR=/run/media/$MYUUID

+

fi

+

mkdir -p /run/media

+

mkdir -p $DIR

+

cat > $TMPFILE << EOF

+

#!/bin/sh

+

echo "$* will be mounted on $DIR. "

+

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

+

cd $DIR

+

$MYSHELL

+

cd

+

sudo /bin/umount $DIR

+

EOF

+

chmod a+x $TMPFILE

+

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

+

sleep 1; rm -f $TMPFILE

+

</nowiki>}}

+

+

When an harddrive 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 UUID of the partition.

+

+

To prevent your password to be asked at umount, add (replace {{Ic|you}} with your login name) to {{Ic|/etc/sudoers}} using the {{ic|visudo}} command. See [[Sudo#Configuration]]

+

+

{{bc|<nowiki>you ALL=(ALL) NOPASSWD: /bin/umount</nowiki>}}

+

+

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

=== Manual mounting ===

−

{{Note|Before you decide that your Arch Linux does not 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.}}

+

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

==== Getting a kernel that supports usb_storage ====

Line 29:

Line 78:

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

* 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 | egrep "sd[a-z]"

+

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

* running

* running

# fdisk -l

# fdisk -l

Line 39:

Line 88:

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

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

−

To find the current UUIDs execute:

+

To find the current UUIDs execute (as root):

{{hc|# blkid -o list -c /dev/null|<nowiki>

{{hc|# blkid -o list -c /dev/null|<nowiki>

device fs_type label mount point UUID

device fs_type label mount point UUID

Line 56:

Line 105:

/dev/sdj2 swap <swap> 20826c74-eb6d-46f8-84d8-69b933a4bf3f

/dev/sdj2 swap <swap> 20826c74-eb6d-46f8-84d8-69b933a4bf3f

</nowiki>}}

</nowiki>}}

+

+

Or to find this information with non-root privileges, use:

+

{{hc|$ lsblk -o name,kname,uuid|<nowiki>

+

NAME KNAME UUID

+

sda sda

+

├─sda1 sda1 A103-2001

+

└─sda2 sda2 6i2E71-zJzL-KXuG-juYv-mbNY-kROA-XsIPlm

+

├─vg0-var (dm-0) dm-0 cebi84r5-0401-491e-a0d6-de0j3bnw867c

+

├─vg0-home (dm-1) dm-1 cceguid6-f3mc-4d7a-a1f2-83f2mkpds3q1

+

└─vg0-root (dm-2) dm-2 973ed4rf-6611-47ed-877c-b66yhn5tgbc7

+

sdb sdb

+

└─sdb1 sdb1 j1Pr1X-b0uM-bkWZ-KNYQ-gezL-YliV-ScRufFyD

+

└─vg0-home (dm-1) dm-1 cefmkbe6-f4n8-4d7a-al32-83f259ijn6t7

+

sr0 sr0

+

</nowiki>}}

+

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

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

Line 80:

Line 145:

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

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

−

If {{Ic|mount}} does not recognized 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]].}}

Revision as of 19:37, 4 February 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 an harddrive 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 UUID of the partition.

To prevent your password to be asked at umount, add (replace you with your login name) to /etc/sudoers using the visudo command. See Sudo#Configuration

you ALL=(ALL) NOPASSWD: /bin/umount

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]"

running

# fdisk -l

lists all available partition tables.

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 (ie /dev/sda).