External Storage Devices in Gentoo Dimitry Bradt Peter Weller Jan Kundrát This howto will show you how to use external (usb/firewire) storage devices. The guide also covers mounting Windows partitions and using iPods. 1 2006-07-25 HAL/pmount

HAL stands for Hardware Abstraction Layer, a software package providing a view of various hardware components attached to your system, as well as some metadata about them. In addition to this kind of database, HAL also offers hooks for applications that are interested in possible changes regarding hardware configuration of your box. In short, your favorite desktop environment can notify you about a plugging of a piece of hardware thanks to the service of HAL.

pmount, the Policy Mounter, is a simple program that allows users to mount devices which are not found in /etc/fstab.

The most important goal of HAL is to provide plug-and-play facilities for UNIX-like desktops, with focus on providing a rich and extensible description of device characteristics and features. You can see an example of this functionality when you plug in a USB storage device that you haven't used before. HAL detects this case and notifies all the applications that explained their interest. If you're logged in and are running a HAL-aware desktop environment like Gnome or KDE, you see a nice pop-up window asking what to do. Thanks to the pmount, your mountpoint is created, device mounted and you can access your files. Nice, isn't it? If you still aren't shocked by those wonderful features, you should read the Making Hardware Just Work article and you certainly will be :).

Configuring HAL

Before emerging the needed programs you should check that hotplug and udev work. The easiest way to test is to plug a USB-storage device into your computer and check the kernel log. If you look at the output of the dmesg command, you should see a similar lines:

# dmesg
(Many lines snipped)
scsi4 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 4
usb-storage: waiting for device to settle before scanning
Vendor: PEAK II   Model: Flash Drive       Rev: 3000
Type:   Direct-Access                      ANSI SCSI
revision: 00
SCSI device sdc: 503808 512-byte hdwr sectors (258 MB)
sdc: Write Protect is off
sdc: Mode Sense: 43 00 00 00
sdc: assuming drive cache: write through
SCSI device sdc: 503808 512-byte hdwr sectors (258 MB)
sdc: Write Protect is off
sdc: Mode Sense: 43 00 00 00
sdc: assuming drive cache: write through
sdc: sdc1
sd 4:0:0:0: Attached scsi removable disk sdc
sd 4:0:0:0: Attached scsi generic sg2 type 0
usb-storage: device scan complete 
scsi.agent[30478]: disk at 
/devices/pci0000:00/0000:00:0b.2/usb1/1-5/1-5:1.0/host4/target4:0:0/4:0:0:0

If you don't see the apropriate device nodes, please follow our Udev Guide to properly configure your system.

Before emerging any packages, you will make sure that the hal USE flag is enabled and optionally rebuild packages built without it. The --newuse option of the emerge command can help you.

Now let's check that you really have HAL and related packages installed:

# emerge --noreplace hal dbus pmount
# rc-update add dbus default
# /etc/init.d/dbus start
# rc-update add hald default
# /etc/init.d/hald start

Another important point is that all your users that you want to be able to use the functionality of HAL have to be members of the group plugdev. Please add them now:

(Repeat for all users that will be using your desktop:)
# gpasswd -a youruser plugdev

Please note that you'll have to cycle your session for those changes to take effect. Logout and login is all that you have to do.

After you've opened a new session, it's time to check that everything works.

Testing stuff

If you're running Gnome, open a computer:/// location in Nautilus. If you're a KDE user, launch Konqueror and go to media:/. Whatever you're using, you should see a list of mounted devices.

Now it's time for a real test - find a USB storage device like a memory stick, connect it to the computer and wait a few seconds. If everything works right, you'll see a pop-up window telling you that you've plugged in a new medium and asking what are your plans to do with it. If it doesn't show up, something isn't working as expected. Don't worry, that's why we have a Troubleshooting section.

If everything worked right and you opted to open the disk contents in a new window, you've probably noticed a rather cryptic name like sdb1 or something like that. As we're working under a UNIX-like system, there's a way to make it look cuter.

All you have to do is to introduce your devices to the udev subsystem. FIXME: explain what those SYSFS{foo} stubs are...

FIXME: remove... Now your window manager should automatically ask you where you would like your external devices mounted. The only thing we could do to enhance the way in which hal works, is let hal make symlinks of our devices. We can do this by making sure it is owned by group hal.

BUS=="usb", 
SYSFS{serial}=="123456789011121314", SYSFS{product}=="JUMPDRIVE",\
KERNEL=="sd?1", NAME="%k", SYMLINK="usbdrive", GROUP="hal"
BUS=="usb", SYSFS{manufacturer}=="Sony", SYSFS{product}=="PSP Type A",\ 
KERNEL=="sd?1", NAME="%k", SYMLINK="psp", GROUP="hal"
BUS=="usb", SYSFS{manufacturer}=="Apple",  SYSFS{product}=="iPod",\
KERNEL=="sd?2", NAME="%k", SYMLINK="ipod", GROUP="hal"
Content below this point wasn't touched.
External storage possibilities
Configuring the kernel

Make sure the options below are set as follows in your kernel config, which can be found at /usr/src/linux/.config.

