How to zero out just the MBR of a USB?

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
mohittomar13
Posts: 51
Joined: Wed Jul 29, 2020 5:12 pm
Location: New Delhi - INDIA
Has thanked: 17 times
Been thanked: 3 times

How to zero out just the MBR of a USB?

Post by mohittomar13 »

I often use dd command for filling my USB with zeroes and then later formatting it using the style that I want. However, my USB stick is 16 GB and it takes around 40 mins for dd to fill it with zeroes. I just want to erase the partition details so that the USB appears to be non-formatted instead of actually filling it with zeroes. Is there some option that I can use with dd so to stop filling the USB after a certain amount of disk if filled with zeroes? I suppose this would not render my USB unusable.

any help will be greatly appreciated.

Laptop: Dell 3568
CPU: intel i3 6006U
RAM: 12 Gigs
4GB-micron + 8GB-kingston

yeah, it works.. :D
HDD: 1TB
OS: Tripple boot- (Windows-10, Xubuntu-20.4LTs, Bionic Puppy) 64Bit

user1111

Re: How to fill zeroes to only starting portion of USB

Post by user1111 »

dd if=/dev/zero of=/dev/xxxx bs=1M count=1

where xxxx is the usb device (sdb/whatever).

Then run gparted and create a new partition table, create a new partition, format it, set boot flag on if its to be a bootable usb.

User avatar
mohittomar13
Posts: 51
Joined: Wed Jul 29, 2020 5:12 pm
Location: New Delhi - INDIA
Has thanked: 17 times
Been thanked: 3 times

Re: How to fill zeroes to only starting portion of USB

Post by mohittomar13 »

Thanks for the reply. I think this is what I was looking for. bs=1 and count=1 means to write '0's for a total of 1MB in size. Right? If I put count=2 and bs=4mb that would mean a total size of 8mb.

Thanks... :D :D

Laptop: Dell 3568
CPU: intel i3 6006U
RAM: 12 Gigs
4GB-micron + 8GB-kingston

yeah, it works.. :D
HDD: 1TB
OS: Tripple boot- (Windows-10, Xubuntu-20.4LTs, Bionic Puppy) 64Bit

User avatar
mikewalsh
Moderator
Posts: 6041
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 739 times
Been thanked: 1906 times

Re: How to fill zeroes to only starting portion of USB

Post by mikewalsh »

@mohittomar13 :-

AFAIK, you only want the first 512 bytes to be cleared, since this is the amount of space occupied by your MBR - Master Boot Record. So that 1 MB in rufwoof's 'code' snippet should more than do the job.....once the MBR is erased, the drive, to all intents & purposes, is empty.

Mike. ;)

user1111

Re: How to fill zeroes to only starting portion of USB

Post by user1111 »

mohittomar13 wrote: Sat Feb 06, 2021 1:25 pm

Thanks for the reply. I think this is what I was looking for. bs=1 and count=1 means to write '0's for a total of 1MB in size. Right? If I put count=2 and bs=4mb that would mean a total size of 8mb.

Thanks... :D :D

bs=1 count=1 ... would just write 1 byte, needs to be suffixed with K or M (or specified bs=1000000 count=1 would write 1,000,000 bytes).

bs of 512 is a reasonable choice but a more awkward one to work out multiples of, but in the case of the MBR just one 512 byte write would likely do the trick of 'wiping' it. 1MB however is more certain, and relatively quick/easy.

If I put count=2 and bs=4mb that would mean a total size of 8mb.

Yes that is correct. But use bs=4M (not sure whether bs=4mb would work).

User avatar
mohittomar13
Posts: 51
Joined: Wed Jul 29, 2020 5:12 pm
Location: New Delhi - INDIA
Has thanked: 17 times
Been thanked: 3 times

Re: How to zero out just the MBR of a USB?

Post by mohittomar13 »

Thanks @mikewalsh and @rufwoof
:thumbup: :thumbup:

Laptop: Dell 3568
CPU: intel i3 6006U
RAM: 12 Gigs
4GB-micron + 8GB-kingston

yeah, it works.. :D
HDD: 1TB
OS: Tripple boot- (Windows-10, Xubuntu-20.4LTs, Bionic Puppy) 64Bit

Clarity
Posts: 3675
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1553 times
Been thanked: 493 times

Re: How to zero out just the MBR of a USB?

Post by Clarity »

mohittomar13 wrote: Sat Feb 06, 2021 9:59 am

I often use dd command for filling my USB with zeroes and then later formatting it using the style that I want.

Without your ever doing this, the answer from @rufwoof will work in any of the choices your reference for reuse of your USB. Just format it for whatever future use you want.

mohittomar13 wrote: Sat Feb 06, 2021 9:59 am

filling it with zeroes. Is there some option that I can use with dd so to stop filling the USB after a certain amount of disk if filled with zeroes?

Again, @rufwoof answer to limit the zeros to the 1st 1 million will work. For just MBR removal, use bs=512.

Code: Select all

dd ... bs=512 ...

ALSO, his answer of using GParted when you want to format is probably the one most of us would use vs the fussing with all the terminal commands to achieve a blanking and formating. Menu>System>Gparted where everything is visual.

GParted GUI.jpg
GParted GUI.jpg (18.91 KiB) Viewed 698 times
mohittomar13 wrote: Sat Feb 06, 2021 9:59 am

I suppose this would not render my USB unusable.

any help will be greatly appreciated.

Correct, his instructions will safely achieve your request.

I seem to remember that PUPPY has an editor, somewhere, for "looking" at the contents of blocks (in hex) on an I/O device. But cannot remember where it is.

Hope this is reassuringly helpful

User avatar
rcrsn51
Posts: 1289
Joined: Sun Aug 23, 2020 4:26 pm
Been thanked: 312 times

Re: How to zero out just the MBR of a USB?

Post by rcrsn51 »

You really don`t need to zero out anything. Just run Gparted > Device > Create Partition Table.

gruhyrose
Posts: 3
Joined: Tue Mar 09, 2021 9:44 am

Re: How to zero out just the MBR of a USB?

Post by gruhyrose »

thanks for share, that's awesome.

Post Reply

Return to “Programming”