• Stars
    star
    274
  • Rank 150,274 (Top 3 %)
  • Language
    Shell
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple set of scripts to automount removable devices for a Linux system

USBmount

The USBmount package automatically mounts USB mass storage devices (e.g., USB pen drives or HDs in USB enclosures) when they are plugged in. The mountpoints (/media/usb[0-7] by default), filesystem types to consider, and mount options are configurable. When multiple devices are plugged in, the first available mountpoint is automatically selected.

If the device plugged provides a model name, a symbolic link at /var/run/usbmount/MODELNAME pointing to the mountpoint is automatically created. When the device is not present anymore in the system (e.g., after it has been unplugged), usbmount deletes the symbolic links that were created.

The script that does the (un)mounting is called by the udev daemon. Therefore, USBmount requires a 2.6 (or newer) kernel.

USBmount is intended as a lightweight solution which is independent of a desktop environment. Users which would like an icon to appear when an USB device is plugged in should use other alternatives.

The comments in the configuration file /etc/usbmount/usbmount.conf describe how to configure the package.

Generic Comments about Flash Drives

Users should be aware that, independently of the filesystem used by the mass storage device, ANY filesystem that resides in flash memory will become unreadable after some time. This unfortunate situation is intrinsic to the storage medium and better quality flash drives perform a "wear levelling" operation, distributing the load of operations across the whole device. [*]

Filesystems using flash memory and mounted with the sync option can degrade earlier due to the fact that the sync mount option forces the operating system to write data more frequently to the device than if it were mounted without the sync option.

So, why mount filesystems with the sync option then? The reason is to keep the written data on the drive reflecting what the user thinks is on the flash drive, and, more importantly, to avoid the problem of the user unplugging the device before it is finished receiving data that the kernel has on the memory of the computer and that is meant to be written to the device.

If you don't like the sync option with your filesystems, then you can remove it from the configuration file of usbmount and use your devices with better performance and longer life time. BUT you should always make sure that you use the sync command (on a shell) to ensure that there is no writes pending for the device in question, so that you don't loose any data when you unplug the device from the computer.

[*] You can see if your flash drives support wear levelling by seeing the technical specifications of your specific drives in the manufacturer's site (e.g., the manufacturer Kingston provides such information regarding its drives and others quite probably do that too).

Of course, usbmount doesn't only work with flash drives. Common hard drives put into enclosures are perfectly used with usbmount and usbmount, despite its name, can mount drives connected via Firewire ports, provided that the kernel has support for it (most distribution kernels, including the ones shipped with Debian and Ubuntu do).

Generic comments about package dependencies

This package depends on a few other packages for installation. These are properly declared in the built package and apt-get will install all required packages if the package is installed from a remote repository but dpkg doesn't install dependencies when the package is installed from a local file.

There are a few ways to deal with dependencies when installing files directly, ex:

Option 1: let apt-get fix missing dependencies.

# Try install, will not necessarily complete if you're missing a dependency
dpkg -i <package>.deb

# Will install missing dependencies and finish the install process
apt-get install -f

Option 2: use a package installer that fetches dependencies even for local packages (ex. gdebi).

# Only required the first time you do this with any package
apt-get install gdebi

# Actually install the package and it's dependencies
gdebi <package>.deb

Technical Considerations

Control of Filesystems Mounted by USBmount

You can choose which filesystems you want usbmount to automatically handle by listing the filesystem types provided by the operating system in the configuration variable FILESYSTEMS.

Recommendations for vfat Filesystems

The vfat filesystem is one of the most commonly used filesystems in pen drives. Unfortunately, due to its age, it is very poor regarding features and, in particular, it doesn't feature the most basic access control present in Unix systems, namely: permissions on files.

Linux works around this by creating "virtual" permissions and restrictions based on who mounted the filesystem. As usbmount is used, the user assigned to the vfat filesystem is, by default, root.

For a more flexible configuration, some useful options for vfat filesystems are to specify explicitly who the user and permissions are. Please, read the manpage of the mount command to get details.

An example is to specify -fstype=vfat,gid=floppy,dmask=0007,fmask=0117 in the FS_MOUNTOPTIONS variable of the configuration file. The particular options specified in the example mean that members of the floppy group can read from and write to the medium, but nobody else can access it.

Troubleshooting USBmount

