Modify Linux commands to use Kingston Flash Media reader.

By CharlieSpencer ·
One of our locations performs the following process to program flash memory cards. They boot a laptop from a Knoppix CD and type the commands in one at at time. I'm trying to build a desktop to accomplish the same task, but I want to boot from the hard drive and put all the commands in one file. I'm using Debian 2.6.18-6-686 and a Kingston FRC-HS219 6-in-1 media reader.

The original procedure is below, as copied from a Word file. I'm not sure why they documented each command with 'echo' lines; maybe the contents of the Word file were copied from a now-lost command file. I've numbered each line here to make it easier to
reference them; the numbers are not part of the actual commands I'm entering.

echo ?Mount the Linux hard drive to the Knoppix?
1. mount /dev/hda3 /media/hda3
echo ?Move to the Linux Root folder containing the image file?
2. cd /media/hda3/root
echo ?Burn the image file to the Compact Flash Card?
3. dd if=nia-720.img of=/dev/hde
echo ?Move to the folder containing the installation file?
4. cd niafs720
echo ?Format the Compact Flash Card?
5. sfdisk -f /dev/hde <blank.part> /dev/null
6. sfdisk -f /dev/hde <128mb1.part> /dev/null
echo ?Make file system?
7. mkfs.ext3 /dev/hde1
echo ?Mount the device, IMPORTANT: must specify file system type be ext3?
8. mount ?t ext3 /dev/hde1 /mnt/hde1
echo ?Install NIA software?
9. tar ?zxf instimage.tgz ?C /mnt/hde1
10. rm ?rf /mnt/hde1/var
11. tar ?zxf uss.tgz ?C /mnt/hde1
echo ?Change the root folder to the Compact Flash Card and run the lilo configuration?
12. chroot /mnt/hde1
13. lilo ?v 3 ?C etc/lilo.config
echo ?Exit and umount the Compact Flash Card?
14. exit
15. umount /dev/hde1

Here's what I've got so far. I've determined the appropriate slot in the media reader is /dev/sdb. I created a /mnt/sdb1 directory. I copied nia-720.imp and the niafs720 directory from the original machine into /home. I deleted the first line entirely since it shouldn't be necessary to mount the HD when I'm booting from it.

2. cd /home
3. dd if=nia-720.img of=/dev/sdb
4. cd niafs720
5. sfdisk -f /dev/sdb <blank.part> /dev/null
6. sfdisk -f /dev/sdb <128mb1.part> /dev/null
7. mkfs.ext3 /dev/sdb1
8. mount -t ext3 /dev/sdb1 /mnt/sdb1
9. tar ?zxf instimage.tgz ?C /mnt/sdb1
10. rm ?rf /mnt/sdb1/var
11. tar ?zxf uss.tgz ?C /mnt/sdb1
12. chroot /mnt/sdb1
13. lilo ?v 3 ?C etc/lilo.config
14. exit
15. umount /dev/sdb1

Problem 2. I have been able to execute line 3 only one time. After testing the rest of the procedure, line 3 now returns:
dd: opening '/dev/sdb': No medium found. How do I reset this card so I can refer to it as /dev/sdb again?

