LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-24-2006, 07:50 AM   #1
RGummi
Member
 
Registered: Nov 2005
Posts: 90

Rep: Reputation: 15
fdisk /mbr


Hello,

How can I rewrite a MBR with Linux?

Background: I want to sell an old harddisk. I have deleted all with dd if=/dev/zero of=/dev/hda bs=512. After that I have started fdisk to rewrite an empty dos partition table. But I know that it is impossible to install windows on it due to a valid MBR. I dont't want to make a floppy only for using fdisk /mbr. So my question which Linux command can do it?

Thanks
RGummi
 
Old 08-24-2006, 08:26 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,124

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by RGummi
But I know that it is impossible to install windows on it due to a valid MBR.
How do you "know" this ?.
The disk is fine as-is; in fact you would be better not to write the partition table at all. Just zero it, and sell it.
During an install Windows will recognise it as an unformatted disk, and offer to format as part of the install.
I do this regularly with XP when testing disk (particularly MBR/partition table) recovery.
Not sure how Windows reacts if it's simply an extra disk (i.e. not being installed onto) - I haven't bothered testing that.
 
Old 08-24-2006, 08:26 AM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
While in Linux, you could use lilo to do this as root user.
Code:
lilo -M /dev/hda
 
Old 08-24-2006, 08:29 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Quote:
The disk is fine as-is; in fact you would be better not to write the partition table at all. Just zero it, and sell it.
Actually, leaving it after doing a zero may cause any installation attempts to fail. I do recommend making an empty partition as the OP did.
 
Old 08-24-2006, 11:28 AM   #5
RGummi
Member
 
Registered: Nov 2005
Posts: 90

Original Poster
Rep: Reputation: 15
Hello,

thanks for the answers!

syg00: I have tried it! Windows installs fine but it can not boot from this disk. After I used the Windows recovery console and doing fixmbr it works!

homey: I will try it! So there is no hidden option in the Linux fdisk to do it?

RGummi
 
Old 08-24-2006, 01:47 PM   #6
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by RGummi
I want to sell an old harddisk. I have deleted all with dd if=/dev/zero of=/dev/hda bs=512
You have not "deleted all". You have only overwritten your MBR, a paltry 512 bytes of your disk. If you think this makes all your previous data unrecoverable, think again. You're probably still sitting at a 99+% chance of COMPLETE RECOVERY right now. You need to overwrite the entire disk, and do so multiple times with varying patterns of one's and zero's.

If you didn't have anything sensitive on the disk you may not want to go to the trouble. On the other hand, if you had something very sensitive I wouldn't sell it, I'd destroy it. Sledgehammers, electric drill holes, dissassembly and scratching up the platters with a grinding wheel are steps to take. Then break the platters into little bitty pieces and take them down to your local hospital for a visit with their MRI scanner (you probably wouldn't be too popular with the hospital staff after that one!)
 
Old 08-24-2006, 02:31 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by haertig
You have not "deleted all". You have only overwritten your MBR, a paltry 512 bytes of your disk. If you think this makes all your previous data unrecoverable, think again. You're probably still sitting at a 99+% chance of COMPLETE RECOVERY right now. You need to overwrite the entire disk, and do so multiple times with varying patterns of one's and zero's.
Hmmmmm---dd will keep going to the end of the file/device if there is no count specified. OP's command will--in fact---write zeros to the whole drive.

As already pointed out, just writing zeros is not really secure. For security , you need something like DBAN:
http://dban.sourceforge.net/

I always thought that you could "wipe" a drive and then install Windows......
 
Old 08-24-2006, 03:51 PM   #8
RGummi
Member
 
Registered: Nov 2005
Posts: 90

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by haertig
You have not "deleted all". You have only overwritten your MBR, a paltry 512 bytes of your disk. If you think this makes all your previous data unrecoverable, think again. You're probably still sitting at a 99+% chance of COMPLETE RECOVERY right now. You need to overwrite the entire disk, and do so multiple times with varying patterns of one's and zero's.

If you didn't have anything sensitive on the disk you may not want to go to the trouble. On the other hand, if you had something very sensitive I wouldn't sell it, I'd destroy it. Sledgehammers, electric drill holes, dissassembly and scratching up the platters with a grinding wheel are steps to take. Then break the platters into little bitty pieces and take them down to your local hospital for a visit with their MRI scanner (you probably wouldn't be too popular with the hospital staff after that one!)
I think you are wrong! There is no count and it will write zeros until the end of the disk is reached. But the topic was no "how to erase", it was how to restore MBR after erasing! But thanks for your answer.

