7 votes

Formatting USBs with live Linux... what's the right way?

I hope I am blind to something here... but every time I want to wipe a USB that had a linux distro on it (Mint, in this case) I have to hop into Windows and use DISKPART. Just now the stupid thing didn't say it was read only (by flags), but I had to clear that anyway before it would clean

I am wiping this to create a macOS installer. I tried to clear it on MacOS, EndeavourOS (with partitionmanager), and Windows (Explorer before DISKPART)

All this said, I love DISKPART and I will never speak ill of it. Its simple and effective and just works.

13 comments

  1. [8]
    Pavouk106
    Link
    You can do as root or via sudo: dd if=/dev/zero of=/dev/sdX bs=1M count=1 where sdX stands for your USB flash (ie. sdc). Don't mess that up or you can destroy data on any of your disks in your PC!...
    • Exemplary

    You can do as root or via sudo:

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

    where sdX stands for your USB flash (ie. sdc). Don't mess that up or you can destroy data on any of your disks in your PC! You won't be asked ANYTHING when you execute the command, it will get done!

    This basically deletes the partition table of the disk, which in turn makes it completely blank (well, data is still written...). You have to partitipn and format it after doing that. You can use parted, fdisk or cfdisk to partition and then:

    mkfs.fat -F 32 /dev/sdX#

    where sdX stands for drive and # is the number of partition you want to format (ie. sdc1). You can use mkfs.exfat if you need exFAT instead of FAT32.

    If you have anything to ask, do so. You want to be sure before you do anything.

    5 votes
    1. [2]
      archevel
      Link Parent
      If I just need an install medium and not a portable USB where I can store things I usually just do: dd if=/some/path/<distro>.iso of=/dev/sdX bs=4M And it's ready to go. No need to zero anything...

      If I just need an install medium and not a portable USB where I can store things I usually just do:

      dd if=/some/path/<distro>.iso of=/dev/sdX bs=4M
      

      And it's ready to go. No need to zero anything out unless you are using an old drive with sensitive info on. This is only useful if you don't intend to use it as a storage device though and only as an install media.

      2 votes
      1. Pavouk106
        Link Parent
        When you need to make bootable USB stick, your command is the easiest way. It will dump whatever is on the stick and make it bootable OS one. I suppose my instructions could be called "get such...

        When you need to make bootable USB stick, your command is the easiest way. It will dump whatever is on the stick and make it bootable OS one.

        I suppose my instructions could be called "get such USB stick back to being mass storage".

    2. [3]
      tomf
      Link Parent
      ok! yeah -- that totally makes sense. I don't get why the GUIs can't do the same. Excellent write up!

      ok! yeah -- that totally makes sense. I don't get why the GUIs can't do the same. Excellent write up!

      1 vote
      1. Nihilego
        Link Parent
        Does gparted not work or come installed with the Live USB?

        Does gparted not work or come installed with the Live USB?

        2 votes
      2. Pavouk106
        Link Parent
        GUIs can't do many things because even though they pften use the same commands in the background, their developer didn't add all the possibilities of the said command-line program. I used some GUI...

        GUIs can't do many things because even though they pften use the same commands in the background, their developer didn't add all the possibilities of the said command-line program.

        I used some GUI programs back in the day to do video re-encoding (no editing, just encode to different format) and since some didn't allow for custom bitrate, some didn't allow for custom resolutions, some didn't allow for specific codecs... I just learned how to use ffmpeg in command line. Since then, I don't bother with GUI programs when I just need to re-encode video.

        I learned a lot since my beginning days with Linux. And the most useful thing I learned is to use command line when possible.

        1 vote
    3. [2]
      fxgn
      (edited )
      Link Parent
      FYI, you don't actually need dd for this. You can just run cat /dev/zero > /dev/sdX (and burn ISOs with cp file.iso /dev/sdX). Unless you actually need something that requires specific block...

      FYI, you don't actually need dd for this. You can just run cat /dev/zero > /dev/sdX (and burn ISOs with cp file.iso /dev/sdX). Unless you actually need something that requires specific block sizes, which you usually don't, you don't need dd.

      https://www.vidarholen.net/contents/blog/?p=479

      You can even run curl ... > /dev/sdX to just directly flash an ISO from a URL!

      https://astrid.tech/2026/03/24/0/curl-to-dev-sda/

      cc @archevel, @tomf

      1 vote
      1. Pavouk106
        Link Parent
        Nice approach! I just described how I would do it. You can do it in many ways, obviously.

        Nice approach!

        I just described how I would do it. You can do it in many ways, obviously.

  2. first-must-burn
    Link
    I have gotten a lot of good use out of gparted although admittedly not in the past 5-10 years. I have always used it with the Linux system rescue as a bookable CD, which probably dates my usage....

    I have gotten a lot of good use out of gparted although admittedly not in the past 5-10 years. I have always used it with the Linux system rescue as a bookable CD, which probably dates my usage. It's a great tool for expanding Windows partitions without reinstalling Windows. I've even used it to copy a windows partition onto a new drive and then expand it. I like the visual aspect because it's easier for me to be sure that I'm doing what I think I'm doing. Also a lot of the operations you can stack up and visualize before you actually commit to the operation.

    2 votes
  3. preposterous
    Link
    If it often mounts RO, it’s possible the stock’s flash is failing and the internal controller blocks any writes to it. Doesn’t happen very often but if the stick is old and has been used a lot,...

    If it often mounts RO, it’s possible the stock’s flash is failing and the internal controller blocks any writes to it. Doesn’t happen very often but if the stick is old and has been used a lot, it’s a possibility.

    1 vote
  4. bo0tzz
    Link
    I swear by https://github.com/ifd3f/caligula, it's a whole lot nicer and simpler than dd.

    I swear by https://github.com/ifd3f/caligula, it's a whole lot nicer and simpler than dd.

  5. arqalite
    Link
    Wouldn't Rufus be able to do it? You can tell it to not flash anything on it and just format as FAT32. I haven't touched any other disk utility since Rufus came out (but tbh I also try out fewer...

    Wouldn't Rufus be able to do it? You can tell it to not flash anything on it and just format as FAT32.

    I haven't touched any other disk utility since Rufus came out (but tbh I also try out fewer and fewer distros as time goes on, Fedora and Zorin are good enough for my purposes).

  6. jcd
    Link
    Ventoy is really worth checking out as a modern way for bootable usbs. You just copy the iso on the ventoy partition of the usb and it works. Supports both windows and linux isos....

    Ventoy is really worth checking out as a modern way for bootable usbs. You just copy the iso on the ventoy partition of the usb and it works. Supports both windows and linux isos.
    https://www.ventoy.net/en/index.html