SOLVED BY SEANFER Problem 1. The system will not boot if the USB flash media reader is connected. Instead it gets so far (I don't know how to tell; advice, please) and then does a hard reboot on it's own. It boots okay if I disconnect the media reader before booting. What do I have to do to allow the system to boot with the media reader attached?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Booting: BIOS?

by seanferd In reply to Modify Linux commands to ...

Is BIOS trying to boot from a removable device first, where the reader is somehow indicating that it is capable of booting the system, but isn't?

Collapse -

Well, DUH!

by CharlieSpencer In reply to Booting: BIOS?

Sorry, I've been unable to see the forest for the trees. What confused me was that I was seeing output from a Linux boot process and assumed it was the hard drive, but apparently it was coming from the flash card. I checked the BIOS and sure enough, the hard drive was after any USB drives.

One down.

Edited - seanferd, I removed the "Thumb" because I didn't want future readers to think all the problems are solved. You've earned it and I'll put it back later after I get replies to the complete project.

Collapse -

Would you need to delete the patition table?

by seanferd In reply to Modify Linux commands to ...

Once formatted, do you need to wipe the format with sfdisk, or dd to sdb1 rather than sdb?

Perhaps if you step through the procedure at the command line, rather than through the script, you may get more feedback on what is happening, as scripted commands seem to abort silently. You could also check the partitions with sfdisk (man sfdisk for your options)to see what's up.

I'm just shooting in the dark here, I'm no unix guru, as evidenced by the fact that I'm completely baffled by the procedure: copy file > partition > format > install.

Collapse -

WTF? Now media reader shows up as /sda instead of previous /sdb!

by CharlieSpencer In reply to Would you need to delete ...

I am stepping through it one command at a time. While a script is my final goal, I haven't created it yet.

I'm glad to see I'm not the only one confused by the timeline. Unless the 'echo' lines are incorrect in their descriptions, I also interpret it as copying before partitioning. I've been unable to get answers from the other location. I suspect whoever developed the script is not with the company and those using it there have even less understanding than I.

I tried an sfdisk -s; the media reader slot that showed up as /dev/sdb last week is listed as /dev/sda. At least I assume /dev/sda is referring to the flash media since I'm unaware of any other 128 meg device attached.

So now I have a new problem: what is causing the /dev assignment to change and how can I lock the slot into one assignment?

Collapse -

I have that same issue

by Neon Samurai In reply to WTF? Now media reader sh ...

USB devices tend to get issued whatever mount point they join the chain at. If you use different USB sockets, it's even worse.

I'm told this is actually a bug with some distros. Mandriva seems to have pretty much got it working right (my usb flash mounts to /media/fda1 consistantly these days).

My way to work around it was to remove the usb during boot so that KDE could spot the new device and mount it as KDE prefered.

My previous work around was to use the device label instead. Look in your /dev and you should spot a /dev/by-id, /dev/by-label and two or three other options. I was able to setup a quick mount command that grabbed the usb flashdrive by-label ("fda1" is the partition label for my drive) and mount it explicitly where I wanted it.

(Work machine is Windows else I'd give you some screen shots)

Collapse -

KDE not a factor; /dev/whatyoutalkingboutWillis ?

by CharlieSpencer In reply to I have that same issue

I'm doing all this from the CLI.

I'd prefer to leave the media player connected permanently. This is a production system for the factory floor. It will be easiest on those using the system if they don't have to keep straight the boot / connect sequence. Another reason is the box I'm using has it's USB ports only on the back.

I'm not sure what you mean by "Look in your /dev and you should spot a /dev/by-id, /dev/by-label ..." I did a 'cd /dev' followed by 'ls b*' but apparently wild cards don't work the way I expect; the only result was a single line with 'usb' on it.

Collapse -

ha.. now I'm at home and can actually answer questions

by Neon Samurai In reply to KDE not a factor; /dev/wh ...


If you've this virtual tree in your dev, you may be able to consistently mount using one of the identifiers form the subdirectories.

You also mention that the process will be used for new media so by-label may be out. With the reader remaining attached, it shouldn't cause an issue provided the system responds to the media being inserted in the reader.

Hm.. what do the fresh media present if you stuff one of those in the reader? You may not get consistant identifiers but you can at least confirm that they are being added to the by-* directories to start.

("locate by-label" would have found it also but I didn't think to suggest that earlier.)

Collapse -

Three out of four ain't bad.

by CharlieSpencer In reply to ha.. now I'm at home and ...

I've got


I don't have /dev/disk/by-label.

None of the file names in /by-path or /by-uuid mean anything to me. However, there are two entries in the /by-id that appear to be relevant:


Is either of these related to the solution?

"...what do the fresh media present if you stuff one of those in the reader?"

I don't understand what you mean by 'present'. Can you translate that into a command I can enter?


Collapse -

hm.. progress it seems

by Neon Samurai In reply to Three out of four ain't b ...

In *nix, everything is a director and file. /proc is actually a non-existant directory tree generated out of the kernel. Your litterally going inside the running kernel and poking around when you do a "ls /proc" or more "/proc/cpustatus". In like fashion, /dev/disk/*/usb-Kingston* is a file representing that device through a link back to the actual device reprsented by /dev/sd*.

Ignore that bit if it's just repeat information.

The plan is to find a consistant identifier for the item on the dynamicaly assigned USB bus so my thinking was that you may find something in that /dev/disk tree.

"what do the fresh media present if you stuff one of those in the reader"

cd /dev/disk

remove the media reader

ls -l ./by*

see what identifiers are there (the usb-King* thing)

Attach the reader without media in it and repeat. See whatnew identifiers apear (my understanding is that HAL should do so).

Insert the media and repeat again. See if new identifiers apear for the media in the reader.

Between the reader and the media, see if there is a consistant identifier or how much consistancy you can find between two different "disks" inserted into the reader.

I'm not yet sure how to modify your script to have it use a "mostly" consistant identifyer for the disk yet but this get's you a step closer.

I would then do some mounting of those by* identifiers with a formatted bit of media to confirm which identifers map to where you

md /mnt/test
mount /dev/disk/by*/usb-King* /mnt/test
ls /mnt/test
(are these the droids you are looking for?)

umount /mnt/test
mount /dev/disk/by*/usb-King*[otherone] /mnt/test
ls /mnt/test
(are these the droids you are looking for?)

If one of those Kingston identifiers is consistantly gets you the media partition mounted; you have something you can script against.

If the inserted media add more identifiers then you need to confirm what degree of consistancy you have between them based on what mounts your preformatted one properly. You then have something to script against but not as easily as the first case.

(My USB media tends to be repeat use rather than one time write on ongoing fresh media but I do like the puzzle. I suspect it'll be one of those "well that was bloody easy" things in the end too but like any learning; it's a pig to do the first time.)

Another thought that won't work but I gotta mention. If it's a factory floor; there may be benefit in considering a minimal X interface. Insert media, pointy-clicky the [go] button. remove the media whent it says "done and unmounted".

(I'm sure other's know a more clean way to get through this the first time but I'm more a "hack away at the keyboard until it does what you want" type with any system.)

Collapse -

Disconnecting and connecting update.

by CharlieSpencer In reply to Three out of four ain't b ...

I'm omitting the 'ata-MAXTOR' results that I assume apply to the HD. After removing the media reader:

cd /dev/disk/by-id

No usb-Kingston entries. Reattached the media reader with no flash card:


Inserted a flash card in the reader:


No new entries; specifically, no 'usb-Kingston_FRC-HS219.1_000003537-part1'. If I had to guess I'd say it isn't seeing the flash card. Unfortunately I only have one flash card to play with.

I'll get back with you on the 'mount' tests.

Related Discussions

Related Forums