No software is free of problems and the situation isn't different with USBmount. To ease the troubleshooting of problems, you may try to check the following:

  • Do you have HAL running? Any GNOME or KDE daemon automounting devices?

  • Let's suppose that the partition containing the filesystem that you want USBmount to automatically handle is /dev/sda1 (your case may, quite possibly, vary). Then, check the result of the following command:

      udevadm test --action=add /sys/class/block/sda1
    

    The command above just gives diagnostics of what USBmount would do with the device, but it doesn't actually mount or interfere with the device. It is intended for debugging purposes. Be careful that it generates a lot of output. Many screens, depending on the device.

  • Under the same assumptions as the above, another good diagnostic tool is the following:

      udevadm info -a -p $(udevadm info -q path -n /dev/sdb1)
    

Hook Scripts

After a device or partition has been mounted, the command run-parts /etc/usbmount/mount.d is executed. This runs all scripts in /etc/usbmount/mount.d which adhere to a certain naming convention; see the run-parts manual page for details.

The following environment variables are available to the scripts (in addition to those set in /etc/usbmount/usbmount.conf and by the hotplug and udev systems):

Variable Description
UM_DEVICE file name of the device node
UM_MOUNTPOINT mountpoint
UM_FILESYSTEM filesystem type
UM_MOUNTOPTIONS mount options that have been passed to the mount command
UM_VENDOR vendor of the device (empty if unknown)
UM_MODEL model name of the device (empty if unknown)

Likewise, the command run-parts /etc/usbmount/umount.d is executed after a device or partition has been unmounted. The scripts can make use of the environment variables UM_DEVICE, UM_MOUNTPOINT and UM_FILESYSTEM. Note that vendor and model name are no longer easily available when the device has been removed. If you need this information in an unmount hook script, write it to a file in a mount hook script and read it back in the unmount hook script.

Safely unmounting filesystems

As it is not possible for the system to detect when the device should be unmounted (such information is only present when the device has already been unplugged, which is too late for some clean ups, like flushing unwritten buffers to disk and marking the filesystem as clean), the user should manually unmount the device that were automatically mounted.

This situation is similar to those in graphical desktop environments where the user has to click on an icon and inform the system that it wants to remove the device from the computer.

A recommended solution for this problem is to use the pumount command (provided by the pmount package), which acts as a wrapper around the regular mount command and lets regular users (i.e., not root) to unmount the filesystems, conveniently.

Warning: carelessly removing the device/filesystem without unmounting it first can (and does) lead to massive filesystem corruption and should only be performed if you know exactly what you are doing.

The Special Case of FUSE Filesystems

Many users use removable drives with NTFS filesystems and the user-space filesystem NTFS-3g, since it provides more flexibility than the native module present in the Linux kernel.

Such users have difficulty when unmounting the filesystems, since they are present in the system /etc/mtab with a filesystem type of fuseblk, not with ntfs (or ntfs-3g) as one might expect.

For such filesystems, it may be convenient to:

  • add ntfs-3g to /etc/usbmount/usbmount.conf's variable FILESYSTEMS (for mounting purposes)
  • add fuseblk to /etc/usb/usbmount.conf's variable FILESYSTEMS (for unmounting purposes).

Similar comments may apply to other FUSE-managed filesystems. In general, if you need a FUSE filesystem, it may be a good idea to add the name of that filesystem to the FILESYSTEMS variable as well as making sure that the special fuseblk filesystem is contained in that list.

This subsection is an adaptation of descriptions made by Thomas Jancar and Jan Schulz.

Remounting filesystems without physical removal

usbmount operates (read: "mounts or unmounts filesystems") based on events issued by the Linux kernel/udev. As a consequence, if you happen to unmount a filesystem and want to mount it again, you have basically two choices:

  1. unplug and plug the device, which may not be desired, for a number of reasons.
  2. make the kernel/udev generate another event so that usbmount knows that it has some work to do.

The latter can be accomplished by the use of the command

udevadm trigger --action=add /dev/sdd2

where /dev/sdd2 should be substituted with the proper partition. This command is likely needed to be run with superuser privileges. Triggering kernel events is also a way to get a particular filesystem mounted after a cold boot.

Building the package

In order to build this package, debhelper and build-essential are required. The package can be built with the simple commands:

# Install dependencies
sudo apt-get update && sudo apt-get install -y debhelper build-essential

