LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   Copy files to USB media reader. (https://www.linuxquestions.org/questions/debian-26/copy-files-to-usb-media-reader-661984/)

Charlie Spencer 08-11-2008 08:17 AM

Copy files to USB media reader.
 
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. This is my first attempt to build a production Linux system; my only previous experience is installing Fedora a couple of times for a few weeks. While I've looked at the man pages, I only about half understand what this does.

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 - 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?

There's plenty more to come if I can get past this issue!

kilgoretrout 08-12-2008 12:09 PM

The first text file indicates to me that it was designed to be a bash script, not instructions for sequentially running commands by hand. The echo lines would print out as the script executes the sequence of commands to give feedback on what the script is doing. This is very typical for bash scripts and the echo syntax is exactly what you see in bash scripts.

In general, the procedure in the first text file appears designed to install a linux system of some sort onto a removable storage device and have it be bootable. From your post, you apparently want to run the same procedure from a script from within a running debian system installed on your hard drive. You have somehow determined that the flash card was given the device file /dev/sdb. From here, it's just not clear to me what is going on. Did you successfully run through the sequence of commands with the second text file and afterwards are unable to rerun them on the same flash card or are you unable to run the same commands on a second flash card?

At any rate, with the problem flash card installed in the card reader, post the output of the following command run as root:

# fdisk -l

That will print out every partition recognized by your system.

Charlie Spencer 08-12-2008 12:31 PM

kilgoretrout, here's what I get for 'fdisk -l' after a reboot. Please excuse any typographical errors. I've omitted the results about /dev/hda and included only the /dev/sda results:

Disk /dev/sda: 129 MB, 129024000 bytes
3 heads, 28 sectors/track, 3000 cylinders
Units = cylinders of 84 * 512 - 43008 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2987 125424 83 Linux

I also have something new to add. Originally this flash card showed up as /dev/sdb. Now it appears to be referred to as /dev/sda. Is this assigned at random or is there a way to predict how I should refer to this device?

I have not attempted to run any of this as a script yet. I'm still entering lines manually at the CLI until I'm comfortable with what each one does and that the procedure as a whole is working. Right now it appears it ain't.

Thanks!

tredegar 08-12-2008 02:50 PM

Things that get plugged into USB sockets used to be assigned (pretty much "at random") to the next spare /dev/something. This is still the default behaviour, until you change it to suit your needs.

This led to all sorts of problems like the ones you are experiencing: "I plugged it in, it was mounted at /dev/sda, I unplugged it and plugged it in again, it is not at /dev/sda so where is it mounted now??"

udev (kernel 2.6 and above) was designed to solve this problem. It does a very good job at recognising what has been plugged in and then what should be done with it.

Things get plugged in. udev starts up. It follows a set of "rules" to decide:
- What the device is identifying itself as
- Where to mount the device
- If any symlinks need to be created eg /dev/production_FlashCard
- What to call it
- What permissions should be granted to it
- Any scripts that should be called automatically once it has been recognised and mounted.

Eg when I plug in my camera, a window pops up "Just open in a new window" and "I detected your camera. Import all these photos to /home/me/Photos?" or "Do Nothing".

You can write a udev rule that, when you plug in a blank flash card pops up a window to ask "Do this, that, the other or nothing"

Debian 2.6.18 should cope with all of this.

Here's a good introduction to udev rules:

http://www.reactivated.net/writing_udev_rules.html

udev rules combined with kdialog are brilliant.

Here is an introduction to kdialog:
http://www.linuxtopia.org/online_boo...y.html#kdialog

The above links should give you an idea of what is possible (it is an awesome concept, and is working).

HTH

jschiwal 08-12-2008 03:22 PM

You probably will want to monitor /var/log/messages by running "tail -f /var/log/messages" as root and then inserting the card. It looks like the kernel may not be noticing it. /dev/sda is probably your systems hard drive and not the card. If your computer has a built in card reader, a flash card may use something like /dev/mmc_blk0 instead. It depends on the hardware in your computer, the type of the card and the kernel version you are using.

Make sure you didn't boot up with the "noacpi" kernel boot option. This will interfere with the hal and dbus daemons.

tredegar 08-12-2008 03:51 PM

Quote:

You probably will want to monitor /var/log/messages by running "tail -f /var/log/messages"
Good advice, but isn't that the old way of doing things? (I'm thinking Mandrake 9.1!)
On a 2.6 kernel, these things are easier.

