-   Linux - Software (
-   -   Erasing MBR from USB stick (

spiffytech 01-03-2006 01:53 PM

Erasing MBR from USB stick
I'm playing around with Linux distros that will run from a USB memory stick and will finction as a complete OS, as if running from an HDD. One that I tried installed the bootloader to the stick's MBR. I have since formatted the stick, so the OS is gone, but the bootloader is still there pointing to it.

I need to get rid of the MBR bootloader so that when my laptop boots to the USB stick, the syslinux file points it to the right OS. How do I clear the MBR?

madluther 01-03-2006 02:49 PM

You can re-install the MBR onto the USB Stick with syslinux, for a stick connected as /dev/sda the following will reinstall the MBR, adjust the device name to suit your setup.


syslinux -s /dev/sda


oneandoneis2 01-03-2006 02:55 PM

Erase the MBR using "dd if=/dev/zero of=/dev/sda bs=512 count=1" assuming the USB stick is sda of course

spiffytech 01-03-2006 05:02 PM

OK, I ran that command to clear the MBR, but it seems that when it did, it also removed all partition s from the memory stick as well. How do I put a partition on there from the command line?

syg00 01-03-2006 06:16 PM

That was a poor decision. Not knowing syslinux, I would have thought the solution offered by madluther would be the best place to start.

What the dd command actually did was also remove the partition table; although the data in the partitions hasn't been touched.
Not only that, it removed the signature bytes on the disk - which means fdisk and cfdisk won't open the disk. These two utilities are the normal way to create partitions.
testdisk probably will do the job although I haven't looked at the code - maybe parted as well.
Probably gparted as well, if you have a GUI available.

oneandoneis2, I suggest you not offer this advice to anyone else.

WhatsHisName 01-03-2006 07:15 PM

spiffytech: As syg00 pointed out, the parted rescue feature usually does a good job of recovering primary partitions. How to use the rescue option is explained here:


Regarding the “dd” command:

Once upon a time, a salesman locked himself out of his car in Manhattan. A kid walked up and said “Hey mister, I’ll open your car for $10, but I want the money up front.” So the salesman gave him $10 and the kid picked up a brick and broke the side window. “Hey mister, you didn’t ask me how I was going to do it.”

oneandoneis2 01-04-2006 05:09 AM

The OP says the drive has been formatted, implying there was no valuable data on the drive, or I wouldn't have recommended the dd method.

I've never had any problems repartitioning a flash drive that's been dd'd in the manner I mentioned. I forget if I used fdisk or cfdisk, but those are the only partitioners I have installed, so I know for a fact that at least one of them works just fine.

Under the cirumstances, as a simple way of clearing the MBR of a blank disk, I believe the dd method is a good one.


syg00 01-09-2006 05:27 PM

Apologies are in order to oneandoneis2.

I just had the opportunity to zero a hard-disk prior to the laptop being returned to the leasing company.
fdisk opened and created partitions even with the zero'd MBR just fine.
Didn't work the last time I tried it, did with this version of Knoppix (3.9 - kernel 2.6.11).

Live and learn.

Vincent_Vega 01-09-2006 08:52 PM

I'm glad dd got the respect it deserves! It's the coolest command out there!

syg00 01-10-2006 05:38 PM

dd was never the issue - merely it's use.
Given the wide variety of kernel versions out there, my preference is to use

dd if=/dev/zero of=/dev/sda bs=446 count=1
This clears the entire code section of the MBR, but leaves the partition table and signature bytes intact.

All times are GMT -5. The time now is 06:41 AM.