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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
12-13-2007, 06:27 AM
|
#1
|
Member
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299
Rep:
|
"Using dd to zero the MBR" query.
Hi there !
Was just wondering if some kind soul could clear this up for me.
I play around with a lot of linux distros as I am always inheriting lots of old machines. My bootloader of choice is always grub, however some installations use lilo and the method I often use to remove lilo is to zero the MBR. Now I have read on LQ that if I use the following command the boot code will be zero'd but the partition table remains intact :
Code:
# dd if=/dev/zero of=/dev/hda bs=446 count=1
Whereas
Code:
# dd if=/dev/zero of=/dev/hda bs=512 count=1
will zero everything including the partition table record.
So if the latter is used, am I correct in assuming that not only will the boot code be wiped but also any record of how the disk is partitioned and formatted ( Partition Table record ?). Hence, if I accessed this drive using a live CD I would not get a readout of all the partitons and their respective formats when performing fdisk -l ? If my assumption is wrong what would be the output if I did run fdisk -l on a drive with the 512 bytes zeroed ?
Thanks,
Uncle-C
|
|
|
12-13-2007, 10:02 AM
|
#2
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
You've got it right. The second example erases the partition table and fdisk will report that the disk has no partitions.
Why erase the MBR when installing GRUB or LILO? Whatever you put in the MBR will simply overwrite what was there.
|
|
|
12-13-2007, 10:32 AM
|
#3
|
Member
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299
Original Poster
Rep:
|
Quote:
Originally Posted by pixellany
You've got it right. The second example erases the partition table and fdisk will report that the disk has no partitions.
Why erase the MBR when installing GRUB or LILO? Whatever you put in the MBR will simply overwrite what was there.
|
Thanks a lot for the reply Pixellany. The above is exactly what I thought
but when trying to install GRUB to re-write over LILO I was getting L99 99 99 99 99 errors on boot up. When I done a hexdump to view my MBR it showed that fragments of LILO were still installed. The way I eventually got grub to install properly was to zero 446 bytes and then re-install it. I was installing SLAX on a spare partiton and it uses LILO as the bootloader and gives you no alternative but to load it into the MBR of hda and not in any specified partition.
Thanks again for the help !
uncle-c
|
|
|
12-13-2007, 12:30 PM
|
#4
|
Member
Registered: Jun 2007
Distribution: Knoppix, antiX
Posts: 252
Rep:
|
With all 512 bytes to 0, it must show the entire disk as unallocated space. Data aren't erased, so you could perhaps restore the deleted partitions using "testdisk".
But, if you put all the MBR to 0, then the disk label is deleted too.
|
|
|
12-14-2007, 04:27 PM
|
#5
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by masterclassic
With all 512 bytes to 0, it must show the entire disk as unallocated space. Data aren't erased, so you could perhaps restore the deleted partitions using "testdisk".
But, if you put all the MBR to 0, then the disk label is deleted too.
|
Not understanding this.....I have always assumed that the MBR was defined as the first sector---ie the first 512 bytes.
On my system, I just made a label using "e2label". Using dd, I found this in the 3rd sector of the partition**---nowhere near the 1st sector / MBR.
**specifically, at an offset of OX478 from the start of the partition. This is in the 63-sector zone that precedes the start of the real partition data.
|
|
|
12-14-2007, 05:35 PM
|
#6
|
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450
Rep:
|
Quote:
Originally Posted by pixellany
Not understanding this.....I have always assumed that the MBR was defined as the first sector---ie the first 512 bytes.
|
It is.
Quote:
Originally Posted by pixellany
On my system, I just made a label using "e2label". Using dd, I found this in the 3rd sector of the partition**---nowhere near the 1st sector / MBR.
|
That’s because labeling a partition has nothing to do with the MBR. It is filesystem-specific (in this case ext2/3) and will undoubtedly affect whatever partition in which your filesystem resides.
As for masterclassic’s suggestion of using testdisk, you might instead backup and restore the partition table (and only the partition table).
|
|
|
12-14-2007, 07:48 PM
|
#7
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,286
|
Quote:
Originally Posted by pixellany
On my system, I just made a label using "e2label". Using dd, I found this in the 3rd sector of the partition**---nowhere near the 1st sector / MBR.
|
As osor explained, masterclassic said "disk label".
Don't know what [s]he meant by that, but I can think of two candidates. The id bytes that Windoze stuffs in there (and the rest of the world ignores), or the "signature" bytes at the end (last 2 bytes) of the first sector.
Neither is a major issue any more - [c]fdisk used to abort if they couldn't find the sig bytes, but that's no longer the case.
Personally I always try to leave the part table and sig bytes intact.
|
|
|
12-15-2007, 05:47 AM
|
#8
|
Member
Registered: Jun 2007
Distribution: Knoppix, antiX
Posts: 252
Rep:
|
Quote:
As osor explained, masterclassic said "disk label".
Don't know what [s]he meant by that, but I can think of two candidates. The id bytes that Windoze stuffs in there (and the rest of the world ignores), or the "signature" bytes at the end (last 2 bytes) of the first sector.
|
It is this last that I mean, the last 2 bytes, that make the system to understand that the disk is formatted for an intel architecture, or for spark architecture, or for power-pc, & so on. This is the "msdos signature", usually needed for Linux/x86. This means that the partition table has this specific structure of 4 primary partition entries.
I think that most manufacturers now sale their disks with this signature already written. Obviously, if we install Linux or another system on an empty disk, it writes this signature in order to proceed to the disk partitioning and format.
Of course, I always prefer to backup the MBR before any partitioning work, rather than recovering Testdisk is a tool we can use if something goes wrong. It is contained in several live cds, as in Gparted livecd (from the terminal), and I think in the Ultimate Boot cd.
|
|
|
All times are GMT -5. The time now is 07:22 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|