Posted by: isaraffee | August 9, 2009

Using USB Thumbdrive in Linux (Kernel 2.4.3)

USING USB THUMBDRIVE IN LINUX

In this section I will explain how to configure a Linux box, which has a kernel 2.4.3 to use a USB thumb drive. Why I specifically mentioned its kernel version is that if you are using LInux with kernel 2.4.3, chances are that if you insert your thumdrive into the USB port, you could not use it straight away i.e. it is not plug and play. You will have to configure some file, like the /etc/fstab file in order to use it. ON the other hand, if you are using Linux with a kernel 2.6, you would not have to worry, as it will detect the device and some distribution like SUSE will even prompt you t hat the thumbdrive is available and ready to use.

So let’s start off with finding the kernel of your Linux machine. To do that type:

# uname -r

2.4.3-20mdk_

The above output shows that for in my case, the Linux kernel version is 2.4.3-20mdk. The letters mdk refers to the Mandrake distribution. Basically all you need to know that the kernel version is 2.4.3

I mentioned earlier that you need to edit the /etc/fstab file. But first take a look at the contents of this file by typing the command:

# more /etc/fstab

/dev/hda4 / ext2 defaults 1 1

none /dev/pts devpts mode=0620 0 0

/dev/hda5 /home ext2 defaults,usrquota,grpquota 1 2

/mnt/cdrom /mnt/cdrom supermount fs=iso9660,dev=/dev/cdrom 0 0

/mnt/floppy /mnt/floppy supermount fs=vfat,dev=/dev/fd0 0 0

/dev/hda1 /mnt/windows vfat user,exec,umask=0,codepage=850,iocharset=iso8859-1 0 0

none /proc proc defaults 0 0

/dev/hda3 swap swap defaults 0 0

The outut shows the the static information about the various filesystems which are mounted.

You can also type the mount command as shown below.

# mount

/dev/hda4 on / type ext2 (rw)

none on /proc type proc (rw)

none on /dev/pts type devpts (rw,mode=0620)

/dev/hda5 on /home type ext2 (rw,usrquota,grpquota)

/mnt/cdrom on /mnt/cdrom type supermount (rw,fs=iso9660,dev=/dev/cdrom)

/mnt/floppy on /mnt/floppy type supermount (rw,fs=vfat,dev=/dev/fd0)

/dev/hda1 on /mnt/windows type vfat (rw,nosuid,nodev,umask=0,codepage=850,iocharset=iso8859-1)

/proc/bus/usb on /proc/bus/usb type usbdevfs (rw,devmode=0664,devgid=43)

Before you edit the fstab file, make a backup copy of the file because if anything goes wrong, you still have the original copy.

# cp -p /etc/fstab /etc/fstab.bak

Now edit the /etc/fstab file. Insert the following line at the bottom of the file.

/mnt/usbking /mnt/usbking supermount fs=vfat,dev=/dev/sda 0 0

What you have done is that to mount the device /dev/sda on to the directory .mnt/usbking. So you must create the /mnt/usbking directory as show below.

# mkdir /mnt/usbking _

Now let’s mount all the filesystem. Type:

# mount -a

Now insert your thumdrive and try to access the device.

# cd /mnt/usbking/

bash: cd: /mnt/usbking/: Input/output error

It gave us an error message. The reason for this is that after you have configured the device you have reboot the system. But before you reboot, you need to insert the thumbdrive. So now insert the thumbdrive and get ready to reboot. But before that you may want to capture the messages log file and grep for usb and sda strings as shown below:

# more /var/log/messages|grep sda

[root@venus /root]# more /var/log/messages|grep usb

Jul 30 07:40:46 venus kernel: usb.c: registered new driver usbdevfs

Jul 30 07:40:46 venus kernel: usb.c: registered new driver hub

Jul 30 07:40:46 venus kernel: usb-uhci.c: $Revision: 1.251 $ time 23:13:16 Apr 15 2001

Jul 30 07:40:46 venus kernel: usb-uhci.c: High bandwidth mode enabled

Jul 30 07:40:46 venus kernel: usb-uhci.c: USB UHCI at I/O 0x6400, IRQ 10

Jul 30 07:40:46 venus kernel: usb-uhci.c: Detected 2 ports

Jul 30 07:40:46 venus kernel: usb.c: new USB bus registered, assigned bus number 1

Jul 30 08:31:18 venus kernel: usb-uhci.c: interrupt, status 2, frame# 602

Jul 30 08:31:18 venus kernel: usb.c: USB device not accepting new address=2 (error=-110)

Jul 30 08:31:18 venus kernel: usb-uhci.c: interrupt, status 2, frame# 851

Jul 30 08:31:18 venus kernel: usb.c: USB device not accepting new address=3 (error=-110)

Now after you inserted the USB thumbdrive and rebooed the system, you can access the thumbdrive by typing:

# cd /mnt/usbking/

[root@venus usbking]# ls

faac-1.24-1.2.fc4.i386.rpm*

festival-1.4.2-25.i386.rpm*

libgcc41-4.1.2_20061115-5.i586.rpm*

libpng-1.2.8-3.i586.rpm*

libpng10-1.0.18-2.i386.rpm*

libpng12-1.2.13-alt2.i586.rpm*

