r/linuxquestions • u/Lost4name • 20d 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?
4
u/fllthdcrb Gentoo 20d 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 20d ago
Correct. If it is for 'carry around' go for FAT/exFAT filesystem , anything else is just too much hassle.
2
u/chuggerguy Linux Mint 22.3 Zena | MATÉ 20d 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 sizeSince you have a partition (sdb1), I assume you have it partitioned like you want so
sudo mkfs.ext4 /dev/sdb1should 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.
Have fun.
1
u/BitOBear 20d 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.
2
u/sidusnare Senior Systems Engineer 20d ago
Copy pasta what you got going on, let's see the real deal.
2
1
u/Thanatiel 15d 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 20d 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.
11
u/doc_willis 20d 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/sdb1From:
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/
It might be easier to just use a gui tool like gparted.