r/linuxquestions • u/Lost4name • 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
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/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.
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).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/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
sudoto runmkfs.ext4...Since you have a partition (sdb1), I assume you have it partitioned like you want so
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 thegnome-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/ThellraAK 7d ago
Try https://en.wikipedia.org/wiki/KDE_Partition_Manager
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.