Also I think Charlie Spencer is running in a business environment (did you just edit that bit of your post out Charlie? It (your IT business address) was there before. That's OK though, I understand, my lips are sealed.)

He doesn't want his users to be reading /var/log/messages all the time and issuing cryptic commands depending on what they have read there. He is looking for a simple "Plug the flash card in, click "Install the usual to the flash card", then unplug it".

I think. Maybe I am wrong.

Charlie Spencer 08-12-2008 03:55 PM

Uh, yeah. What you guys said.

tredegar, it's going to take some serious reading before I'll be able to attempt anything with udev. I'm not using the KDE desktop (or any other; right now this is a CLI-only installation) so I don't know if kdialog will benefit me.

jschiwal, when I enter 'tail -f /var/log/messages', what am I looking for? When I first typed it I got several about a dozen lines, all identical except for the time:

Aug 12 09:38;19 DT9053 -- MARK --

Now the cursor is sitting after the last line, not at any apparent prompt. When I insert the card, nothing appeared to happen. I'll Google the 'tail' command tomorrow.

EDITED: tredegar, apparently we have overlapping posts. Yes, this is a business environment. I don't recall removing my business address; heck, I don't even remember including it. All the editing I've done so far is to add additional details; I don't think I've removed anything.

Your description of my end goal is pretty close. Since there's no GUI, replace clicking an icon with entering 'nia'.

tredegar 08-12-2008 04:34 PM

OK
One thing at a time.
Quote:

Now the cursor is sitting after the last line, not at any apparent prompt.
CTRL-c will get you the prompt back.
Quote:

it's going to take some serious reading before I'll be able to attempt anything with udev.
Yes. You get what you read about (or pay for) but it is likely to work :) And we all started thinking "this is maybe waaay to complicated, but I'll just give it a try, and see what happens". I am still here. Happily.

Quote:

I don't recall removing my business address
It's back, in your sig. Maybe a glitch at LQ, or me looking in the wrong place (more likely).

Quote:

Your description of my end goal is pretty close. Since there's no GUI, replace clicking an icon with entering 'nia'.
Good. Once I can understand what you are trying to do, maybe I can help. The more information you give me, the easier is it is for me to help you.

You don't need a GUI for udev to work. But it does make editing files easier. I can use vi but prefer not to. The command line is fine though.

You want to write a script called nia ? OK, weird choice of acronym, but we can do it (fingers crossed).

Please read up on the writing udev rules link I gave you. Don't bother with kdialog as you are not using a GUI.

You should be reading that, thinking "How can I write a rule that identifies what I have plugged in is blank flash-card, and once I have done that, how do I ask udev to run my nia script that does whatever is needed to be done to the flash card".

Then try writing a udev rule.

Leave the complexities of the nia script for later: just make the script say

Code:

#!/bin/bash
echo You plugged in a suitable flash drive! UDEV noticed it and nia was called. Bye.
exit 0

and make it executable.

Test it out. Let us know how you get on.

Charlie Spencer 08-12-2008 05:16 PM

I mentioned the "serious reading" only to alert you and jschiwal that it may be a while before I post anything else.

Is it necessary for udev to call the script? Can't the users just type the name in manually and have it run? 'nia' is the first of two scripts, 'fiu' being the other (not my choices). If udev runs nia whenever it detects flash media, how do I tell it which script to run? The media is identical. It strikes me as easier if the user enters which one to run.

At this point I'm about ready to tell them to key every line in manually and let them deal with the typing errors.

You can make a script executable? I'm carrying a lot of DOS and Windows baggage. I expected the users to be able to run the script similar to the way I'd run a DOS batch file: stick the commands in a file, give it an appropriate name, type the name, press Enter, sit back and watch. Please tell me you're going to get great satisfaction from destroying that ignorant notion.

tredegar 08-12-2008 06:14 PM

It is late here, but here goes, before I sleep:

Quote:

Is it necessary for udev to call the script?
Yes, because the script will not work if it doesn't know where the flash card is mounted, or this location changes (as you have found). udev can take care of this for you, but needs to be told how, for your particular flash card.


Quote:

