LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-22-2014, 10:01 AM   #1
daf1kpp
LQ Newbie
 
Registered: Feb 2013
Posts: 19

Rep: Reputation: Disabled
Using DD to write MBR


Hey. I want to write new values to sector number 0 (MBR) of flash drive. Flash drive is formatted to have 1 partition with FAT32 filesystem. After drive is inserted it "gets" sdc name. Then I execute this command:

Quote:
dd if=files/mbr_binaryFile of=/dev/sdc bs=512 count=1
No error message, when I want to check if all is fine then I do this command (get 1st sector and check it with hexdump):


Quote:
dd if=/dev/sdc of=files/mbr_check_binaryFile bs=512 count=1
hexdump files/mbr_check_binaryFile
Hexdump result (file mbr_check_binaryFile) is fine. But dunno what after that is going wrong because when I want to boot with this flash drive it seems that no changes were done. Shall I do some kind of "SAVE" after DD command is executed ? All is lost and first sector has old data. Why ?
 
Old 01-22-2014, 10:25 AM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,613

Rep: Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703Reputation: 703
Like most programs, dd writes to memory which is mapped to disk. The data is actually flushed to disk by a background process. This is forced when you unmount the drive or shutdown your system. If you pulled the drive out without doing a umount, then it may be corrupted. You can also ask dd to bypass memory with the -oflag=direct option.
 
Old 01-22-2014, 10:34 AM   #3
daf1kpp
LQ Newbie
 
Registered: Feb 2013
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by smallpond View Post
Like most programs, dd writes to memory which is mapped to disk. The data is actually flushed to disk by a background process. This is forced when you unmount the drive or shutdown your system. If you pulled the drive out without doing a umount, then it may be corrupted. You can also ask dd to bypass memory with the -oflag=direct option.
I didn't use "mount" command, so why would I have to use "unmount" then ?

I have directly connected flash drive memory to PC. Checked /var/log/messages for name like sdb/sdc etc.. then did command like above. I didn't mound file system, I was doing operations on physical drive. Shall I do some kind of flush anyway in this case ? What is the way to flush data after dd command's changes are being done ?
 
Old 01-22-2014, 11:16 AM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,117

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Your dd command is good. I have used the same many times over.

You do not need to flush or unmount anything, because as you already know, you are not writing to a mounted filesystem. You are writing to a raw device.

You do not have to do any kind of "save" with dd. results are immediate after the command completes.

Quote:
Originally Posted by daf1kpp View Post
Hexdump result (file mbr_check_binaryFile) is fine. But dunno what after that is going wrong because when I want to boot with this flash drive it seems that no changes were done. ... All is lost and first sector has old data.
This is where I'm confused. I think you're saying that your did the write and then verified the data with a subsequent read - proving the initial write was successful. Then you try to reboot with the newly written device, which fails. Then you re-read the MBR from the device and it is now different than it was when you did your previous verification. Is that correct? You are saying that the MBR contained XXX data before you attempted a reboot, and then after the reboot attempt, the MBR contained YYY (different) data?

p.s. - Booting from a flash drive can sometimes require you to invoke black magic. It is not a guarranteed doable thing on every system. However, despite this, I would not expect your thumbdrives MBR to change on a reboot attempt, regardless if that reboot failed or succeeded. Maybe do you have some kind of new-fangled, funky, special non-standard thumbdrive? Some thumbdrives come with a bunch of crap on them. I personally haven't run into one with a "frozen" MBR, but who knows, some manufacture could have done something like that. I haven't bought a new thumbdrive for many years. Manufacturers seem to always be farting around with them trying to make them more than just a storage device. Adding encryption, adding built-in apps, etc.

Last edited by haertig; 01-22-2014 at 11:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
do not write to MBR question obnascar Linspire/Freespire 6 10-03-2006 09:56 PM
write grub to the MBR lixy Linux - General 1 08-27-2005 10:54 AM
Lilo don't write on MBR clapton Slackware 7 10-11-2004 08:20 AM
Does LoadLin write to the MBR? jhecht Linux - Software 1 06-25-2004 11:50 AM
mbr had over write so lilo is gone how to rewrite lilo to mbr mch Linux - Software 4 10-25-2002 03:55 PM


All times are GMT -5. The time now is 10:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration