7

I have a USB device /dev/sda1 and I want to format it as ext4. I have tried

sudo mkfs.ext4 /dev/sda1

It gives warning, goes ahead and completes formatting without error. But when I check it using sudo fdisk -l, I can see that it is still FAT32,

  Device     Boot Start      End  Sectors Size Id Type
  /dev/sda1        8192 62816255 62808064  30G  c W95 FAT32 (LBA)

I don't have any data on it and I just want to change the file system..

Please advise.

Thanks,

usmanayubsh
  • 377
  • 5
  • 16
Ahmed
  • 921

1 Answers1

6

You can try to change the partition type in fdisk. To do this, run fdisk /dev/sda with t you can change your partition type in fdisk, which will lead you through the process. Your partition number should be 1 (because of /dev/sda1) and you should choose the partition type 83 (Linux).
Then try again to run mkfs.ext4 /dev/sda1.

EDIT: To have a better check for your fs type, run df -T which shows you the correct type of each partition.

jklmnn
  • 181
  • 2
    I have no idea why this is downvoted. The partition type (which jklmnn tells you to change) has nothing to do with the actual filesystem used. It basically is a flag in the MBR (A USB stick usually uses MBR), and you can see the value of it in the "Id" column of the fdisk output.

    So, using mkfs.ext4, is not enough. You end up with a partition that has ext4 structures on it, but the partition table thinks it's FAT32. You have to do both. Stuff like GParted and so do this for you, but if you want or need to do it manually (on a sever, for example), this is the way to go.

    – jawtheshark Aug 17 '16 at 08:05
  • @jawtheshark I'm trying to work out how to reformat ext4 without a DOS partition table but it seems most answers assume a lot and just give constricted GUI based solutions. It sounds like you might have enough knowledge to make a really good answer here, putting in the trade offs with different partition tables and outlining a good command line manual approach. Or maybe jklmnn could do it. – NeilG Dec 11 '21 at 10:51
  • @NeilG What do you mean by "without a DOS partition table"? No partition table or a different type (e.g. GPT)? You can use a block device without partitions at all. Just use mkfs on the device you want your ext4 on (e.g. /dev/sda instead of /dev/sda1). If you want a different type of partition table you can still use the above explanation and just select your intended partition table after pressing t. – jklmnn Dec 11 '21 at 22:04
  • I didn't know that, @jklmnn, I'd like to know more about the different trade offs and use cases for things like not using a partition table. I've reformatted my 960GB external SSD with GPT and ext4 in one partition now, but perhaps I should ask a new question here for more general info on how to do that and what are the advantages? Are you interested? – NeilG Dec 12 '21 at 23:41
  • I would suggest you start a new question instead of hijacking an old thread. – jawtheshark Dec 13 '21 at 08:45
  • 1
    @NeilG To give a really short/ simplified answer: A file system is basically an abstraction layer that lets you use files without having to care about the underlying storage medium (mostly). Usually that medium is a block device. That's just a storage medium that is divided into equally sized blocks that can only be accessed as a whole. These blocks are numbered starting from 0. A partition manager takes the whole device, divides it into part(ition)s and provides multiple new devices that each start from block 0. The file system doesn't really care where it is, it just wants a block device. – jklmnn Dec 20 '21 at 20:07
  • But as @jawtheshark pointed out, you should open a separate question for any more thorough explanation on that. – jklmnn Dec 20 '21 at 20:08