libpng3-1.2.8-1mdk_1.2.8-1mdk.i586.delta.rpm*

libstdc++41-4.1.2_20061115-5.i586.rpm*

libtheora-1.0alpha5-1.i386.rpm*

libtheora-1.0alpha5-41.i586.rpm*

libtheora0-1.0-0.alpha5.0.1.20060mdk.i586.rpm*

libtheora0-1.0-0.alpha5.1mdk.i586.rpm*

libtiff4_3.8.2-7_i386.deb*

lzo-1.08-fr1.i386.rpm*

svgalib-1.9.25-2.fc4.i386.rpm*

termcap-2.0.8-879.i586.rpm*

zgv-5.9-alt1.i586.rpm*)

Take a look at the /var/log/messages file after reboot. The USB daemon was started and the thumbdrive recognized.

# more /var/log/messages | grep usb_

Jul 30 08:37:52 venus usbd: usbd v0.1 © 1999 by Thomas Sailer

Jul 30 08:37:52 venus usbd: Stoping USB daemon succeeded

Jul 30 08:39:57 venus kernel: usb.c: registered new driver usbdevfs

Jul 30 08:39:57 venus kernel: usb.c: registered new driver hub

Jul 30 08:39:57 venus kernel: usb-uhci.c: $Revision: 1.251 $ time 23:13:16 Apr 15 2001

Jul 30 08:39:57 venus kernel: usb-uhci.c: High bandwidth mode enabled

Jul 30 08:39:57 venus kernel: usb-uhci.c: USB UHCI at I/O 0x6400, IRQ 10

Jul 30 08:39:57 venus kernel: usb-uhci.c: Detected 2 ports

Jul 30 08:39:57 venus kernel: usb.c: new USB bus registered, assigned bus number 1

Jul 30 08:39:57 venus kernel: usb.c: USB device 2 (vend/prod 0xa16/0x9780) is not claimed by any active driver.

Jul 30 08:39:57 venus kernel: usb.c: registered new driver usb-storage

# more /var/log/messages | grep sda

Jul 30 08:42:40 venus kernel: Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0

Jul 30 08:42:40 venus kernel: SCSI device sda: 72704 512-byte hdwr sectors (37 MB)

Jul 30 08:42:40 venus kernel: sda: Write Protect is off

Jul 30 08:42:40 venus kernel: sda: sda1 sda2 sda3 sda4_

You can check to see if the USB daemon is running by typing:

# ps -ef|grep usb | grep -v grep

root 609 1 0 08:39 ? 00:00:00 /usr/sbin/usbd -l

root 611 1 0 08:39 ? 00:00:00 [usb-storage-0]_

UNMOUNTING THE USB THUMBDRIVE

If you want to remove the USB thumbdrive, you need to unmount the device first. It is advisable to unmount the device otherwise your files in your thumbdrive may get corrupted. To unmount the device type:

[root@venus usbking]# umount /mnt/usbking/

umount: /mnt/usbking: device is busy

You may wonder why we are unable to unmount the device. This is because when we run the umount command, we are at the /mnt.usbking directory. You must first change directory to / root for example (you must not be in the /mnt/usbking directory), and execute the umount command again.

# umount /mnt/usbking/

[root@venus /root]#

This time you have successfully unmount the device and when you try to access the files in the thumbdrive, it did not list any files.

# cd /mnt/usbking/

[root@venus usbking]# ls

[root@venus usbking]#

To mount back the thumbdrive, type:

# mount -a

You can then access the files in the device as usual.

# ls /mnt/usbking/

faac-1.24-1.2.fc4.i386.rpm*

festival-1.4.2-25.i386.rpm*

libgcc41-4.1.2_20061115-5.i586.rpm*

libpng-1.2.8-3.i586.rpm*

libpng10-1.0.18-2.i386.rpm*

libpng12-1.2.13-alt2.i586.rpm*

libpng3-1.2.8-1mdk_1.2.8-1mdk.i586.delta.rpm*

libstdc++41-4.1.2_20061115-5.i586.rpm*

libtheora-1.0alpha5-1.i386.rpm*

libtheora-1.0alpha5-41.i586.rpm*

The standard form of the mount command, is

mount -t type device dir

This tells the kernel to attach the file system found on device (which is of type type) at the directory dir. The previous contents (if any) and owner and mode of dir become invisible, and as long as this file system remains mounted, the pathname dir refers to the root of the file system on device.

Three forms of invocation do not actually mount anything:

mount -h

prints a help message;

mount -V

prints a version string; and just

mount [-l] [-t type]ë___

Now lets’ explore some of the mount commands.

# mount -h

Usage: mount -V : print version

mount -h : print this help

mount : list mounted filesystems

mount -l : idem, including volume labels

So far the informational part. Next the mounting.

The command is `mount [-t fstype] something somewhere’

Details found in /etc/fstab may be omitted.

mount -a : mount all stuff from /etc/fstab

mount device : mount device at the known place

mount directory : mount known device here

mount -t type dev dir : ordinary mount command

Note that one does not really mount a device, one mounts a filesystem (of the given type) found on the device.

A device can be given by name, say /dev/hda1 or /dev/cdrom, or by label, using -L label or by uuid, using -U uuid ._

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: