Question Locked

Modify Linux commands to use Kingston Flash Media reader.

0 helpful
40 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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 /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 /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 SEANFERD: 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?

40 replies

by seanferd

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?

by charliespencer

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.

by seanferd

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.

by charliespencer

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?

by neon samurai

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)

by seanferd

It's starting to sound like one of those Windows/USB ports things.

by charliespencer

I'm getting nothing in the Debian forums of either Linux Forums or Linux Questions. So much for the much touted "community support". Looks like the only community is this one.

by neon samurai

I much prefer when it is not and it's not been close to the definitive /. battlegrounds. I'd have to read your posts in the forums and probably lurk a little to get to know them. I've always got into them through google finding similar issues and solutions.

I hear Mandriva's forums are good and I've been surprised at some of the quick turnarounds for my own questions in the Maemo forums. I've also had ignored posts; usually questions I solve myself a day later and go "oh bloody hell, why didn't I get that sooner, it's so easy."

(I asked how one sorts the menu entries. Windows has sort by name, KDE seems to just do it that way by default, Hildon left the menu entries in first come, first listed order. An hour later I acidentily dragged an entry above another instead of too a different directory and Tadaa.." I'm not saying your questions where the same type of case.)

by charliespencer

Their internal search engine is down:

http://search.debian.org/

I've tried searching the web for various combinations of usb, media, flash, reader, player, debian, /dev, /sda, /sdb, etc. Most of what I get is sites trying to sell USB devices. I also get people trying to download music to or from thumb drives. I haven't found anybody trying to do anything like what I'm attempting, but maybe I'm not using the right search terms. I've got the original problem description in a text file, but I've run out of ideas about where else to post it.

I have confirmed the person who developed the original procedure has left the company. The guy I've been working with is glacially slow to respond to requests but makes up for it by appearing to know less about Linux than I do. He definitely doesn't know why I'm dd'ing a .img file to the flash media and then apparently destroying it by partitioning.

by neon samurai

To confirm I'm finally caught up; is the issue that your flashdrive is not being mounted to the same location each time?

You put the drive in and it's /dev/sda. You put the drive in again and it's /dev/sdb with all your scripts now brokenly pointing at /dev/sda?

I'll go back and read the initial post to see if you detailed what the actual process is outside of the notes posted. If it's not there, what is the overall function? You take a clean/used flashdrive, and replace the contents with updated contest? (I'm thinking certs kept on flashdrive for dual authentication maybe?)

by charliespencer

I'm still trying to get consistent results when I enter each command manually.

Yes, at the moment the issue is that the flash media doesn't appear to consistently called the same thing. Once it was /sdb; now it's /sda.

In the long run we'll be taking clean flash media and adding content. Replacement or reuse will not be an issue. Once the files are written to it, the flash card is installed in one of our products and shipped to the customer.

by neon samurai

"I'm not sure why they documented each command with 'echo' lines"

I'm guessing they copied an existing bat file or script to the word document. If run as an executable, the given list would anounce what it is doing then perform the action; potentially with little visible output returned.

This is an interesting puzzle you've got though. I'll be watching how it goes and will give the post a more detailed read later when time permits. I'm not sure that I can add to what other's have probably suggested already but we'll see.

by charliespencer

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.

by neon samurai

/dev/disk/by-id
/dev/disk/by-label
/dev/disk/by-path
/dev/disk/by-uuid

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.)

by charliespencer

I've got

/dev/disk/by-id
/dev/disk/by-path
/dev/disk/by-uuid

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:

usb-Kingston_FCR-HS219.1_000003537
usb-Kingston_FCR-HS219.1_000003537-part1

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?

Thanks.

by neon samurai

So you basically need a media reader slot and a button that runs the scripts to do the prep work. I think I'm all caught up now and left some notes in the previous comment.

Consistant location mounting of USB media is one of the things I'd like to see done more cleanly. Nothing as drastic as mounting to letters, just more consistant. It's probably more my lack of learning about it though.

Anyhow, confirm that you have the /dev/disk/* directories and see if there is a common way to identify the new media device as it's picked up. Hopefully, one of those directories is showing the non-changing reader identifier.

by neon samurai

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.)

by neon samurai

So, hypothetically, you get the script mounting consistantly and running clean.

You could even drop each command into it's own chmod 700 file so you can simply modify the command line until each step works right on it's own then:

(if cmd01, cmd02, cmd03 as names)
cat cmd* > script01

To compile the single command scripts into your final script.

But, the "more automation" idea. Once the script runs clean and consistantly. You could even add a cron job that checks for the disk identifier every few seconds.

a. If it exists, run the script.

b. If it exists and the user pressed "continue" (spacebar, Y.. whatever), run script.

c. If it exists and is not already written, rn script.

Option A is easy to setup but will wipe and rewrite your media every few seconds. That may eat the write limit of the flash chips while your worker is at lunch.

Option B gives you the user confrimation that this is a new disk and should be written.

Option C goes more the automation route with various ways to confirm that a new media has been inserted. You could even automatically start the process then have a confirmation at the end saying "please remove media and press any key". That would keep the scripts PID active which gives you somethign to run the scripts if statement off of. (if PID exists, end else, step through commands)

by charliespencer

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

cd /dev/disk/by-id
ls

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

ls
usb-Kingston_FRC-HS219.1_000003537

Inserted a flash card in the reader:

ls

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.

by charliespencer

You lost me at 'chmod 700 file'. From there it was down an icy hill on a greased banana peel

by neon samurai

I wish my knowledge would catch up to my imagination
most days.

Short answer; chmod changes permissions and 700 makes
the file executable, readable and writable for the file
owner only. If the file has executable permissions than it
can do stuff else it's just a text file.

ok. briefly, chmod is your command to change the
security settings on a file or directory. Change Mode is the
long name I believe. You also have chown and chgrp.

(Linux in a Nutshell would be a good book to browse
through at your chapters too; great command reference)

So, with chmod you change a files user
read/write/execute, or group, or anyone (reading left to
write). You can do this two ways; by letter or by number.

chmod u+x u+w u+r filename
chmod 700 filename

In the first case, you specify granting the user execute
permissions turing a text script into an executable script.
You write the .bat file then you have to allow the .bat file
to actually run commands in Windows lingo.

In the second case, you are doing the same but with a
numeric value. The file permissions you'll see with ls -l
are rwxrwxrwx. The first three are User, the second are
Group the third three at furthest right are anybody on the
system. This can also be indicated numerically as
421421421 a-la age old binary counting:

700 = user read/write/exec, no group permissions, no
any permissions = rwx------. if permissions exist for
group or user, they are removed. For a folder, the owner
can enter it, read files within it or write files within it. For
a file, the owner can execute it, read or write it.

777 = rwxrwxrwx. Everybody can do what they like with it.
it's just a bad idea in general unless it's trully an
"everybody" area you chmod'ing.

600 = rw-------. owner can read/write but no one else.

644 = rw-r--r--. Owner can read/write, all others can
only read.

man chmod will give you all the gory details.

chown and chgrp are two other commands you'll want to
have basic familiarity with. Change owner and change
group. I tend to use chown more than chgrp simply
because I can change bot user and group with it.

chown username:groupname filename

In a user's home directory, it can be handy to do a:

chown -r username:group ./*

That recursively insures that the user owns everything
under there home directory. I frequently move crap to my
home directory using the root command so giving my
user account ownership is required before I scp whatever
it is back to my local machine or send something the
other direction.

As for my wild ideas:

- the sript alone can be started manually in it's current
form leaving the intelligence too the operator.

- the script could take on some of the intelligence by
confirming that a disk is there and asking the user if it
should proceed. This would be using the script as a cron
job with a "press any key to continue" pause.

- the script could be mostly automated with intelligence
in the third case where it confirms if it is still working on
a disk or if the disk is new and needing to be imaged still.
it then takes on all intelligence except telling the operator
that the disk is ready. That's probably where you want to
be aiming for but the latter two ideas take me a bit of
learning to go from concept to actual code.

by charliespencer

I've had a couple of other items take precedence. I'll return to this project next week.

Edited - and apparently I'm better than I thought since both of them are out of the way. See 'Starting Over' below for the lastest! I'm in danger of making actual progress!

by charliespencer

I reloaded Debian this afternoon. This time I took the 'Desktop' option and wound up with the Gnome GUI. I also set up the network connectivity and our proxy server, so now I don't have to manually enter results on my Windows box to post to the Internet.

It looks like the media reader is consistently appearing on /dev/sda. At this point I've decided to assume it will continue to do so and move on. Here's what I've got so far, entered at a command prompt as root:

# cd /home
# dd if=nia-720.img of=/dev/sda
# cd niafs720
# sfdisk -f /dev/sda /dev/null
Checking that no-one is using this disk right now ...
BLKRRPART: Device or resource busy
This disk is currently in use - repartitioning is probably a bad idea.
Umount all file systems, and swapoff all swap partitions on this disk.
.
.

And some other stuff. So

# mount -l
/a bunch of other apparantly unrelated entries
/dev/sda1 on /media/usb0 type ext3 (rw,noexec,nosuid,nodev)

I didn't mount this manually so something else must have.

# umount /media/usb0
# sfdisk -f /dev/sda /dev/null
# sfdisk -f /dev/sda <128mb1.part> /dev/null
Checking that no-one is using this disk right now ...
OK
Warning: The partition table looks like it was made
for C/H/S=*/3/28 (instead of 1016/4/62).
For this listing I'll assume that geometry.
start: (c,h,s) expected (0,1,5) found (0,0,33)
end: (c,h,s) expected (1023,2,28) found (1011,2,28)
Warning: partition 1 does not end at a cylinder boundary
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes: dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

So at this point I've got a bunch of new questions.
1) Should I assume I need to 'umount /media/usb0' every time and stick a line in my procedure