RGummi
 
Old 08-24-2006, 04:05 PM   #9
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by RGummi
I think you are wrong!
You are right. I am wrong! I guess I've seen that dd command so many times, with "count=1" added to the end of it, that I just ASSUMED it was there in the original example. Oops!

I agree, the entire drive was wiped. A single pass wipe using only zeros is good enough to obliterate things from normal people. If the NSA or somebody like that got ahold of the drive they could probably recover some stuff. But having the NSA grab your disk is not really a high probablility for most of us (I hope!)
 
Old 08-24-2006, 04:19 PM   #10
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
Originally Posted by pixellany
I always thought that you could "wipe" a drive and then install Windows......
I've done that before. Never seemed to make any difference on future installs if the MBR was totally zeroed out or not. I'm not sure what the variations might be that make some people have trouble doing so.
Quote:
Originally Posted by RGummi
Windows installs fine but it can not boot from this disk. After I used the Windows recovery console and doing fixmbr it works!
If Windows installed, but then wouldn't boot until you did a manual fixmbr, that almost sounds like it has to be a defect in the Windows installer. Otherwise, it would appear that Windows was EXPECTING something to preexist on the harddrive, which doesn't sound like something an operating system would expect.
Quote:
Originally Posted by RGummi
But the topic was no "how to erase", it was how to restore MBR after erasing!
I understand this and wasn't trying to hijack the thread. I made an error and did not correctly interpret what you had done with dd. My mistake left me thinking that you had not done the wiping you thought you had. I pointing this out to you with the noblest of intentions - to save you possible grief later if your personal data was stolen. I am sorry that I made a mistake.
 
Old 08-24-2006, 04:41 PM   #11
RGummi
Member
 
Registered: Nov 2005
Posts: 90

Original Poster
Rep: Reputation: 15
Defect in the Windows installer: Only in the installer ;-)

Quote:
it would appear that Windows was EXPECTING something to preexist on the harddrive, which doesn't sound like something an operating system would expect
It would be intersing to look at a new disk, what there is already on it. I think each sector ends normally with 0x55 0xAA. Perhaps this is the reason why windows does not install a MBR.
 
Old 08-24-2006, 04:59 PM   #12
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by RGummi
Defect in the Windows installer: Only in the installer ;-)



It would be intersing to look at a new disk, what there is already on it. I think each sector ends normally with 0x55 0xAA. Perhaps this is the reason why windows does not install a MBR.
The 55AA signature is the last two bytes of a partition table. It does not appear on a sector with no partition table.
 
Old 08-24-2006, 05:20 PM   #13
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,124

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Close - it's a disk "signature".
Last 2 bytes of the first sector - after the partition table.

Older versions of [c]fdisk used to explicitly check for the presence of these two bytes prior to opening a disk. I was surprised to see such code.
I think if you have an old knoppix (3.3 maybe ???), you would see fdisk fail to open such a formatted disk.

Quote:
I have tried it! Windows installs fine but it can not boot from this disk. After I used the Windows recovery console and doing fixmbr it works!
Don't understand this - never seen it happen (with XP).
To sell it now (i.e. without windows) use "skip=1" on the dd command.
Save you (and the rest of us ) a heap of grief.
 
Old 08-24-2006, 05:56 PM   #14
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
From HIW (http://ata-atapi.com/hiwtab.htm):
Quote:
First, all partition table records (sectors) have the same format. This includes the partition table record at LBA 0 (cylinder 0, head 0, sector 1) -- what is known as the Master Boot Record (MBR). The last 66 bytes of a partition table record contain a partition table and a 2 byte signature. The first 446 bytes of these sectors usually contain a program but only the program in the MBR is ever executed (so extended partition table records could contain something other than a program in the first 466 bytes). See Master Boot Record.
Yes, the signature is after the actual partition table--and is the last two bytes of a partition table record. It can appear many times on one disk if there are a lot of extended partitions.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fdisk /MBR Eugney Slackware 39 08-23-2011 09:30 AM
fdisk /mbr for linux lunlun Linux - Newbie 2 06-19-2006 04:56 AM
Grub - fdisk /MBR lucho707 Linux - Software 1 11-30-2005 11:07 PM
fdisk /mbr rharvey@cox Linux - Software 2 02-16-2004 12:19 PM
why won't my mbr fdisk /mbr? jamessp007 Mandriva 13 01-03-2004 01:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:09 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
Open Source Consulting | Domain Registration