Linux working with usb

Setting up USB on Linux

It’s easy to get a Linux kernel that supports USB now. But that’s only part of what you need in order to use USB; the rest of the operating environment needs updates, of various types, to make it usable. At this writing, only a few GNU/Linux distributions support even statically configured USB . yet USB is about hotplugging and dynamic configuration. What does your Linux system need to really run USB? Kernel Configuration for USB You’ll need a 2.4.0 or 2.2.18 kernel; some other USB ports also exist. Configure all (!) USB features as modules, and enable the USB «device» file system. You may prefer non-modular versions of some key USB modules so that you can boot with a USB keyboard and mouse. Install the kernel as usual. USB Initialization Part of this may be done as the Linux kernel bootstraps. The more modular your kernel USB configuration is, the more initialization needs to be done in scripts after the kernel starts to run. USB initialization needs to be run from your system’s equivalent of /etc/rc.d/rc.sysinit, ideally without needing to set up lots of system config files and without overlooking anything important. Hotplugging: USB Daemon (USBD) and Policy Agent A basic design goal for USB is Plug’n’Play operation: Linux should react when users plug in new devices, making such devices usable without requiring administrative action. Some notifier (conceptually a «USB Daemon») reports new devices to a policy agent which can choose and start a driver for the device. Such agents can also tell other subsystems (networking, print spooling, etc.) about new devices which concern them. At this writing, the only supported «USB Daemon» is enabled by a kernel configuration option (CONFIG_HOTPLUG), but similar functionality has also been written with pure user-mode support. Configure a USB Daemon, as listed later, to invoke those agent scripts. Other System Updates File system device nodes for USB devices need to get created. Recent GNU/Linux distribution have been taught about USB. Otherwise, you’ll likely need to follow the /usr/src/linux/Documentation/usb files distributed with your kernel. You may also need to update X11 configuration files to tell the server about /dev/input/mice or other devices. (And surely there are lots of other updates that we just don’t understand yet. Cardbus, print spooling, and networking just for starters. ) The USB Guide is the best resource for information about such sysadmin topics. Tools and Troubleshooting If you aren’t running in an automated Plug’n’Play mode, you will require tools. They don’t really exist, except for classic (wetware-enhanced) text editors. For troubleshooting, configure «usbdevfs» into your USB; it’s the main way to determine USB status. Basic diagnostic scripts («rc.usb status») exist.

Читайте также:  Linux shadow and shadow

The short version of the rest of this document is this: download and install the Linux-USB tools, so that USB is fully set up and so that you can use your kernel HOTPLUG support.

USB Initialization: /etc/rc Scripts

  • Conectiva Linux Server Edition 5.1
  • Corel Linux Second Edition
  • Mandrake 7.1
  • RedHat 7
  • SuSE 6.4

Linux Hotplug Tools

The current software is at the linux-hotplug project site. There’s an RPM version (soon, APT), and also a tarball (with installation instructions) if you need that. This includes USB hotplugging support, and also handles PCI.

Hotplugging: USB Daemon and Policy Agents

  • Something that notifies when new USB devices are added to the system . for example, kUSBD (in the kernel) is invoked by the «khubd» thread, and other approaches monitor what «usbdevfs» reports.
  • Something to notify of such changes . a policy agent. This is where the intelligence lives: Load a kernel driver? Start a user mode driver? Reconfigure something?

The same approach can work with other kernel subsystems that need to dynamically react to device addition and removal. The /sbin/hotplug program (typically a shell script; see the reference code in CVS above) handles USB the same way it can handle other types of hotplug events.

The Linux-USB Tools package provides an implementation of a USB Hotplug agent; more intelligent implementations will likely appear. Documentation exists. The most recent release leverages USB «modutils» support with Linux 2.4.0 kernel series. (The expectation is that such support will replace earlier support that relied exclusively on driver configuration scripts.)

Kernel USB Daemon (kUSBD)

The only currently supported USB Daemon is the Kernel USB Daemon. You get it when you enable HOTPLUG with USB; it is «light weight» in that it doesn’t require «usbdevfs» support (a design requirement) and adds only a very small amount of kernel code. (Previous daemons required «usbdevfs» and a user mode process scanning it for changes. That was a much larger system footprint.) Most of the work is punted to user mode, by invoking a user mode helper program (/sbin/hotplug by default) that knows how to find the USB policy agent that does the real work. The modutils support is targeted at 2.4.0 but the 2.2.18 kernel also works.