I'm carrying a lot of DOS and Windows baggage....
If you are carrying baggage, drop it. Or put it in "storage" (Maybe you'll get back to that, maybe not). Life is lighter, and easier.
Quote:

stick the commands in a file, give it an appropriate name, type the name, press Enter, sit back and watch.
No. You have to make the file executable.

Linux doesn't care about .exe or .bat extensions.

Try renaming a .jpg as a .foo
Click on it (but you don't have a GUI)
It opens as a .jpg file in your picture viewer. This is neat because linux knows what files are without them having to be labelled with extensions. [Search Engine: Linux magic numbers for more information, but I doubt you need this right now]

Any file can be executed if it has the "execute permission bit set". It doesn't matter what it is called. You can set this permission with chmod +x filename
Then it is executable, otherwise, it is not.

Quote:

Please tell me you're going to get great satisfaction from destroying that ignorant notion.
Sorry, no satisfaction at all. "Leading horses to water but .."

I get satisfaction from "Thanks, that worked, and I have learnt something".

You need to read up on a lot of stuff, it's educational, and fun when you can make linux work for you: "I made it work" you'll be rightly pleased.

Come back when you have further Q's.

jschiwal 08-13-2008 07:12 AM

When monitoring /var/log/messages, look at whether there are messages including the disk node and the partition node.
For example, here I am pluggin in a 2gb usb pen drive:
Code:

Aug 13 07:00:34 qosmio kernel: usb 8-1.4: new high speed USB device using ehci_hcd and address 24
Aug 13 07:00:34 qosmio kernel: usb 8-1.4: configuration #1 chosen from 1 choice
Aug 13 07:00:34 qosmio kernel: scsi23 : SCSI emulation for USB Mass Storage devices
Aug 13 07:00:34 qosmio kernel: usb-storage: device found at 24
Aug 13 07:00:34 qosmio kernel: usb-storage: waiting for device to settle before scanning
Aug 13 07:00:34 qosmio kernel: usb 8-1.4: New USB device found, idVendor=090c, idProduct=1000
Aug 13 07:00:34 qosmio kernel: usb 8-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Aug 13 07:00:34 qosmio kernel: usb 8-1.4: Product: DISK 2.0
Aug 13 07:00:34 qosmio kernel: usb 8-1.4: Manufacturer: USB
Aug 13 07:00:34 qosmio kernel: usb 8-1.4: SerialNumber: G3X7CRTIRASZ4RCH
Aug 13 07:00:35 qosmio kernel: scsi 23:0:0:0: Direct-Access    USB      DISK 2.0        1219 PQ: 0 ANSI: 0 CCS
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] 7831552 512-byte hardware sectors (4010 MB)
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Write Protect is off
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Mode Sense: 43 00 00 00
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Assuming drive cache: write through
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] 7831552 512-byte hardware sectors (4010 MB)
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Write Protect is off
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Mode Sense: 43 00 00 00
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Assuming drive cache: write through
Aug 13 07:00:35 qosmio kernel:  sdd: sdd1
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: [sdd] Attached SCSI removable disk
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: Attached scsi generic sg3 type 0
Aug 13 07:00:35 qosmio kernel: sd 23:0:0:0: Embedded Enclosure Device
Aug 13 07:00:35 qosmio kernel: usb 8-1.4: reset high speed USB device using ehci_hcd and address 24
Aug 13 07:00:36 qosmio syslog-ng[2122]: last message repeated 3 times
Aug 13 07:00:36 qosmio kernel: sd 23:0:0:0: Failed to get diagnostic page 0x70000
Aug 13 07:00:36 qosmio kernel: sd 23:0:0:0: Failed to bind enclosure -19
Aug 13 07:00:36 qosmio kernel: usb-storage: device scan complete
Aug 13 07:00:36 qosmio hald: mounted /dev/sdd1 on behalf of uid 1000

From this I can tell that the device node for the pendrive is /dev/sdd and for the partition on the drive is /dev/sdd1. I'm thinking that if you see a /dev/sdd but not a /dev/sdd1, you may want to try a different drive and see if the same problem reoccurs. Your system probably already has the udev rules set up and you shouldn't need to edit them. Before a node is created, the kernel needs to detect the device.

The rule will look somewhat like this:
60-persistent-storage.rules:KERNEL=="sd*[0-9]|cciss*p[0-9]", ENV{ID_SERIAL}=="?*", SYMLINK+="disk/by-id/$env{ID_BUS}-$env{ID_SERIAL}-part%n"

A pattern sd*[0-9] from the kernel will trigger this rule, but it there is no such pattern, then the rule won't get triggered. Better not change a udev rule when it may not be the problem.

An external drive may very will have a different device node the next time you plug it in. That is why it is better to use the UUID number or LABEL if you create an fstab entry. However, you said that you saw /dev/sda. If you are using a recent kernel, ide and scsi drives both have /dev/sd# designations, so the /dev/sda drive is probably your boot drive, and the pen drive isn't showing up at all.

fhleung 10-03-2008 07:45 AM

howto card reader -- SD and other media
 
There are many different media slot in a card reader. For SD card, I can read data by
Code:

mount /dev/sda1 /mnt/<directory>

What about other card sony MS and XD? Who ever sucessfully mount these cards?

fhleung 10-09-2008 02:28 PM

Who able to use Sony MS, XD or compact flash media in Linux?

I can do mount for SD but not other cards (having kernel version 2.4)

Quote:

