Re: USB Memory key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alex Tang wrote:
Hi folks.

I've got a working kickstart installation, however in the %post section, i would like to detect, mount, and write to a USB memory key.

However, I can't seem to detect the memory key properly. Does the standard anaconda kernel support USB? Is there something else I need to do?

Thanks

...alex...

In the USA we have Labor Day and many stores have Labor Day sales. I went and purchased an USB Thumb Drive and 9-in-1 Flash Media Reader/Writer. This was an interesting question so I had to answer it for myself. Hopefully, it will answer your questions too. More importantly, it also gave me a reason to finally buy these contraptions. ;-)

If you can find a device that is USB 2.0 and compatible with USB 1.1 and also complying with USB Storage Class specification version 1.0, then the device should work with Linux. The Memorex TravelDrive had this stated on the back of the blister pack. The packaging also said it would work with Linux 2.4.x and above. The PPA Internaltion http://www.ppa-usa.com/product_pages/cardreaders/2285.htm Media Reader did not mention Linux but it had all the same specs as the Memorex drive. Both drives correctly worked with a working FC2 machine as well as with Anaconda during install. Oh! I do not work or represent nor have I received any money for research from these companies! They were just the best value for the specifications above.

The difference between these two USB devices as per the salesperson is that the USB thumbdrive can be booted from by most modern motherboards. The USB thumbdrive is also supposed to be faster device. So says he...I don't know.

So far I can answer that the FC2 Anaconda kernel has USB support. At the Fedora Boot: prompt I hit enter. After I hit enter the kernel boots. Finally I briefly see the message "loading usb-storage driver" that is displayed by the Anaconda loader. After this I see the media test screen--"CD Found...To begin testing the CD media..." I hit enter and wait for the "Welcome" screen. At that point you can use the <Alt><Ctrl><F2> keys to access a bash prompt. The bash shell let me poke around.

I have already seen usb-storage drive message now I was curios what dmesg said. Here's the output:

<snip>
usbcore: registered new driver hiddev
usbcore: registered new driver hid
drivers/usb/input/hid-core.c: v2.0:USB HID core driver
<snip>
SCSI subsystem initialized
ohci_hcd: 2004 Feb 02 USB 1.1 'Open' Host Controller (OHCI) Driver (PCI)
ohci_hcd: block sizes: ed 64 td 64
ohci_hcd 0000:00:02.2: OHCI Host Controller
ohci_hcd 0000:00:02.2: irq 10, pci mem e0831000
ohci_hcd 0000:00:02.2: new USB bus registered, assigned bus number 1
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 3 ports detected
ohci_hcd 0000:00:02.3: OHCI Host Controller
ohci_hcd 0000:00:02.3: irq 5, pci mem e0833000
ohci_hcd 0000:00:02.3: new USB bus registered, assigned bus number 2
hub 2-0:1.0: USB hub found
hub 2-0:1.0: 3 ports detected
usb 1-1: new full speed USB device using address 2
usb 2-1: new full speed USB device using address 2
Initializing USB Mass Storage driver...
scsi0 : SCSI emulation for USB Mass Storage devices
  Vendor: Generic   Model: USB Storage-SMC   Rev: I03A
  Type:   Direct-Access                      ANSI SCSI revision: 02
Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
  Vendor: Generic   Model: USB Storage-CFC   Rev: I03A
  Type:   Direct-Access                      ANSI SCSI revision: 02
SCSI device sdb: 250368 512-byte hdwr sectors (128 MB)
sdb: assuming Write Enabled
sdb: assuming drive cache: write through
 sdb: sdb1
Attached scsi removable disk sdb at scsi0, channel 0, id 0, lun 1
  Vendor: Generic   Model: USB Storage-MMC   Rev: I03A
  Type:   Direct-Access                      ANSI SCSI revision: 02
Attached scsi removable disk sdc at scsi0, channel 0, id 0, lun 2
  Vendor: Generic   Model: USB Storage-MSC   Rev: I03A
  Type:   Direct-Access                      ANSI SCSI revision: 02
Attached scsi removable disk sdd at scsi0, channel 0, id 0, lun 3
USB Mass Storage device found at 2
scsi1 : SCSI emulation for USB Mass Storage devices
  Vendor:           Model: Memorex TD 2B     Rev: PMAP
  Type:   Direct-Access                      ANSI SCSI revision: 02
SCSI device sde: 487424 512-byte hdwr sectors (250 MB)
sde: assuming Write Enabled
sde: assuming drive cache: write through
 sde: sde1
Attached scsi removable disk sde at scsi1, channel 0, id 0, lun 0
USB Mass Storage device found at 2
usbcore: registered new driver usb-storage
USB Mass Storage support registered.
<snip>