# Build
sudo dpkg-buildpackage -us -uc -b

More Repositories

1

deprecated-lame-mirror

[DEPRECATED] Old, Semi-official mirror of the CVS repository of the LAME MP3 encoder.
C
75
star
2

mediterranean-gtk-themes

Maintenance fork of the Mediterranean theme for GTK2/3.
CSS
53
star
3

pkg-youtube-dl

Official Debian packaging of youtube-dl
Python
52
star
4

urw-garamond

Improved version of the font URW Garamond No.8
Python
46
star
5

xpdf-poppler

Fork of xpdf with use of the poppler library
C++
32
star
6

tunesviewer

iTunes U browser for non-{Mac,Windows} operating systems
Python
24
star
7

epub-example

Simple example of the anatomy and of the creation of an EPUB file
14
star
8

gnome-themes-zukitwo

Debian packaging of the Zukitwo GNOME theme
CSS
11
star
9

edx-dl-old-fork

Simple tool to download videos from edX-based sites
Python
10
star
10

dotfiles

Example dotfiles for programs that I like
Python
9
star
11

lartc

Linux Advanced Routing & Traffic Control HOWTO
7
star
12

pkg-mp3packer

Debian packaging of mp3packer
OCaml
7
star
13

pkg-faenza-icon-theme

Debian packaging of the Faenza icon theme
6
star
14

py-lame

Unofficial mirror of the CVS module py-lame of the LAME project
C
6
star
15

lombardi-spirograph

David Eppstein's LombardiSpirograph.py graph drawing script.
Python
4
star
16

enjoyreading-ng

Maintenance fork of the Enjoy Reading extension for Firefox
4
star
17

pkg-dvd-rw-tools

Debian packaging of dvd+rw-tools
C++
3
star
18

avr-evtd

AVR watchdog daemon for Linkstation/Kuroboxes
C++
3
star
19

scripts

Random scripts of mine
Jupyter Notebook
3
star
20

pkg-hfsprogs

Debian packaging of a port of Apple's fsck and mkfs for Linux
C
3
star
21

pkg-libvidstab

Debian packaging of vid.stab
C
3
star
22

lastfm

*VERY* simple command-line program to query last.fm for similar songs/artists
Python
3
star
23

kurobox-ppc-uboot

Uboot used for creation of image KuroBox HD/HG (based on version uboot 1.1.4)
C
3
star
24

rdiff-backup-fs

Automatically exported from code.google.com/p/rdiff-backup-fs
C
3
star
25

algorithms

The algorithms set of packages for LaTeX
TeX
3
star
26

html5-test

JavaScript
2
star
27

zip2tar

Convert zip files to tar files in memory
Python
2
star
28

old-projects

Old programs that I wrote about 15 years ago
Java
2
star
29

fonts-policy

2
star
30

cgit

C
1
star
31

readability

Debian packaging of Firefox's readability extension
JavaScript
1
star
32

pkg-parallel

Debian packaging of GNU parallel
Perl
1
star
33

math-faq

Frequently Asked Questions on Mathematics
TeX
1
star
34

pkg-pdfbeads

Debian packaging of pdfbeads
Ruby
1
star
35

blackboard

Python
1
star
36

flash-video-replacer

Debian packaging of Firefox's FlashVideoReplacer extension
JavaScript
1
star
37

powerpc-tutorial

Small tutorial document for running Linux on PowerPC machines, with emphasis on KuroBoxes
1
star
38

rbrito

My simple blog
Perl
1
star
39

toy-android-apps

Just some toy Android apps for learning purposes.
Java
1
star
40

pkg-pdfsizeopt

Unofficial packaging of pdfsizeopt
Python
1
star
41

RehearsalAssistant

Fork of https://sourceforge.net/projects/rehearsalassist/
Java
1
star
42

parallel

Debian packaging of GNU parallel
Perl
1
star
43

pkg-jbig2enc

Unofficial Debian packaging of jbig2enc
C++
1
star
44

userisomount

Debian packaging of nautilus addon to mount ISO files with a simple right click
Shell
1
star
45

codebreakers

Subtitles for the "Codebreakers" video documentary translated to Portuguese
1
star
46

rbrito.github.com

Compiled version of my Homepage/Blog
HTML
1
star
47

pkg-kotlin-compiler

Unofficial Debian packaging of the Kotlin command-line compiler
Shell
1
star