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 - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-03-2006, 01:53 PM   #1
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Rep: Reputation: 15
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?
 
Old 01-03-2006, 02:49 PM   #2
madluther
Member
 
Registered: Aug 2004
Distribution: LFS
Posts: 350

Rep: Reputation: 31
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.

Code:
syslinux -s /dev/sda
HTH

Mad.
 
Old 01-03-2006, 02:55 PM   #3
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 48
Erase the MBR using "dd if=/dev/zero of=/dev/sda bs=512 count=1" assuming the USB stick is sda of course
 
Old 01-03-2006, 05:02 PM   #4
spiffytech
Member
 
Registered: Dec 2005
Location: NC, USA
Distribution: (K)ubuntu
Posts: 139

Original Poster
Rep: Reputation: 15
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?
 
Old 01-03-2006, 06:16 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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.
 
Old 01-03-2006, 07:15 PM   #6
WhatsHisName
Senior Member
 
Registered: Oct 2003
Location: /earth/usa/nj (UTC-5)
Distribution: RHEL, AltimaLinux, Rocky
Posts: 1,151

Rep: Reputation: 46
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: http://www.gnu.org/software/parted/m...ted.html#SEC24

..........

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.”
 
Old 01-04-2006, 05:09 AM   #7
oneandoneis2
Senior Member
 
Registered: Nov 2003
Location: London, England
Distribution: Ubuntu
Posts: 1,460

Rep: Reputation: 48
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.

YMMV.
 
Old 01-09-2006, 05:27 PM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
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.
 
Old 01-09-2006, 08:52 PM   #9
Vincent_Vega
Member
 
Registered: Nov 2003
Location: South Jersey
Distribution: Slackware, Raspbian, Manjaro
Posts: 826

Rep: Reputation: 31
I'm glad dd got the respect it deserves! It's the coolest command out there!
 
Old 01-10-2006, 05:38 PM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,129

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
dd was never the issue - merely it's use.
Given the wide variety of kernel versions out there, my preference is to use
Code:
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.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
mount/umount usb stick - PQI Intelligent Stick 2.0 sandbag Linux - Software 5 05-06-2005 11:12 AM
erasing the MBR in linux TheOneAndOnlySM Linux - General 5 02-15-2005 07:48 AM
formating without erasing fedora and mbr a2ps Linux - General 4 08-17-2004 12:05 PM
USB problems: Memorex USB stick 256MB and PSX to USB adapter by Radio Shack Knuckles T15 Linux - Hardware 1 05-19-2004 06:58 PM
USB-Stick/usb-storage JC_at_LQ Linux - General 2 07-14-2003 06:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:30 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