Need some more help from a Linux Guru

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
My Linux ignorance is profound. :(

Could someone interpret the following for me?

Code:
dd if=/path/to/zImage of=/dev/sdb seek=2048
dd if=/path/to/initrd of=/dev/sdb seek=8192
I understand the concept of specifying the path to the said files but what I can't grasp is why these instuctions don't specify the file name itself. Or am I reading it wrong?

Thanks
 

dataoscar

Member
Dec 2, 2013
68
10
8
/path/to/zImage is the file name. zImage is the input file and the output is the disk mapped to /dev/sdb
 

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
/path/to/zImage is the file name. zImage is the input file and the output is the disk mapped to /dev/sdb
Sorry, clear as mud. "/path/to/zImage" is not the file name. The file name is just zImage. when I try /dev/sdc/zImage I get a error message. The USB drive on which zImage is located is sdc. So if /dev/sdc/zImage isn't the correct syntax, what is.

Thanks, and again sorry for my ignorance. :(
 

fractal

Active Member
Jun 7, 2016
309
69
28
33
My Linux ignorance is profound. :(

Could someone interpret the following for me?

Code:
dd if=/path/to/zImage of=/dev/sdb seek=2048
dd if=/path/to/initrd of=/dev/sdb seek=8192
I understand the concept of specifying the path to the said files but what I can't grasp is why these instuctions don't specify the file name itself. Or am I reading it wrong?

Thanks
You are putting the contents of the file "zImage" on the hard drive "sdb" starting at sector 2048.
You are then putting the contents of the file "initrd" on the hard drive "sdb" starting at sector 8192

It "appears" those instructions are patching a new boot image and initial ram disc onto an existing Linux image on physical drive sdb. You are addressing the drive "sdb" as a physical device, NOT as a file system. Hence you don't specify any file name. You specify the offset into the drive with the "seek=" option. This makes a LOT of assumptions as to how the files on the drive are structured.
 

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
You are putting the contents of the file "zImage" on the hard drive "sdb" starting at sector 2048.
You are then putting the contents of the file "initrd" on the hard drive "sdb" starting at sector 8192

It "appears" those instructions are patching a new boot image and initial ram disc onto an existing Linux image on physical drive sdb. You are addressing the drive "sdb" as a physical device, NOT as a file system. Hence you don't specify any file name. You specify the offset into the drive with the "seek=" option. This makes a LOT of assumptions as to how the files on the drive are structured.
So how does it know which file to put where?

I've become obsessed with making this work. I removed the two original drives and used them for other purposes. I didn't realize what a PITA it is to start out with 2 new drives.

Maybe I should just take a ball peen hammer to it and be done with it. :(
 
Apr 2, 2015
48
1
8
46
ever wrote an iso image to a cd/dvd? it's the same concept.

by using dd you write the contents of the zImage file directly to the sdb disk.

in your specific case, you probably download that zImage file from somewhere, an you put it in a folder, let's say /home/fritz/zImage

then you do

dd if=/home/fritz/zImage of=/dev/sdb seek=2048

make sure /dev/sdb is the correct disk you want to write to. dd doesnt ask for confirmation, and you can screw up the data on the drive you write to, since it writes raw data.

Sent from my SM-G930F using Tapatalk
 

fractal

Active Member
Jun 7, 2016
309
69
28
33
So how does it know which file to put where?
You told it where to put the data. That is what the "seek" field does.

We might want to step back a minute and ask "what the frick are you trying to do???"

I have been using Linux for 25 years and there are very few times I write blocks to the raw block device at fixed offsets like you are trying. Those are typically on an embedded linux system, like a router, or when I am storing non file-system data. Neither of those are common these days. Everyone uses file system tools to create the volume, create the file system then write their data to the filesystem.

The commands you provided ignore the file system and write data directly to the raw block device. This presumes you know where the partition tables are, where the partitions are and where the directory entries on the partitions point to for the specific files. It also presumes you know how much room is reserved on the disc for the initial ram disc (initrd). None of this is something a rational newbie should be doing.

So, given that you don't know what you are doing and what you are doing is very, very dangerous ... I suppose that rather than answer your question it would be prudent to ask you what you are trying to achieve and help you do it more sanely.
 
  • Like
Reactions: cperalt1

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
What I'm trying to do is reencarnate a Lenovo ix2-ng. The link I posted above is to the instructions I'm using. The original HDs are gone along with the OS.

So if the seek command tells where to put it, how do you tell it which file to put there. They are both in the same folder when extracted, could it be that they need to be in different folders?
 

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
So I put zImage in a folder called "a" and initrd in a folder called "b". It says that /dev/sbc/a is not a folder. This is all Chinese to me. It can't be that complicated. :mad:
 

xnoodle

Active Member
Jan 4, 2011
258
48
28
the `if` parameter is the input file, so you specify either the relative or absolute path to the "file" you want to write.

So, is your USB drive mounted? It's on /dev/sdc you said?
Can do a `mount.ntfs /dev/sdc /mnt` to mount it if needed.

Once mounted, use your dd command with the if=/mnt/zImage, etc
 

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
The 64 thousand dollar question is, how do you specify the file NAME or how does it know which file to write. They are both in the same directory and when I specify the file name I get an error, when I don't (i.e /dev/sdc) something happens but it doesn't work. As I understand it I'm copying these 2 files but how the heck does it know WHICH file to copy to where when only the path and not the file name are specified.
 

ttabbal

Active Member
Mar 10, 2016
747
207
43
47
Can you see the image files you want to write from? Do they show up in "ls"?

What happens when you do dd if=/dev/sdc of=file is the raw device /dev/sdc, probably a drive, usb or otherwise, is copied block by block to whatever you specify for the "of" parameter. This is like an old school sector copy of a floppy, if you ever did that. It completely ignores filesystems, dd works below the filesystem.

Remember, in UNIX, everything is a file. Devices can be accessed like any other file. That's what dd does. It accesses the device at a block level and blindly reads/writes.

What it looks like is happening here is that the hardware expects to load the kernel and ramdisk from particular sectors. So that's what you are doing, writing those images over to the place the hardware is loading them from. Much like a BIOS boot loads sector 0 and starts executing whatever it finds there.

The most important things to know right now are.. The device name of the hard drive you want to install in the embedded device. Likely /dev/sd?.. The device you have the image files on, and where it is mounted on the system. Some linux distros auto mount usb, some don't. What does "lsblk" and "mount" output?
 

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
Hang on, I'll be right back with the answers.

lsblk show all the drives. I'm presently doing "dd if=/dev/sdc of=/dev/sda seek=2048. zImage is the only file in the root of sdc. When it's finished I plan to delete it and put initrd in the root and run the command again.

Since this gibberish doesn't reference the file names (zImage and initrd) but lists 2 different command (both the same but different paths) I figure I have to run it twice. When these to files are extracted they are both in the same directory and thus have the same path. This is where I'm confused. The above 2 commands are exactly the same except for seek=. Could maybe the seek= statement determine which file goes where? How does it know which file goes where if the file name isn't specified? This is where my confusion lies, path/to is meaningless if both files are in the same directory. I think I'm losing me mind. :confused:
 
Last edited:

ttabbal

Active Member
Mar 10, 2016
747
207
43
47
Yeah, you're basically copying the whole filesystem, and everything else from sdc to sda. That isn't what you want. Does mount show sdc mounted? What directory? That's where you want to look to find zImage. Seek is moving 2048 bytes forward before writing. So it's skipping the first 2k on the drive.

If you are booting to a live linux or desktop install, it might be easier to download the zImage file there rather than using a usb drive. Then it will probably be in ~/Downloads or similar.
 

ttabbal

Active Member
Mar 10, 2016
747
207
43
47
I'm going to assume you're more familiar with windows.. /dev and the files in it are basically what you see in Device Manager. They represent devices that the kernel knows how to talk to. For drives like sda, sdc, those are basically a view of the drive as if it were one giant file. No filesystems, just byte 1 on the drive is byte 1 in the file /dev/sda. If you are familiar with C/C++, it's like a pointer to the first byte of the drive.

So you won't see individual files in /dev/sd?. To get those, you "mount" the filesystem to a directory. This is like seeing it show up in "My Computer". But rather than using a letter like C:, it uses an empty directory to let you access the files. Once mounted, that directory becomes the root directory of the filesystem you mounted. So "mount /dev/sda1 /mnt" takes the filesystem from the first partition of sda, and makes it available on /mnt. If you don't have partitions, leave off the numbers.

I hope that's more helpful than not... :)
 

Fritz

Well-Known Member
Apr 6, 2015
3,386
1,387
113
70
Thanks. My eyes are beginning to open. Will get back on it after morning coffee. :)