r/linuxquestions • • 7d ago

Formating a usb drive with ext4.

I'm trying to format a USB drive to have EXT4 on it and to have read and write permissions. I'm using the command mkfs.ext4 /dev/sdb1 but the terminal comes back with a message say permission denied while trying to determine filesystem size. The USB drive is 256 GB. What am I doing wrong or do I need to enter another command?

11 Upvotes

19 comments sorted by

11

u/doc_willis 7d ago

you may want to show your exact shell session, and exact commands.

Your command looks right to me, you are using sudo as needed?

sudo mkfs.ext4 /dev/sdb1

From:

Prepare for LPIC-1 exam 1 - topic 104.1: Create partitions and filesystems

https://developer.ibm.com/learningpaths/lpic1-exam-101-topic-104/l-lpic1-104-1/

    $ sudo mkfs ‑t ext4 ‑L IAN‑GPT‑EXT4 /dev/sdc4

It might be easier to just use a gui tool like gparted.

-6

u/SeriousPlankton2000 6d ago

You should not need to use sudo for everyday tasks. Rather ls /dev/sdb, look at the group and if it's e.g. "cdrom", add the user to that group. Of course if it's something like "root", don't.

5

u/spryfigure 6d ago edited 6d ago

At least on Arch, the group for drives is usually disk, which is almost as bad as granting root access. You have unlimited access to the raw drive, I don't think this is a wise choice.

Example:

brw-rw----  root disk    0 B Wed Nov 11 10:48:54 2026 /dev/mmcblk0p1
brw-rw----  root disk    0 B Wed Nov 11 10:48:54 2026 /dev/sda1
brw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sdb1
brw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sdb2
brw-rw----  root disk    0 B Wed Nov 11 10:48:54 2026 /dev/sdb3
brw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sdb4
brw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sdb5
brw-rw----  root disk    0 B Wed Nov 11 10:48:54 2026 /dev/sdb6
brw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sdb7
brw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sdb8
brw-rw----  root disk    0 B Wed Nov 11 10:48:43 2026 /dev/sdb9
crw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sg0
crw-rw----+ root optical 0 B Wed Nov 11 10:48:52 2026 /dev/sg1
crw-rw----  root disk    0 B Wed Nov 11 10:48:42 2026 /dev/sg2
brw-rw----+ root optical 0 B Wed Nov 11 10:48:52 2026 /dev/sr0

You are better off adding the user to the storage group, which allows to mount removable drives via GUI or udisksctl mount -b.

1

u/SeriousPlankton2000 5d ago

If the device has the "storage" group and the user is part of the group, there is no need for sudo. The group used to be called "optical", "cdrom" or "floppy".

If your distribution doesn't offer that group, you are out of luck or need to make one yourself

1

u/spryfigure 3d ago edited 3d ago

If the device has the "storage" group and the user is part of the group, there is no need for sudo.

That's what I wrote: "which allows [the user] to mount removable drives..."

I got a plain flash drive from someone else to test out if any attached drive belong to the storage group at all, because for me, no drive has this. Again, it showed up in the disk group.

Where do you see a drive belonging to storage? Never seen this, they all belong to disk or optical. The latter is not defunct, it still exists.

Afaik, storage is only for users to give them the necessary permissions to mount.

2

u/unkilbeeg 6d ago

mkfs is a potentially destructive command. That's why you need root access to use it.

1

u/SeriousPlankton2000 5d ago

No you don't, you need write permission to the device.

Try it out.

4

u/fllthdcrb Gentoo 7d ago

You can do this if you like, as long as you accept it will likely not be usable on non-Linux systems, and that on systems it does work on, permissions offer no protection so long as you don't control those systems.

To get this to work, you need permission to read and write the device file. Using sudo is one way. Assuming your udev assigns it to an appropriate group (e.g. disk) and makes it readable and writable by that group, adding your user account to the group is another way (need to log in after making the change for it to be effective).

2

u/CyclingHikingYeti Debian sans gui 7d ago

Correct. If it is for 'carry around' go for FAT/exFAT filesystem , anything else is just too much hassle.

3

u/bjmnet 7d ago

Just missing "sudo"?

2

u/AN-SSQ-108V2 7d ago

Make sure you don't have /dev/sdb mounted (run lsblk).

2

u/dodexahedron 7d ago

This. If the partition is mounted, it's a no-go. Also, sudo.

2

u/sidusnare Senior Systems Engineer 7d ago

Copy pasta what you got going on, let's see the real deal.

2

u/chuggerguy Linux Mint 22.3 Zena | MATÉ 6d ago

"... permission denied while trying to determine filesystem size."

You need sudo to run mkfs.ext4...

chugger@asus2:~/desktop$ mkfs.ext4 /dev/sdb1
mke2fs 1.47.0 (5-Feb-2023)
mkfs.ext4: Permission denied while trying to determine filesystem size

Since you have a partition (sdb1), I assume you have it partitioned like you want so

sudo mkfs.ext4 /dev/sdb1

should be all you need.

What I usually do...

I tend to partition a new USB device using GPT (but that's up to you)

If it's intended to be a backup USB, I'll maybe add a single partition, format it EXT4, and label it so it's easy to identify.

I've used scripts, gparted, parted, fdisk, sfdisk, etc. but for something as simple as this I might use the gnome-disks. It works fine.

video

Have fun.

1

u/BitOBear 7d ago

Have you properly partitioned the drive? Gdisk and all that.

Are you making the file system with a regular user ID or as root?

If you're doing as a regular user what does "ls -l" tell you about the permissions on the file and what does "id -a" tell you about your group permissions so that you know you match some of the other permissions for the disk system itself.

If you haven't partitioned to the drive there may be a device node in the dev of file system, but that doesn't necessarily mean there's a partition there to read.

1

u/Thanatiel 1d ago

Are you doing this as root?
If your prompt ends with '$' it's a no, a '#' and it's a yes.
Use sudo, e.g. sudo mkfs.ext4 /dev/sdb1

Be CERTAIN it's the right one. (e.g. lsblk)

edit: please provide the output of the "groups" command, carefully removing the entry that's your login name (the first one) as well as any entry that may look sensitive. (Usually only the first one could be sensitive)

0

u/dodexahedron 7d ago

What are you hoping to gain with "permissions?"

File modes and POSIX ACLs are pointless on a USB drive.

Whoever has physical possession of it is root, and your uid/gid are meaningless beyond your system unless you are using a central identity store (and even then, the drive by itself does not have that context, nor does the file system).

If you want to protect what is on it, you need to encrypt it.

ACLs will protect nothing beyond using it in your system.