2) My understanding of sfdisk is it's a partition management tool, but the man page doesn't do a good job of explaining the parameters. Are the two commands setting up two separate partitions, or is the second one overwriting what the first one did? What roles do '', '<128mb1.part>', and '/dev/null' play? There are two files in the niafs720 directory with the same names as the .part parameters, so I assume the sfdisk commands are doing something with them, but I can't figure out what. Also, I thought /dev/null was a null device, but I can't tell what role it's playing here.

3) If the sfdisk is partitioning the flash media, are the results of the initial 'dd' command being lost?

4) While we found entries in /dev/disk/by-id and /by-uuid that appear to correspond to the media reader, I'm unclear what I'm supposed to do with them.

5) Are the warnings displayed after the second 'sfdisk' command anything I need to be concerned about?

That ought to be enough to let me keep Google's servers thrashing this weekend.

by seanferd

That may be because you've reformatted it more than once, and made it bootable (if you got that far in the list of commands). Just a guess, but maybe you should zero those first 512 bytes if that is the boot sector, then step through the script.

I don't know what you've read up on, but FYI, in the dd command if= in file, and of=out file (source, destination). Just thought I'd mention it.

No idea what's up with the CHS mismatch if it isn't offset by the boot sector.

by neon samurai

In my defense, I've been spoiled by the draktools disk manager. It presents a great graphic display of hard drives and USB storage for managing partitons, mount points and mount permissions. I even slap Mandriva Free in ahead of other OS installs so I can cancel out of the custom install right after the disk manager writes the partition table. GNU Parted is more the defacto GUI partition manager which can be had easily with the GParted liveCD or Parted Magic liveCD (meant as disk management liveboot rather than my Mandriva installer method). I noticed the sfdisk man page listed GNU Parted so that's my bit on that.

