19 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.

23 comments

  1. [14]
    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.

    11 votes
    1. [5]
      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

      7 votes
      1. pra
        Link Parent
        The count=1 in grandparent does save you from writing to the entire USB drive, which the suggested cat command doesn't do. Only zeroing out the first megabyte is sufficient to save yourself some...

        The count=1 in grandparent does save you from writing to the entire USB drive, which the suggested cat command doesn't do.

        Only zeroing out the first megabyte is sufficient to save yourself some warnings in partition editors while saving one write cycle over the bulk of the drive, and also saves a few seconds to minutes of waiting depending on the size and speed of things.

        As Vidar's post mentions, not all uses of dd are useless.

        You should always check your sums, though, especially with large downloads and especially with security exploits landing so frequently in this pre-singularity age.

        2 votes
      2. 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.

      3. archevel
        Link Parent
        Nice! I didn't know that worked. I would caution against piping curl output directly for the same reason you really shouldn't use it to pipe things into sh which seem to be popular for some tools...

        Nice! I didn't know that worked. I would caution against piping curl output directly for the same reason you really shouldn't use it to pipe things into sh which seem to be popular for some tools as an install method. I prefer downloading and a quick sha256sum to verify. But, nice to know anyway!

      4. Crestwave
        Link Parent
        dd also has status=progress, which can be nice for slow flash drives. It also has handy flags for syncing, otherwise you think you're done with the copy then have to wait ages for your eject to...

        dd also has status=progress, which can be nice for slow flash drives. It also has handy flags for syncing, otherwise you think you're done with the copy then have to wait ages for your eject to complete.

        pv is probably my favorite replacement, as it has both progress built-in and a --sync flag.

    2. [4]
      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. [2]
        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?

        3 votes
        1. tomf
          Link Parent
          probably -- but this is clearing the stick to use it for something else :)

          probably -- but this is clearing the stick to use it for something else :)

          1 vote
      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.

        3 votes
    3. [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.

      1 vote
      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".

        1 vote
    4. [2]
      Octofox
      Link Parent
      This certainly works and is the traditional way of doing it, but it’s such a dangerous command, it’s a single character difference between setting up a Linux usb and formatting your computer....

      This certainly works and is the traditional way of doing it, but it’s such a dangerous command, it’s a single character difference between setting up a Linux usb and formatting your computer.

      These days we have GUI programs which make it clear you are targeting a 32gb external usb rather than “sdb1”. Personally I use the raspberry pi imager app but there are many other similar programs.

      1 vote
      1. Pavouk106
        Link Parent
        That's why I said user must be certain what they are doing. It is fast way to hell! And to heaven as well! The destination lies in that one character. This is what I love about Linux command line...

        That's why I said user must be certain what they are doing. It is fast way to hell! And to heaven as well! The destination lies in that one character.

        This is what I love about Linux command line - you execute it, it gets done. It can nuke your PC or even server, but it just gets done.

        With great power comes great responsibility.

  2. [2]
    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

    9 votes
    1. Narry
      Link Parent
      This is the best one right here. I tried it once and I'm not going back.

      This is the best one right here. I tried it once and I'm not going back.

      1 vote
  3. 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.

    4 votes
  4. 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.

    2 votes
  5. kfwyre
    Link
    Mint has built-in software that should let you do it: USB Image Writer under Accessories

    Mint has built-in software that should let you do it:

    2 votes
  6. [2]
    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).

    1 vote
    1. tomf
      Link Parent
      in this case I am wiping it but not for a distro. Rufus or Etcher would likely do it, though.

      in this case I am wiping it but not for a distro. Rufus or Etcher would likely do it, though.

      2 votes
  7. xk3
    (edited )
    Link
    This creates a new GPT partition table with a linux partition: sudo sgdisk --zap-all -n 0:0:0 -t 0:8300 /dev/sdX Then you can do mkfs on /dev/sdX1. You could also do sudo wipefs -a /dev/sdX to...

    have to hop into Windows and use DISKPART

    This creates a new GPT partition table with a linux partition:

    sudo sgdisk --zap-all -n 0:0:0 -t 0:8300 /dev/sdX
    

    Then you can do mkfs on /dev/sdX1.

    You could also do sudo wipefs -a /dev/sdX to clear the device but the above --zap-all already includes this step. If you have sgdisk you don't really need wipefs.


    If you want a bootable USB just do:

    sudo dd bs=4M oflag=direct status=progress if=Fedora-KDE-Desktop-Live-44.iso of=/dev/sdX
    

    And this should do all that you need to do for you as long as you used /dev/sdX and not /dev/sdX1.

    1 vote