https://wiki.archlinux.org/api.php?action=feedcontributions&user=Ffhaddad&feedformat=atomArchWiki - User contributions [en]2024-03-29T12:38:15ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=USB_storage_devices&diff=275961USB storage devices2013-09-18T15:36:54Z<p>Ffhaddad: Shortened title to be more consistent with other titles.</p>
<hr />
<div>[[Category:Storage]]<br />
[[es:USB Storage Devices]]<br />
[[it:USB Storage Devices]]<br />
[[ru:USB Storage Devices]]<br />
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.<br />
<br />
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.<br />
<br />
== Auto-mounting with udisks ==<br />
<br />
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.<br />
<br />
== Auto-mounting with udev ==<br />
<br />
{{Deletion|Conflicts with [[Udev#Udisks]] (first sentence). See [[Talk:USB Storage Devices#Auto-mounting with udev]] for details.|Talk:USB Storage Devices#Auto-mounting with udev}}<br />
<br />
See [[Udev#Auto mounting USB devices|Udev:Auto mounting USB devices]].<br />
<br />
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: <br />
{{bc|<nowiki><br />
# ignore sda*<br />
KERNEL!="sd[b-z]*", GOTO="end"<br />
<br />
# run the script<br />
ACTION=="add", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="partition", RUN+="domount %N"<br />
<br />
# exit<br />
LABEL="end"<br />
</nowiki>}}<br />
and a file (executable by root) named {{ic|/usr/lib/udev/domount}} with (set the variables on top to the correct values):<br />
<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
#edit the following variables to suit your needs<br />
MYUID=1000 # your user uid<br />
MYGID=100 # your user gid<br />
MYLOGIN=al # your login<br />
TERM=lxterminal # your terminal emulator<br />
MYSHELL=zsh # your shell<br />
export DISPLAY=:0 # your X display<br />
<br />
<br />
TMPFILE=/run/automount.$RANDOM<br />
DIR=$(grep -v '#' /etc/fstab | grep $* | awk '{print $2;}')<br />
if [ -z "$DIR" ]; then<br />
LABEL=$(lsblk -no LABEL $*)<br />
if [ -z "$LABEL" ]; then<br />
UUID=$(lsblk -no UUID $*)<br />
if [ -z "$UUID" ]; then<br />
DIR=/run/media/"unknown"<br />
else<br />
DIR=/run/media/"$UUID"<br />
fi<br />
else<br />
DIR=/run/media/"$LABEL"<br />
fi<br />
fi<br />
mkdir -p $DIR<br />
<br />
cat > $TMPFILE << EOF<br />
#!/bin/sh<br />
echo "$* was mounted on $DIR. "<br />
cd $DIR<br />
$MYSHELL<br />
EOF<br />
chmod a+x $TMPFILE<br />
<br />
/bin/mount -o uid=$MYUID,gid=$MYGID $* $DIR<br />
su $MYLOGIN -c "$TERM -t 'Terminal - $* mounted on $DIR' -e $TMPFILE"<br />
/bin/umount $DIR<br />
<br />
sleep 1; rm -f $TMPFILE<br />
</nowiki>}}<br />
<br />
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. <br />
<br />
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"<br />
<br />
== Auto-mounting with udev and systemd ==<br />
<br />
{{Deletion|Conflicts with [[Udev#Udisks]] (first sentence). See [[Talk:USB Storage Devices#Auto-mounting with udev]] for details.|Talk:USB Storage Devices#Auto-mounting with udev}}<br />
<br />
The above solution does not work, since the RUN directive is for only short processes, and udev enforces this; Scripts will be killed shortly after starting.<br />
Instead, the following solution based on the previous one uses [[systemd]], [[udev]] and [[screen]] to create a more elegant solution.<br />
<br />
First, we create a systemd service template ({{ic|/etc/systemd/system/automount@.service}}):<br />
{{bc|<nowiki><br />
[Unit]<br />
Description=Automount removable storage<br />
<br />
[Service]<br />
Type=forking<br />
ExecStart=/usr/lib/udev/domount %I<br />
</nowiki>}}<br />
<br />
We also create a udev rule in {{ic|/etc/udev/rules.d/automount.rules}} very similar to the previous solution.<br />
<br />
{{bc|<nowiki><br />
# ignore sda*<br />
KERNEL!="sd[b-z]*", GOTO="end"<br />
# Also allow SD cards<br />
KERNEL=="mmcblk[0-9]p[0-9]", GOTO="MMC"<br />
<br />
# USB: run the script<br />
LABEL="USB"<br />
ACTION=="add", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="partition", RUN+="/usr/bin/systemctl start automount@%N.service", GOTO="end"<br />
ACTION=="add", ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="partition", RUN+="/usr/bin/systemctl start automount@%N.service", GOTO="end"<br />
<br />
LABEL="MMC"<br />
ACTION=="add", ENV{DEVTYPE}=="partition", RUN+="/usr/bin/systemctl start automount@%N.service", GOTO="end"<br />
<br />
# exit<br />
LABEL="end"<br />
</nowiki>}}<br />
<br />
The juice of the solution is placed in {{ic|/usr/lib/udev/domount}}:<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
#edit the following variables to suit your needs<br />
MYUID=1000 # your user uid<br />
MYGID=100 # your user gid<br />
MYLOGIN="ME" # your login<br />
<br />
<br />
USERSCRIPT="/usr/lib/udev/domount_user";<br />
<br />
BASE='/media'<br />
DIR=$(basename $*)<br />
i=0<br />
while [ -d "$BASE/$DIR" ]; do<br />
DIR="$(basename $*).$i"<br />
i=$((i+1))<br />
done<br />
<br />
mkdir -p "$BASE/$DIR" && /bin/mount -o uid=$MYUID,gid=$MYGID "$*" "$BASE/$DIR"<br />
<br />
if [ -z "$(su $MYLOGIN -c 'screen -ls | grep AUTOMOUNT')" ]; then<br />
su $MYLOGIN -c "screen -dm -S AUTOMOUNT -t $DIR $USERSCRIPT $* $BASE $DIR"<br />
exit<br />
fi<br />
su $MYLOGIN -c "screen -S AUTOMOUNT -X screen -t $DIR $USERSCRIPT $* $BASE $DIR"<br />
</nowiki>}}<br />
<br />
and in {{ic|/usr/lib/udev/domount_user}}:<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
DEV="$1";<br />
BASE="$2";<br />
DIR="$3";<br />
<br />
echo "$DEV mounted on $BASE/$DIR"<br />
echo "Contents:"<br />
ls --color=auto "$BASE/$DIR"<br />
echo -e "\n------------------------------------\nExit shell to unmount when finished.";<br />
while true; do<br />
d=$HOME;<br />
cd $BASE/$DIR<br />
bash<br />
cd $dir;<br />
<br />
echo "------------------------------------"<br />
lsof | grep $BASE/$DIR;<br />
if [ $? -eq 1 ]; then<br />
break;<br />
else<br />
echo "------------------------------------";<br />
echo "The above processes will block the unmount. Please end them.";<br />
fi<br />
done<br />
<br />
sudo /bin/umount "$BASE/$DIR" && sudo rmdir "$BASE/$DIR";<br />
</nowiki>}}<br />
<br />
To access the screen session which controls the mounted partitions, simply run <br />
$ screen -d -r AUTOMOUNT<br />
I would suggest putting this in a command key shortcut, for example with [[xbindkeys]] to run in a terminal.<br />
<br />
== Manual mounting ==<br />
<br />
{{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.}}<br />
<br />
=== Getting a kernel that supports usb_storage ===<br />
<br />
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:<br />
<br />
# modprobe usb-storage<br />
# modprobe sd_mod (only for non SCSI kernels)<br />
<br />
{{Tip|In case of manually loading modules, you may also need to load the {{ic|sg}} module (SCSI generic driver).}}<br />
<br />
=== Identifying device ===<br />
<br />
First thing one need to access storage device is it's identifier assigned by kernel. See [[fstab#Identifying filesystems]] for details.<br />
<br />
{{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.}}<br />
<br />
=== Mounting USB memory ===<br />
<br />
{{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.}}<br />
<br />
You need to create the directory in which you are going to mount the device:<br />
# mkdir /mnt/usbstick<br />
<br />
==== As root ====<br />
<br />
Mount the device as root with this command (do not forget to replace '''device_node''' by the path you found):<br />
# mount '''device_node''' /mnt/usbstick<br />
or<br />
# mount -U '''UUID''' /mnt/usbstick<br />
<br />
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.<br />
<br />
{{Note|If mounting your stick does not work you can try to repartition it, see [[Format a device]].}}<br />
<br />
==== As normal user with mount ====<br />
<br />
If you want non-root users to be able to write to the USB stick, you can issue the following command:<br />
<br />
# mount -o gid=users,fmask=113,dmask=002 /dev/sda1 /mnt/usbstick<br />
<br />
==== As normal user with fstab ====<br />
<br />
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:<br />
/dev/sda1 /mnt/usbstick vfat '''user''',noauto,noatime,flush 0 0<br />
or better:<br />
UUID=E8F1-5438 /mnt/usbstick vfat '''user''',noauto,noatime,flush 0 0<br />
(see description of '''user''' and other options in the [[Fstab|main article]])<br />
<br />
{{Note|Where {{ic|/dev/sda1}} is replaced with the path to your own usbstick, see [[USB_Storage_Devices#Mounting_USB_memory|Mounting USB memory]].}}<br />
<br />
Now, any user can mount it with:<br />
$ mount /mnt/usbstick<br />
<br />
And unmount it with:<br />
$ umount /mnt/usbstick<br />
<br />
== Unmounting devices mounted with udev or systemd/udev ==<br />
<br />
Create an executable file (e.g. {{ic|/usr/local/bin/unmount.sh}}):<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
# Global variables<br />
TITLE="Unmount Utility"<br />
COLUMNS=3 # TARGET,SOURCE,FSTYPE<br />
#IFS=$'\n'<br />
<br />
# Populate list of unmountable devices<br />
deviceList=($(findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]"))<br />
deviceCount=$((${#deviceList[@]} / $COLUMNS))<br />
<br />
# Start of program output<br />
echo $TITLE<br />
<br />
# Display list of devices that can be unmounted<br />
for ((device=0; device<${#deviceList[@]}; device+=COLUMNS))<br />
do<br />
printf "%4s) %-25s%-13s%-10s\n"\<br />
"$(($device / $COLUMNS))"\<br />
"${deviceList[$device]}"\<br />
"${deviceList[$(($device + 1))]}"\<br />
"${deviceList[$(($device + 2))]}"<br />
done<br />
<br />
printf "%4s) Exit\n" "x"<br />
<br />
# Get input from user<br />
read -p "Choose a menu option: " input<br />
<br />
# Input validation<br />
if [ "$input" = "X" ] || [ "$input" = "x" ]<br />
then<br />
echo "Exiting"<br />
exit 0<br />
fi<br />
<br />
if (( $input>=0 )) && (( $input<$deviceCount ))<br />
then<br />
echo "Unmounting: ${deviceList[$(($input * $deviceCount))]}"<br />
sudo umount "${deviceList[$(($input * $deviceCount))]}"<br />
exit 0<br />
else<br />
echo "Invalid menu choice"<br />
exit 1<br />
fi<br />
</nowiki>}}<br />
<br />
{{Note|This script requires that you have sudo installed and that you have sudo rights.}}<br />
<br />
== Troubleshooting ==<br />
<br />
=== Poor copy performance to USB pendrive ===<br />
<br />
{{Merge|Maximizing Performance}}<br />
<br />
{{Expansion|provide better description, or at least some reference}}<br />
<br />
If you experienced slow copy speed to pendrive (mainly in KDE), then append these three lines in a [[systemd]] tmpfile:<br />
<br />
{{hc|/etc/tmpfiles.d/local.conf|<br />
w /sys/kernel/mm/transparent_hugepage/enabled - - - - madvise<br />
w /sys/kernel/mm/transparent_hugepage/defrag - - - - madvise<br />
w /sys/kernel/mm/transparent_hugepage/khugepaged/defrag - - - - 0<br />
}}<br />
<br />
See also [[Maximizing Performance#Tuning kernel parameters]].</div>Ffhaddadhttps://wiki.archlinux.org/index.php?title=USB_storage_devices&diff=275933USB storage devices2013-09-18T06:45:39Z<p>Ffhaddad: Added code to unmount devices mounted with udev or systemd/udev to provide a more complete solution.</p>
<hr />
<div>[[Category:Storage]]<br />
[[es:USB Storage Devices]]<br />
[[it:USB Storage Devices]]<br />
[[ru:USB Storage Devices]]<br />
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.<br />
<br />
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.<br />
<br />
== Auto-mounting with udisks ==<br />
<br />
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.<br />
<br />
== Auto-mounting with udev ==<br />
<br />
{{Deletion|Conflicts with [[Udev#Udisks]] (first sentence). See [[Talk:USB Storage Devices#Auto-mounting with udev]] for details.|Talk:USB Storage Devices#Auto-mounting with udev}}<br />
<br />
See [[Udev#Auto mounting USB devices|Udev:Auto mounting USB devices]].<br />
<br />
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: <br />
{{bc|<nowiki><br />
# ignore sda*<br />
KERNEL!="sd[b-z]*", GOTO="end"<br />
<br />
# run the script<br />
ACTION=="add", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="partition", RUN+="domount %N"<br />
<br />
# exit<br />
LABEL="end"<br />
</nowiki>}}<br />
and a file (executable by root) named {{ic|/usr/lib/udev/domount}} with (set the variables on top to the correct values):<br />
<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
#edit the following variables to suit your needs<br />
MYUID=1000 # your user uid<br />
MYGID=100 # your user gid<br />
MYLOGIN=al # your login<br />
TERM=lxterminal # your terminal emulator<br />
MYSHELL=zsh # your shell<br />
export DISPLAY=:0 # your X display<br />
<br />
<br />
TMPFILE=/run/automount.$RANDOM<br />
DIR=$(grep -v '#' /etc/fstab | grep $* | awk '{print $2;}')<br />
if [ -z "$DIR" ]; then<br />
LABEL=$(lsblk -no LABEL $*)<br />
if [ -z "$LABEL" ]; then<br />
UUID=$(lsblk -no UUID $*)<br />
if [ -z "$UUID" ]; then<br />
DIR=/run/media/"unknown"<br />
else<br />
DIR=/run/media/"$UUID"<br />
fi<br />
else<br />
DIR=/run/media/"$LABEL"<br />
fi<br />
fi<br />
mkdir -p $DIR<br />
<br />
cat > $TMPFILE << EOF<br />
#!/bin/sh<br />
echo "$* was mounted on $DIR. "<br />
cd $DIR<br />
$MYSHELL<br />
EOF<br />
chmod a+x $TMPFILE<br />
<br />
/bin/mount -o uid=$MYUID,gid=$MYGID $* $DIR<br />
su $MYLOGIN -c "$TERM -t 'Terminal - $* mounted on $DIR' -e $TMPFILE"<br />
/bin/umount $DIR<br />
<br />
sleep 1; rm -f $TMPFILE<br />
</nowiki>}}<br />
<br />
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. <br />
<br />
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"<br />
<br />
== Auto-mounting with udev and systemd ==<br />
<br />
{{Deletion|Conflicts with [[Udev#Udisks]] (first sentence). See [[Talk:USB Storage Devices#Auto-mounting with udev]] for details.|Talk:USB Storage Devices#Auto-mounting with udev}}<br />
<br />
The above solution does not work, since the RUN directive is for only short processes, and udev enforces this; Scripts will be killed shortly after starting.<br />
Instead, the following solution based on the previous one uses [[systemd]], [[udev]] and [[screen]] to create a more elegant solution.<br />
<br />
First, we create a systemd service template ({{ic|/etc/systemd/system/automount@.service}}):<br />
{{bc|<nowiki><br />
[Unit]<br />
Description=Automount removable storage<br />
<br />
[Service]<br />
Type=forking<br />
ExecStart=/usr/lib/udev/domount %I<br />
</nowiki>}}<br />
<br />
We also create a udev rule in {{ic|/etc/udev/rules.d/automount.rules}} very similar to the previous solution.<br />
<br />
{{bc|<nowiki><br />
# ignore sda*<br />
KERNEL!="sd[b-z]*", GOTO="end"<br />
# Also allow SD cards<br />
KERNEL=="mmcblk[0-9]p[0-9]", GOTO="MMC"<br />
<br />
# USB: run the script<br />
LABEL="USB"<br />
ACTION=="add", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="partition", RUN+="/usr/bin/systemctl start automount@%N.service", GOTO="end"<br />
ACTION=="add", ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="partition", RUN+="/usr/bin/systemctl start automount@%N.service", GOTO="end"<br />
<br />
LABEL="MMC"<br />
ACTION=="add", ENV{DEVTYPE}=="partition", RUN+="/usr/bin/systemctl start automount@%N.service", GOTO="end"<br />
<br />
# exit<br />
LABEL="end"<br />
</nowiki>}}<br />
<br />
The juice of the solution is placed in {{ic|/usr/lib/udev/domount}}:<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
#edit the following variables to suit your needs<br />
MYUID=1000 # your user uid<br />
MYGID=100 # your user gid<br />
MYLOGIN="ME" # your login<br />
<br />
<br />
USERSCRIPT="/usr/lib/udev/domount_user";<br />
<br />
BASE='/media'<br />
DIR=$(basename $*)<br />
i=0<br />
while [ -d "$BASE/$DIR" ]; do<br />
DIR="$(basename $*).$i"<br />
i=$((i+1))<br />
done<br />
<br />
mkdir -p "$BASE/$DIR" && /bin/mount -o uid=$MYUID,gid=$MYGID "$*" "$BASE/$DIR"<br />
<br />
if [ -z "$(su $MYLOGIN -c 'screen -ls | grep AUTOMOUNT')" ]; then<br />
su $MYLOGIN -c "screen -dm -S AUTOMOUNT -t $DIR $USERSCRIPT $* $BASE $DIR"<br />
exit<br />
fi<br />
su $MYLOGIN -c "screen -S AUTOMOUNT -X screen -t $DIR $USERSCRIPT $* $BASE $DIR"<br />
</nowiki>}}<br />
<br />
and in {{ic|/usr/lib/udev/domount_user}}:<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
DEV="$1";<br />
BASE="$2";<br />
DIR="$3";<br />
<br />
echo "$DEV mounted on $BASE/$DIR"<br />
echo "Contents:"<br />
ls --color=auto "$BASE/$DIR"<br />
echo -e "\n------------------------------------\nExit shell to unmount when finished.";<br />
while true; do<br />
d=$HOME;<br />
cd $BASE/$DIR<br />
bash<br />
cd $dir;<br />
<br />
echo "------------------------------------"<br />
lsof | grep $BASE/$DIR;<br />
if [ $? -eq 1 ]; then<br />
break;<br />
else<br />
echo "------------------------------------";<br />
echo "The above processes will block the unmount. Please end them.";<br />
fi<br />
done<br />
<br />
sudo /bin/umount "$BASE/$DIR" && sudo rmdir "$BASE/$DIR";<br />
</nowiki>}}<br />
<br />
To access the screen session which controls the mounted partitions, simply run <br />
$ screen -d -r AUTOMOUNT<br />
I would suggest putting this in a command key shortcut, for example with [[xbindkeys]] to run in a terminal.<br />
<br />
== Manual mounting ==<br />
<br />
{{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.}}<br />
<br />
=== Getting a kernel that supports usb_storage ===<br />
<br />
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:<br />
<br />
# modprobe usb-storage<br />
# modprobe sd_mod (only for non SCSI kernels)<br />
<br />
{{Tip|In case of manually loading modules, you may also need to load the {{ic|sg}} module (SCSI generic driver).}}<br />
<br />
=== Identifying device ===<br />
<br />
First thing one need to access storage device is it's identifier assigned by kernel. See [[fstab#Identifying filesystems]] for details.<br />
<br />
{{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.}}<br />
<br />
=== Mounting USB memory ===<br />
<br />
{{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.}}<br />
<br />
You need to create the directory in which you are going to mount the device:<br />
# mkdir /mnt/usbstick<br />
<br />
==== As root ====<br />
<br />
Mount the device as root with this command (do not forget to replace '''device_node''' by the path you found):<br />
# mount '''device_node''' /mnt/usbstick<br />
or<br />
# mount -U '''UUID''' /mnt/usbstick<br />
<br />
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.<br />
<br />
{{Note|If mounting your stick does not work you can try to repartition it, see [[Format a device]].}}<br />
<br />
==== As normal user with mount ====<br />
<br />
If you want non-root users to be able to write to the USB stick, you can issue the following command:<br />
<br />
# mount -o gid=users,fmask=113,dmask=002 /dev/sda1 /mnt/usbstick<br />
<br />
==== As normal user with fstab ====<br />
<br />
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:<br />
/dev/sda1 /mnt/usbstick vfat '''user''',noauto,noatime,flush 0 0<br />
or better:<br />
UUID=E8F1-5438 /mnt/usbstick vfat '''user''',noauto,noatime,flush 0 0<br />
(see description of '''user''' and other options in the [[Fstab|main article]])<br />
<br />
{{Note|Where {{ic|/dev/sda1}} is replaced with the path to your own usbstick, see [[USB_Storage_Devices#Mounting_USB_memory|Mounting USB memory]].}}<br />
<br />
Now, any user can mount it with:<br />
$ mount /mnt/usbstick<br />
<br />
And unmount it with:<br />
$ umount /mnt/usbstick<br />
<br />
== Script to unmount devices mounted with udev or systemd/udev ==<br />
<br />
Create an executable file (e.g. {{ic|/usr/local/bin/unmount.sh}}):<br />
{{bc|<nowiki><br />
#!/bin/sh<br />
<br />
# Global variables<br />
TITLE="Unmount Utility"<br />
COLUMNS=3 # TARGET,SOURCE,FSTYPE<br />
#IFS=$'\n'<br />
<br />
# Populate list of unmountable devices<br />
deviceList=($(findmnt -Do TARGET,SOURCE,FSTYPE | grep -e "sd[b-z]"))<br />
deviceCount=$((${#deviceList[@]} / $COLUMNS))<br />
<br />
# Start of program output<br />
echo $TITLE<br />
<br />
# Display list of devices that can be unmounted<br />
for ((device=0; device<${#deviceList[@]}; device+=COLUMNS))<br />
do<br />
printf "%4s) %-25s%-13s%-10s\n"\<br />
"$(($device / $COLUMNS))"\<br />
"${deviceList[$device]}"\<br />
"${deviceList[$(($device + 1))]}"\<br />
"${deviceList[$(($device + 2))]}"<br />
done<br />
<br />
printf "%4s) Exit\n" "x"<br />
<br />
# Get input from user<br />
read -p "Choose a menu option: " input<br />
<br />
# Input validation<br />
if [ "$input" = "X" ] || [ "$input" = "x" ]<br />
then<br />
echo "Exiting"<br />
exit 0<br />
fi<br />
<br />
if (( $input>=0 )) && (( $input<$deviceCount ))<br />
then<br />
echo "Unmounting: ${deviceList[$(($input * $deviceCount))]}"<br />
sudo umount "${deviceList[$(($input * $deviceCount))]}"<br />
exit 0<br />
else<br />
echo "Invalid menu choice"<br />
exit 1<br />
fi<br />
</nowiki>}}<br />
<br />
{{Note|This script requires that you have sudo installed and that you have sudo rights.}}<br />
<br />
== Troubleshooting ==<br />
<br />
=== Poor copy performance to USB pendrive ===<br />
<br />
{{Merge|Maximizing Performance}}<br />
<br />
{{Expansion|provide better description, or at least some reference}}<br />
<br />
If you experienced slow copy speed to pendrive (mainly in KDE), then append these three lines in a [[systemd]] tmpfile:<br />
<br />
{{hc|/etc/tmpfiles.d/local.conf|<br />
w /sys/kernel/mm/transparent_hugepage/enabled - - - - madvise<br />
w /sys/kernel/mm/transparent_hugepage/defrag - - - - madvise<br />
w /sys/kernel/mm/transparent_hugepage/khugepaged/defrag - - - - 0<br />
}}<br />
<br />
See also [[Maximizing Performance#Tuning kernel parameters]].</div>Ffhaddad