Using a full GUI desktop install as your initial development platform is a good plan. You can always do the customized production install once the process is confirmed and your more comfortable at the prompt.

For viewing mounted partitions, you can probably leave the "-l" off the mount command. Actualy, any of the following should give you information:

fs - list file system usage and mount points.

mount - by default, will list mounted media and mount permissions, I use it as a second look if the first doesn't answer my questions.

cat /etc/fstab
more /etc/fstab - some people like to stick with the old ways so one can simply "type" the fstab and see what the system has mounted.

That's also my order of preference for viewing mount points.

Q1, I'd say yes. play it safe and include the umount command where applicable. A script doesn't care about one more command in the sequence.

The way it works here is that a partition is mounted to a directory resulting in the tree of subdirectories and folders on that partition. As files are read and changed, they are kept in memory and periodically written back to the partition. This means less writes to eat the drive read/write limit and less fragmentation. Media needs to be unmounted giving the system the chance to sync up any outstanding changed data between memory and the media. It then lets go of the media uncoupling it from the mount point it apears as.

This same thing can be seen with Windows management of flashdrives. Removing a flashdrive without "safely remove .." from the taskbar icon can damage the data because outstanding changes may get left unwritten.

Both platforms can also be told to keep the mounted media in sync at all times too of course.

But.. the point is that umount is better to do and not need rather than not do.