Note that I attached both the 9-in-1 reader and the thumb drive to the system. There's your first obstacle to detecting the correct drive. I don't know how the kernel orders the device names for these storage devices. I don't recall the order I had these installed earlier in the day. Hence, I don't know if switching USB port that the devices were plugged into would make a difference. It appears that the "Initializing USB Mass Storage driver..." message is the key. Once that is displayed the kernel starts assigning device names. The Memorex drive received sde:sde1 while the 9-in-1 reader received four scsi device names, sda:sda1 through sdd:sdd1. If you have other scsi devices on the system, then this could complicate your detection code.

As an aside, this ordering of device names would affect your kickstart stanza. If you only had one usb-storage device on your system, then you would use

ks=hd:sda1/ks.cfg

to locate the kickstart file. However, in the example above with two readers on the system and five device names, I would use either

ks=hd:sdb1/ks.cfg

for the CompactFlash card or

ks=hd:sde1/ks.cfg

for the thumbdrive.

If just a thumbdrive is attached to an Anaconda kernel then you will see this in the dmesg output.

<snip>
Initializing USB Mass Storage driver...
scsi0 : SCSI emulation for USB Mass Storage devices
  Vendor:           Model: Memorex TD 2B     Rev: PMAP
  Type:   Direct-Access                      ANSI SCSI revision: 02
SCSI device sda: 487424 512-byte hdwr sectors (250 MB)
sda: assuming Write Enabled
sda: assuming drive cache: write through
 sda: sda1
Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
USB Mass Storage device found at 2
usbcore: registered new driver usb-storage
USB Mass Storage support registered.
<snip>

The thumbdrive now has a device name of sda:sda1.

If I use fdisk -l /dev/sda then I will see this output.

Disk /dev/sda: 249 MB, 249561088 bytes
16 heads, 32 sectors/track, 952 cylinders
Units = cylinders of 512 * 512 = 262144 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         952      243696    6  FAT16

(Note that when the 9-in-1 reader was attached, the fdisk output looked like this for a 128MB CompactFlash card.

fdisk -l /dev/sdb

Disk /dev/sdb: 128 MB, 128188416 bytes
8 heads, 32 sectors/track, 978 cylinders
Units = cylinders of 256 * 512 = 131072 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         978      125168    6  FAT16 )

It appears that FAT16 is used on these devices for compatibility purposes. A CompactFlash card in the 9-in-1 reader/writer also shows as FAT16. I bet Microsoft saw a cash cow here and wanted to license FAT http://www.eweek.com/article2/0,1759,1569534,00.asp. Anyhow, the Anaconda kernel also recognizes FAT16. So you can mount the drive as

mkdir /tmp/td
mount /dev/sda1 /tmp/td

   or

mkdir /tmp/td
mount -t vfat /dev/sda1 /tmp/td

I selected /tmp because Anaconda mounts other devices used in the install process under /tmp. It appears that /mnt is saved for the live hard drives that you will be updating or installing the distribution on.

Depending on where you create your mount point, in my case it is /tmp/td, then writing to the thumbdrive is as simple as

   cp mylogfile.log /tmp/td

In bash you could use

   dmesg > /tmp/td/dmesg.txt

In any scripting language you could just open a file on the mount point. In Python it may be something like this

   tdoutput = open(/tmp/td/tdoutput, 'w')
   tdoutput.write(...)
   tdoutput.close()

Your most pressing problem is selecting the correct scsi device name should multiple scsi devices be configured on your target install system. This could include cameras, thumbdrives, media readers, scanners, and gasp a parallel port zip drive. Let's not forget scsi hard drives or cd-rom drives. If you know your only scsi device is the thumbdrive, then /dev/sda1 is all you need.

If you are trying to make the Anaconda Kick Start file work on multiple machines, then one file may be helpful. This is the /tmp/scsidisks file. With both the 9-in-1 reader and the Memorex TravelDrive attached to the FC2 install target machine, the contents of the file looked like this

sda	usb-storage
sdb	usb-storage
sdc	usb-storage
sdd	usb-storage
sde	usb-storage

With just the Memorex TravelDrive, the file looked like this

sda	usb-storage

If you are not doing something twisted like I did with two usb-storage devices attached to the PC, then you could just look for the usb-storage line. I checked that sed, awk, cut, bash, and python are available to you in the Anaconda runtime environment on FC2. A tab separates the device name and usb-storage literal string. I do not know how portable this approach would be from one Red Hat distro/version to the next. Other people may be able to provide you with another approach. With that said, "I leave the thrill and joy of discovering the rest of the solution to you."

Greg Morgan



[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux