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"

−

−

=== Auto-mounting with udev and systemd ===

−

−

The above solution does not work, since the processes started by udev scripts will be killed shortly after starting.

−

Instead, the following solution based on the previous one uses [[systemd]], [[udev]] and [[screen]] to create a more elegant solution.

−

−

First, we create a systemd service template ({{ic|/etc/systemd/system/automount@.service}}):

−

{{bc|<nowiki>

−

[Unit]

−

Description=Automount removable storage

−

−

[Service]

−

Type=forking

−

ExecStart=/usr/lib/udev/domount %I

−

</nowiki>}}

−

−

We also create a udev rule in {{ic|/etc/udev/rules.d/automount.rules}} very similar to the previous solution.

To access the screen session which controls the mounted partitions, simply run

−

$ screen -d -r AUTOMOUNT

−

I would suggest putting this in a command key shortcut, for example with [[xbindkeys]] to run in a terminal.

−

−

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

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

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

Line 22:

# modprobe sd_mod (only for non SCSI kernels)

# modprobe sd_mod (only for non SCSI kernels)

−

==== Identifying device ====

+

{{Tip|In case of manually loading modules, you may also need to load the {{ic|sg}} module (SCSI generic driver).}}

−

−

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:

+

=== Identifying device ===

−

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

+

First thing one need to access storage device is it's identifier assigned by kernel. See [[fstab#Identifying filesystems]] for details.

−

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

+

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

−

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

+

=== Mounting USB memory ===

−

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

+

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

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

Tip: In case of manually loading modules, you may also need to load the sg module (SCSI generic driver).

Mounting USB memory

Notes: 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. (Discuss in Talk:USB storage devices#)

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.

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

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