These kernel-options are very general, you should first look at the output of lspci (emerge pciutils if you haven't got it installed) and check for yourself to see if you need OHCI or UHCI. The options below have been set for UHCI.
# nano /usr/src/linux/.config
MSDOS_FS=y
VFAT_FS=y
BLK_DEV_SD=y
CHR_DEV_ST=y
CHR_DEV_SG=y
USB_STORAGE=y
USB_UHCI_HCD=y
USB_OHCI_HCD=n

Now compile and install your kernel, when that finishes, reboot your system.

Making sure that hotplug detects your devices
# dmesg | grep usb-storage
usb.c: USB device 4 (vend/prod 0xdda/0x2005) is not claimed by any active 
driver.
If this happens, it means you did not configure your kernel as it should have been configured - you should return to Configuring the kernel.

You can do this automatically by putting your driver name in /etc/modules.autoload.d/kernel-2.{4|6}.

Utilities for querying the sg SCSI interface (contains rescan_scsi_bus.sh)
# emerge sg3_utils
mounting the USB drive

After that emerge completes, you should be able to mount the drive:

# mkdir /mnt/usbstick
# mount -t vfat /dev/sda1 /mnt/usbstick
mounting firewire devices

You can use sg3_utils to scan for firewire devices as such:

# sg_scan -i
# sg_map
Editing your fstab
Mounting your external usb-devices
# MY USB STICK
/dev/sda1             /mnt/stick      vfat        noauto,user,exec,sync     0 0

Please note that you should use vfat in the fstab file, because if you choose auto, you won't get the full name but only the first 8 characters. Add the option sync to have synchronize changes between the usb mass storage device itself, and the place that it's been mounted. Otherwise it would be done while you unmount it. This is advantageous, because otherwise, you risk losing data if you forgot to unmount the device in question, it also speeds up unmount times. You don't need to use vfat in the fstab file as long as /etc/filesystems is set up properly.

If vfat exists in /etc/filesystems before any other fat filesystems, or by itself with an asterisk ("*") on the last line, it will be tried first during a mount. Read the mount (8) man page for more details.

#
# This file defines the filesystems search order used by a
# 'mount -t auto' command.
#
# Uncomment the following line if your modular kernel has vfat
# support and you want mount to try vfat.
vfat
# Uncomment the following line if your modular kernel has udf
# support and you want mount to try udf before iso9660.
udf
# Keep the last '*' intact as it directs mount to use the
# filesystems list available at /proc/filesystems also.
# Don't remove it unless you REALLY know what you are doing!
Managing your IPOD

To be able to access the contents of an iPod correctly, you will need to install gtk-pod.

# emerge gtk-pod
Mounting your Windows partitions
The different filesystem types
# mount -t ntfs /dev/hda1 /mnt/win
# mount -t vfat /dev/hda2 /mnt/data
user permissions

With all three filesystems (MS-DOS, VFAT, NTFS), mount lets you pass the uid and gid options, which allow you set the user and group IDs of those who the files are chown'd to when the filesystem is mounted. To find out the values for uid and gid, you can run id $user.

umask: Octal file permissions
You can change permissions using the parameter umask. However, please be aware that it must be the bitmask of permissions which are not present for the mountpoint. It is an octal number, formed like this:

  • Character '0': Indicates that this is an octal number, not decimal
  • First digit: owner user permissions
  • Second digit: owner group permissions
  • Third digit: world permissions (every other user on the system).
MRWX0***1**-2*-*3*--4-**5-*-6--*7---
Table 3.1: Permissions table
# my windows partition
/dev/hda1  /mnt/ntfs  ntfs  uid=1000,gid=100  0 0

For more options:

# man mount 8
Captive NTFS You will need an X window system for captive.

We need sys-fs/captive (Description: Captive uses binary Windows drivers for full NTFS r/w access.) to get this to work. For now Captive is masked, and as such, you will need to unmask it first:

Emerge captive:

# emerge captive

Now load the appropriate kernel module, and make it load at boot.

# modules-update
# modprobe fuse
# echo "fuse" >> /etc/modules.autoload.d/kernel-2.6

Congratulations; Captive should now be installed. To acquire the necessary filesystems drivers you should run the following command to locate your ntfs drives in a wizard. You should choose to download the appropriate drivers from http://microsoft.com (You will need a Windows SP2 license to do this legally.) (It doesn't matter if your partitions are mounted or not - the program itself looks for the right partitions.)

# captive-install-acquire

After you walked through the wizard, you should now be able to mount your windows partitions read/write.

# umount /mnt/win
# mount -t captive-ntfs /dev/hda1 /mnt/win

If the following works without errors you may want to put it in your /etc/fstab

/dev/hda2          /windows          captive-ntfs     users      0 0
You will need to recompile fuse if you update your kernel!
# modprobe -r fuse
# emerge sys-fs/fuse
# modules-update
# modprobe fuse
Troubleshooting
Devices don't get recognized when inserted

This is probably due to udev not working. One of the reasons this could be happening is becse udev needs specific kernel options to be turned on. The basic options needed by udev for kernel 2.6.16 and earlier are CONFIG_NET, CONFIG_HOTPLUG and CONFIG_UEVENT and the basic options needed by udev for kernel 2.6.17 and later are CONFIG_NET, CONFIG_HOTPLUG as CONFIG_UEVENT has been deprecated in favour of CONFIG_NET

These basic options should be turned on by default. If someone turns them off they should already know the consequences.

Enable KOBJECT_UEVENT and CONFIG_HOTPLUG in your kernel. Search for the following options with /, or edit /usr/src/linux/.config to include them.

KOBJECT_UEVENT=y
CONFIG_HOTPLUG=y