I suspect HAL is mounting the partition after you create it. (not just a red dot and smooth voice). HAL is a program that watches for hardware changes and responds. I don't know it it only watches USB or only storage either way, it also watches USB and storage.

Based on the mount point, I'd say HAL is the ghost in your system. It is spotting the valid partition /dev/sda1 and mounting it to /media/usb0 as a default location. It will normally use the partition label if one is available (ex. /media/mydisk if your disk is labelled "mydisk").

If you are writing an image file with DD, you won't want the partition mounted. If you where copying the data as directories/files with cp or a similar command then you would want the partition mounted.

Not mounted:
dd if=data.img of=/dev/sda1

Mounted:
cp -r /archives/data/* /mnt/usb0

I'm new to using fsdisk (partitioning SD for my Maemo PDA; SD with three partitions blows my mind).

For DD, think of it like "rawwrite" if you've used the Windows program to write .bin or .img files to a diskette. Copy reads the directories and files you want to move and duplicates them in the new location. DD reads the 1s and 0s you want to copy and writes the same order of 1s and 0s to the destination.

In another case where I made things harder than they had to be out of Windows habit; I wanted to pull an ISO of a CD for a VM rather than mount the distro install disk through the physical disk reader. In windows, Nero, winISO and a list of other programs do this for the user so I went looking for some sort of LinISO type thing. And, what was the archaine series of hoops I had to jump through eventually to get my ISO?

dd if=/dev/cdrom of=/home/user/cdrom.iso

I kicked myself for a day over how easy that little thing was; especially after years of writing image files the other way for diskette driven network installs of Red Hat and Mandrake.

Q4. use /dev/disk/by* contained file entries the same way you use /dev/sda. If you go into your by-uuid directory and do a "ls -l" you should see what actual device the virtual device points back too. (I should have thought to mention that earlier.) In my own machine right now I have the following:

lrwxrwxrwx 1 root root abc123def456 -> ../../sda1

(modified to remove specifics)

So, uuid abc123def456 is a link (man ln) pointing to /dev/sda1 using a relative path.

If you are mounting /dev/sda1, you can also mount /dev/disk/by-uuid/abc123def456. dd or sfdisk should also work through the uuid provided your "ls -l" shows it pointing to the right device ahead of time.

I'm still understanding the sfdisk steps myself so I can't help much there yet but I'll step through your commands and hopefully be repeating what you already know:

# cd /home

Switch to the home directory, this should be modified to your user directory; cd /home/palmetto or cd ~/ (home directory for applicable uname)

# dd if=nia-720.img of=/dev/sda

raw copy the image contained in blah.img to media recognized as device /dev/sda. This is writing the disk image just like taking a .iso and writing the binary image to CD/DVD.

# cd niafs720

change to the niafs720 subdirectory. Based on your commands, that's /home/niafs720 though I would make it a subdirectory of the applicable user. In your case, /home/palmetto/niafs720. This is only to keep all your user activities within your own area (~/).

# sfdisk -f /dev/sda /dev/null

I've only used sfdisk interactively so I'm not sure what this longer command is doing other than forcing (-f) the command. /dev/null is, well, null so it looks to be writing blank to the device/partition (blank.part?).

# mount -l

You can use "mount" without the "-l" porbably. it should default to listing mounted partitions without any command switches.

# umount /media/usb0

unmounts the automounted partitoin sda1 by specifying the mount point /media/usb0 used to identify it.

# sfdisk -f /dev/sda /dev/null
# sfdisk -f /dev/sda <128mb1.part> /dev/null

My understanding is that DD could be used to create the partition and contained data all at once from the image file so the fsdisk is throwing me. It does seem like you create the disk and image then blow it away by mucking the partition tables. I have to read Seanferd's comment though as he may have answered it already.

What files do you have or what are the "supplies" and end result your after? Are there more files involved other than the one .img file written with DD?

nia-720.img <- a file you have
blank.part <- is this a file?
128mb1.part <- is this a file?

So, with that/those initial files, you need to take a blank SD (MMC or such) and write the nia-720.img too it? The result is the written data then placed into the hardwar product as the authentication or unit unique data with the unit's own OS code on a ROM chip? (or, is this the OS/control software on the SD or MMC?)

Sorry to go back to the beggining again. Reviewing the intended goal and materials (img files) without the specific steps may result in a cleaner process for you.

by seanferd

And I still can't grok the copy then partition gig.

Is everyone sure that this guy who is no longer with the company did not muck up the scripting to yank some chains?

by charliespencer

What determines if a file is executable is the permissions one has to it, not the content of the file itself? What happens if I make something non-executable, like a spreadsheet, executable and then try to 'run' it?

by neon samurai

Correct. "executable" is a permission attribute specified explicitly for the owner or group or anybody or combination of those three.

If you make a spreadsheet executable, it will return an error or at least I assume as much. I've not thought to try that but I'm going now that you bring it to mind. I expect either an error or a coredump file as the results but we'll see.

In shell scripts, you may notice many of them starting with a shell entry:

#!/bin/bash (or often #!/bin/sh)
## file made to do something for someone
## date file was made

command
command

That first #! line will tell the system what shell it should prefer to use though if the line is not present and the script is executable, it will run in the current shell.

Now, here's the advantage; when something is downloaded, it does not get executable permissions. It will likely have owner read/write permissions and equal or lesser group and other permissions. The user then has to make the file executable if that is the valid and intended use. If someone else is able to sneak something onto your system through the network, they still gotta crack an account to make the file executable; the file probably being the tool expected to crack the account in the first place.

This can be broken by adjusting the default permissions mask for new files but that's like turning off the Windows firewall then surfing for porn and cracks.

permissions and chmod/chown/chgrp are one of the corner stones to be aware of unless a user is working purely through the GUI on a preconfigured appliance system.

That is purely about "permissions". At the risk of making things more complicated, there are also true file "attributes". With fat/ntfs, you have R, H, S, A that can be applied to files or directories. In the same way, "chattr" is a command to change attributes of directories/files with about seven or so attributes to choose from. I'm a fan of the "only allow changes from owner/creater" attribute for things like website directory trees.

Most of the time, permissions are all that one will be mucking with making things readable, executable or restricted to a smaller control group. I just thought I'd mention attributes in addition for interest. I don't think they apply to this task but they are good to keep in your mind distantly encase they become usefull in another case.

by neon samurai

I've partitioned drives and moved crap around on platters all over the place. Given the starting materials and end objective, we may be able to write Palmetto a clean script to do the same thing.

by charliespencer

I have a procedure written by someone no longer with the company, a vague understanding of what each step does, but I don't really know what the final product is. Once the process is complete I have no way to test the media to be sure it actually does what it needs to. Since it goes into a piece of railroad safety equipment, it has to be right or someone may die (literally).

I don't think the users at my location really understand it either; they refer to the process as 'programming' the flash media. I've already given up on my contact at the other site who has been doing this for us; he says he follows this procedure because it's what works.

by neon samurai

Overall, it seems you take the SD or MMC, create a partition on it then write the software image too it. I could see the steps being the following:

- insert media
- create partition
- format partition
- copy contents to partition
- remove media

Since you have an image my mind says it should be more like this:

- insert media
- write image file to media
- make media bootable (if that is required)
- remove media

Writing an image file to a SD/MMC/Diskette should take care of everything except the bootable flag. The image should contain the contents and the partition file system unless it is an image of a blank partition that get's stuffed with contents by the next person down the assembly process.

The part that makes me nervous is not being able to compare a fresh SD/MMC to a completed and tested one and not being able to test the card in the final device. Especially if this is safety equipment; there has to be some quality control step between writing the media and dropping the final hardware unit into place.

I also have the benefit of being an interested third party in the puzzle. I'm guessing you've used some interesting discriptors with this being more than voluntary interest.

by seanferd

Simply copying the image and making it bootable is how I would approach it. Not having any way to verify that the result is the desired product, fully functional, is entirely insane. It seems there was a lot of ball-dropping going on before this little gem of a project was handed to Palmetto.

There is way too much uncertainty, and far too little documentation, to be playing around with the safety factor. Where are the requirements, etc., that started this project prior to the disappearing guy even getting his hands on it? Oy vey.

edit: If the image is not ext3fs, I could see that it may need to be converted, but the sfdisk would wipe everything, no?

The other step that needs to be taken is to do the installation (unpacking) from the niafs720 directory, and the subsequent deletion of the /var/ directory (for some reason). Perhaps because that /var/ belonged to the machine the image was created on? (Useless for any other machine.)

What I'm wondering is, if a successful installation does occur, could Palmetto then just create an image of the installation, then just copy (dd) it to any number or drives, no muss, no fuss?

by charliespencer

My poor choice of words has mislead you. I personally don't have a way of testing the media or even know what it's supposed to do. However, others in this building have a test procedure for the assembled component that uses the media. The problem is we're not scheduled to make any of the assemblies for several weeks yet. This is good because it gives me plenty of time to get it done, but it makes testing difficult. Hopefully when I've got something ready to test we can pull a finished unit off the shelf.

Sorry for the lack of feedback on this lately; I've had other support issues push it to the back burner.

by neon samurai

Any time I have a flashdrive currupted, I do a "dd if=/dev/sda of=~/flashdrive.iso" just so I can later mount the ISO if needed (yeah, mount isn't just for devices.. muwahaha).

In the same way, unless each disk is different somehow, he can simply dump a working flashdrive image to an ISO with DD.

He should even be able to mount the .img file directly and see what's actually in there.

by neon samurai

I figured you'd be a bit spotty when you mentioned that other projects where getting priority at the moment. Good to hear your not working blind either.

Is there any of the older units availabe from the testing team? Seeing a final working flashdrive and what it does may clarify your requirnments.

I wish we could get some of the other even more knowedgable eunics in here. (I couldn't resist. ;D)

(Like anything, this wouldn't be half as complicated if it wasn't through text back and forth; it's like negotiating a contract over email.)

by neon samurai

http://maemo.org/community/wiki/HowTo_EASILY_Partition_your_MMC_card/

I've finally cut that page into a PDF but that is my reference for sfdisk when I have to repartion a free SD for my PDA.

You may be able to step through the interactive sfdisk process to get the process working then translate that to the non-interactive command lines.

I now have to go do a mkdosfs and mkextfs to create the file system within the two partitions I cut but I thought to hand off the link now before I forgot.

This discussion is closed to new replies.