When you boot a kUSBD-enabled kernel, you will see a file /proc/sys/kernel/hotplug if you’re running with procfs (as you probably should be). It will name the program /sbin/hotplug by default. Whenever a USB device is added or removed, that program will be invoked (if it exists). To change the program name, write to /proc/sys/kernel/hotplug. Use the hotplug script and USB policy agent provided with the Linux-USB tools (see above).

Читайте также:  Linux утилита проверки дисков

If you use kUSBD, the Linux-USBD scripts can be a single-download solution for «USB Plug’n’Play». If you’re using a 2.4 kernel with USB modutils support, you can make do with just the «/sbin/hotplug» script, which handles most module loading and driver-specific setup tasks using only common /sbin programs. You can install a more functional policy agent in /etc/hotplug/usb.agent if you prefer.

Other USB Daemons

The first USB Daemon to fully support USB hotplugging was the Java USB Daemon (jUSBD); it has since been desupported in favor of the kernel support (which doesn’t require usbdevfs). This relied on /etc/usb/policy scripts, which were then used as kUSBD policy agents.

Recently, another usbdevfs based effort was reported: the USB Manager defines a custom configuration file and driver database format which somewhat resembles the PCMCIA support. It provides a usbdevfs based notification service.

A devfs based prototype required an experimental usbdevfs-to-devfs merge patch (not part of Linux 2.4); mostly it’s listed here for historical knowledge. It successfully invoked the /etc/usb/policy scripts to cause driver loading and configuration.

There are several «USB View» tools available; for example, Corel Linux bundles one version, another is written in Java/Swing. The key difference between those and most shell script listers («usbtree» etc) is just that they automatically rescan, like a USBD.

It’s worth mentioning that Microsoft documentation uses the term «USBD» to refer to a shared library that is part of the Win32 USB device driver API. Try to avoid being confused by that; on Linux, that «d» suffix normally indicates a «daemon».

Источник

USB storage devices

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.

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.

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 detailed information, including list of mount helpers.

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.

Identifying device

The first thing one needs to access a storage device is its identifier assigned by kernel. See File systems#Identify existing file systems for details.

Читайте также:  Remote connect to linux desktop

Newly plugged-in devices are usually shown in the journal.

Mounting USB memory

If mount does not recognize the file system of the device you can try to use the -t argument, see mount(8) for details. If mounting does not work, you can try to recreate the file system or even repartition the disk.

Allow writing by regular users

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

If it does not work, make sure that the file system is mountable and writable as root, see the previous section for details.

As normal user with fstab

See FAT#Writing to FAT32 as normal user if you want normal user to do the mount/unmount action.

Mount tools

Multiple mount tools facilitate mounting as a regular user.

Troubleshooting

No USB storage devices are detected

If you have connected your USB storage device and it is not listed by lsblk but appears in the journal without being assigned a block device, see General troubleshooting#Cannot use some peripherals after kernel upgrade.

Also ensure that your BIOS has both XHCI Handoff and EHCI Handoff enabled, but this is usually not an issue with most modern devices.

Device not shutting down after unmounting all partitions

This article or section needs expansion.

Reason: Please advise how to automatically shut down devices after unmounting (Discuss in Talk:USB storage devices)

Failure to power off a device might result in:

  • a hard disk drive not parking its head, making a faint scratching sound while spinning out and degrading the device [2], or
  • a solid-state drive (especially older) not flushing its cache buffers or updating its mapping tables, and losing data [3].

When you unmount the partitions, the device is still powered on. You should ask the system to turn it off first in order to safely remove it: [4]

# echo 1 > /sys/block/disk_name/device/delete

If you use udisks, you can use these commands: [5]

$ udisksctl unmount -b /dev/sdXY $ udisksctl power-off -b /dev/sdX 

Device is detected but does not register as mountable

udev is shipped with a default set of rules, found in /usr/lib/udev/rules.d/ , including one for ignoring some specific devices for various reasons. Some hardware devices, such as digital cameras, portable recorders, etc., may format usb storage in a way that results in the ignore rules to be triggered. You can check if one of these rules was applied with the following command and then find the corresponding conditions in the defaults:

$ udevadm info --attribute-walk --name=device_name | grep UDISKS_IGNORE

If this is the case and your device has this property set to «1», you can override it with a custom rule, following the udev page.

Источник

Оцените статью
Adblock
detector