Jump to content











Photo
- - - - -

Using dd in grub4dos commadnline mode


  • Please log in to reply
16 replies to this topic

#1 tjung

tjung

    Member

  • Members
  • 37 posts
  •  
    Germany

Posted 26 July 2010 - 07:42 PM

Hello,

I would like to save the first sector #0 which holds the MBR
to the (fd0) Fat 16/32 or (hd0,0) Fat 32 but the dd command
in the grub (0.4.4 stable or 0.4.5b) command line like:

dd if=(hd0) of=(fd0)/hd0mbr.bin bs=512 count=1

give me the message:
---snip---
buf_size=0x10000, loops=0x0, in_pos=0x0, out_pas=0x0

Bytes read / written = 0x0 / 0x0
---snap---

What is the correct syntax to save the boot record?
btw: fd0 is a writable usb stick mounted as fd0

Same with:
dd if=(hd0) of=(hd0,0)/hd0mbr.bin bs=512 count=1

Remark: The file hd0mbr.bin exists with 0 byte and
I created that before.

btw: If the file hd0mbr.bin doesn't exist before,
I get the error:
---snip---
Error 15: File cannot be found
---snap---

Somebody told me that grub4dos can't _create_ files.
Is that true and the reason for that "Error 15"?

But what is wrong if the file exist in the destination
file system? Why "Bytes read / written = 0x0 / 0x0" ?

I really would like to use grub4dos for that task and
think that is the right tool for such a task, because I
don't like to boot a full 32 bit OS (e.g. Linux) only
to save the sector 0 or the first two sectors
(to save the backup MBR too) or the first 64 sectors, etc.
And it would be fine, if I don't have to boot an OS
in general, just to restore or save the MBR or boot records.

Hope anybody can say what is my mistake an what is
going wrong.
Is the implementation not finished or do I make a
mistake?

T.

#2 Icecube

Icecube

    Gold Member

  • Team Reboot
  • 1063 posts
  •  
    Belgium

Posted 26 July 2010 - 07:47 PM

The file needs to be on the disk already AND it needs to be large enough.
For your case, it needs to be at least 512 bytes.

#3 tjung

tjung

    Member

  • Members
  • 37 posts
  •  
    Germany

Posted 26 July 2010 - 08:48 PM

The file needs to be on the disk already AND it needs to be large enough.
For your case, it needs to be at least 512 bytes.


uhhh. Sounds a little bit strange.
Think it is still in development, isn't it?
And a file which is bigger doesn't make sense
to me. It's not very handy.

What tools do you use for such a task?

What's about the freedos included dd?
How can I pass the harddisk device to that
dd tool to get the first or any other sector?
Does anybody know that?

Would be good to do it with the DOS dd tool,
because a DOS system is booted fast and very
small and dd is very flexible and can read write
byte by byte, I think.

T.

#4 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 27 July 2010 - 08:32 AM

tjung

the dd in grub4dos is something you shouldn't EVEN think of using as it is highly experimental.

From DOS (and Windows also), read this:
http://www.boot-land...showtopic=12088

:cheers:
Wonko

#5 dog

dog

    Frequent Member

  • Expert
  • 236 posts

Posted 27 July 2010 - 11:46 AM

I use grub4dos "experimental" functions all the time, although I'm careful about other kinds of backups.
The only bug I've seen was when cat --locate didn't work in 0.4.4 31/3/09, but in recent releases that works too.

title wipe the MBR

dd if=(cd)/512zero of=(hd0) bs=512 count=1

pause



title wipe the PBR

dd if=(cd)/512zero of=(hd0,0) bs=512 count=1

pause



title dd xp boot code

dd if=(cd)/xp440 of=(hd0) bs=440 count=1

write --offset=510 (hd0) \x55\xAA

pause



title set disk signature

cat --hex --skip=440 --length=4 (hd0)+1

write --offset=440 (hd0) \xFF\xFF\xFF\xFF

cat --hex --skip=440 --length=4 (hd0)+1 && pause



title create 20GB partition

partnew --active (hd0,0) 0x07 63 41929587

pause


#6 tjung

tjung

    Member

  • Members
  • 37 posts
  •  
    Germany

Posted 31 July 2010 - 11:59 AM

Hello dog,

thank you very much for your examples.
It's working very well and in my tests
it is working (behavior) exactly like
the dd commandline tool. But only used
bs, count, seek and skip.

I havn't worked much with dd so I'm still
experimenting and just to clarify.

Does this command (the input file has 9216 bytes)

dd if=()/boot/9216kb18.bin of=(hd0) bs=9216 count=1

do the same like:

dd if=()/boot/9216kb18.bin of=(hd0) bs=512 count=18

I think so, but what is the better choice and what
is the maximum size of "bs" which can be used be the
dd command of grub4dos?


T.

#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 31 July 2010 - 01:08 PM

Within limits, the bigger the bs, the faster will be the throughput, though it doesn't make ANY sense on such small amount of data.
See this:
http://lists.freebsd...ber/001555.html

Usually the bs size is a power of 2, though it's not mandatory, but probably using something else will slow the process (which in this case is irrelevant).

:cheers:
Wonko

#8 beginner

beginner
  • Members
  • 5 posts
  •  
    Russian Federation