Sony MS (not work)
Compact flash (not work)
XD (not work)

farslayer 10-09-2008 03:15 PM

mine come up as

/dev/sdb1
/dev/sdc1
/dev/sdd1
/dev/sde1

Each slot on the card reader is a different drive.

Issue the following command before you plug in your card reader and you should be able to see the assignments given to the card reader.

tail -f /var/log/messages

Code:

it-etch:~# tail -f /var/log/messages

Oct  9 15:31:53 it-etch -- MARK --
Oct  9 15:51:53 it-etch -- MARK --
Oct  9 16:11:54 it-etch -- MARK --
Oct  9 16:14:02 it-etch kernel: ohci_hcd 0000:00:13.3: wakeup
Oct  9 16:14:02 it-etch kernel: usb 4-1: new full speed USB device using ohci_hcd and address 12
Oct  9 16:14:02 it-etch kernel: usb 4-1: configuration #1 chosen from 1 choice
Oct  9 16:14:02 it-etch kernel: scsi12 : SCSI emulation for USB Mass Storage devices
Oct  9 16:14:07 it-etch kernel:  Vendor: ICSI      Model: SD Card          Rev: 2.7C
Oct  9 16:14:07 it-etch kernel:  Type:  Direct-Access                      ANSI SCSI revision: 00
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:0: Attached scsi removable disk sdb
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:0: Attached scsi generic sg1 type 0
Oct  9 16:14:08 it-etch kernel:  Vendor: ICSI      Model: CF Card           Rev: 2.7C
Oct  9 16:14:08 it-etch kernel:  Type:  Direct-Access                      ANSI SCSI revision: 00
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:1: Attached scsi removable disk sdc
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:1: Attached scsi generic sg2 type 0
Oct  9 16:14:08 it-etch kernel:  Vendor: ICSI      Model: SM Cad           Rev: 2.7C
Oct  9 16:14:08 it-etch kernel:  Type:  Direct-Access                      ANSI SCSI revision: 00
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:2: Attached scsi removable disk sdd
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:2: Attached scsi generic sg3 type 0
Oct  9 16:14:08 it-etch kernel:  Vendor: ICSI      Model: SM Card           Rev: 2.7C
Oct  9 16:14:08 it-etch kernel:  Type:  Direct-Access                      ANSI SCSI revision: 00
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:3: Attached scsi removable disk sde
Oct  9 16:14:08 it-etch kernel: sd 12:0:0:3: Attached scsi generic sg4 type 0


fhleung 10-12-2008 02:02 AM

USB card reader modules in linux 2.4.xx
 
The reason I can not mount card reader drives is:

I having kernel version 2.4.xx with NO usb_storage, scsi_mod, sd_mod etc
I'd like to keep the older version I having.


Can I just insert the module files .ko for card reader (usb_storage,scsi_mod,sd_mod) copy from version 2.6 to 2.4 ?
Do I need a newer kernell version then customerise/re-compile the things inside?

fhleung 10-16-2008 01:34 PM

Who able to use Sony MS, XD or compact flash media in Linux 2.4.xx?

This thread topic is about copy read files to USB media reader.

Wellcome human to post reply to this topic.

I think using card reader in Linux deian belong to this topic.

tredegar 10-16-2008 04:46 PM

You have several problems:

1] You have hi-jacked this thread.
2] You are talking to yourself (see [1], and previous posts, by yourself)
3] You are running an "old" kernel, which very few people have any interest in: things move on, and improve, and generally "get better" with newer kernels, Eg kernel 2.6.xx
Quote:

I having kernel version 2.4.xx with NO usb_storage, scsi_mod, sd_mod etc
I'd like to keep the older version I having.
Ok, keep it, if that is what you want, but things are changing fast with linux, and improving all the time. I don't have the time, or inclination to back-port all this stuff to a person who is complaining that "it doesn't work on my 2.4.xx kernel".
If you choose to install the latest stable kernel you will find many improvements.

Please try to keep up to date: You are the equivalent of someone saying "I am running MS-DOS 3.0 and I cannot use the internet. I want to keep MS-DOS 3.0, but still want firefox."

Please wake up!

Quote:

Who able to use Sony MS, XD or compact flash media in Linux
Many sony media devices are intentionally "closed source". Sony will not reveal how these devices are to be accessed. So I don't use them. (I have a sony laptop, and the SD slot will not work with any linux distribution, because the driver / module is owned by, and private to sony, and not usable, open-source, or yet fixable by the linux community.

Please just deal with it, and stop complaining at us for help in solving your problems.

Instead you should direct your complaints directly to sony.
It is their fault that this doesn't work with linux.


All times are GMT -5. The time now is 04:26 AM.