Posted 23 April 2012 - 05:30 PM

dd if=()1+10M of=(md)50M+10M buflen=2M # works ok!
dd if=()1+10M of=(md)50M+10M buf=0x1000000 # Invalid argument :dubbio:

#9 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 April 2012 - 05:48 PM

dd if=()1+10M of=(md)50M+10M buflen=2M # works ok!
dd if=()1+10M of=(md)50M+10M buf=0x1000000 # Invalid argument :dubbio:


I am not sure to get it. :dubbio:

grub> help dd
dd: dd if=IF of=OF [bs=BS] [count=C] [skip=IN] [seek=OUT] [buf=ADDR] [buflen=SI
ZE]
Copy file IF to OF. BS is blocksize, default to 512. C is blocks to
copy, default is total blocks in IF. IN specifies number of blocks to
skip when read, default is 0. OUT specifies number of blocks to skip
when write, default is 0. Skipped blocks are not touched. Both IF and
OF must exist. dd can neither enlarge nor reduce the size OF, the
leftover tail of IF will be discarded. OF cannot be a gzipped file. If
IF is a gzipped file, it will be decompressed automatically when
copying. dd is dangerous, use at your own risk. To be on the safe side,
you should only use dd to write a file in memory. ADDR and SIZE are
used for user-defined buffer.



buf is an address
buflen is a size.
What makes you think that any of them accept Hex input?
Why do you need to use any of them? :unsure:

:cheers:
Wonko

#10 beginner

beginner
  • Members
  • 5 posts
  •  
    Russian Federation

Posted 23 April 2012 - 06:51 PM

What makes you think that any of them accept Hex input?
Why do you need to use any of them? :unsure:


New options are implemented for user defined buffer. By default,
the buffer is at address 0x50000, and length is 0x10000(=64KB). You cannot
specify ADDR to be lower than 0x100000(=1MB). Besides, you must specify SIZE
larger than 0x10000(=64KB). Normally you want ADDR >= 0x1000000(=16MB), and
SIZE also >= 16MB. A large SIZE could speed up the progression of dd.


dd if=()1+10M of=(md)50M+10M buf=0x1000000 buflen=0x1000000 # Invalid argument
dd if=()1+10M of=(md)50M+10M buflen=4M # reboot

Edited by beginner, 23 April 2012 - 06:57 PM.


#11 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 23 April 2012 - 07:03 PM

dd if=()1+10M of=(md)50M+10M buf=0x1000000 buflen=0x1000000 # Invalid argument
dd if=()1+10M of=(md)50M+10M buflen=4M # reboot


Maybe I am starting to understand :unsure:, you are trying to speed up dd operation...

Can you try:
dd if=()1+10M of=(md)50M+10M buf=16M buflen=16M
:dubbio:

Which EXACT version of grub4dos are you using?


:cheers:
Wonko

#12 beginner

beginner
  • Members
  • 5 posts
  •  
    Russian Federation

Posted 23 April 2012 - 07:44 PM

Maybe I am starting to understand :unsure:, you are trying to speed up dd operation...

Yes

dd if=()1+10M of=(md)50M+10M buf=16M buflen=16M # Invalid argument

I am using grub4dos-0.4.6a-2012-03-26

#13 tinybit

tinybit

    Gold Member

  • Developer
  • 1175 posts
  •  
    China

Posted 24 April 2012 - 02:19 AM

I think the "help dd" doc, as well as the readme, is buggy.

The latest grub4dos reserved 32M for its internal use. So the user defined buffer should be above or equal to the address of 32M.

dd also has a bug that it still uses
safe_parse_maxint
which might not resolve the "M, K" units.

#14 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 24 April 2012 - 06:48 AM

I am using grub4dos-0.4.6a-2012-03-26



I think the "help dd" doc, as well as the readme, is buggy.

The latest grub4dos reserved 32M for its internal use. So the user defined buffer should be above or equal to the address of 32M.


@beginner
Try an earler version with 16M.
Try the 0.4.6a with both:
dd if=()1+10M of=(md)50M+10M buf=0x2000000 buflen=0x2000000
dd if=()1+10M of=(md)50M+10M buf=0x2000000 buflen=0x1000000
and
dd if=()1+10M of=(md)50M+10M buf=32M buflen=32M
dd if=()1+10M of=(md)50M+10M buf=32M buflen=16M

:cheers:
Wonko

#15 beginner

beginner
  • Members
  • 5 posts
  •  
    Russian Federation

Posted 24 April 2012 - 08:38 AM

Posted Image

2011-10-03 (tinybit)changed buf_addr from 0x20000 to 0x100000 to avoid possible conflict between dd_func and get_diskinfo.


With grub4dos-0.4.5b-2011-10-04 and above don't work

#16 tinybit

tinybit

    Gold Member

  • Developer
  • 1175 posts
  •  
    China

Posted 24 April 2012 - 09:21 PM

Yes. It is a bug. Please try this fix

http://bbs.znpc.net/...nt.php?aid=4646

in this thread(on a Chinese board):

http://bbs.znpc.net/...ad.php?tid=6214

#17 beginner

beginner
  • Members
  • 5 posts
  •  
    Russian Federation

Posted 24 April 2012 - 10:09 PM

Thanks!

Latest version now works! :good:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users