# [SOLVED] mounting usb stick as ext2

## Joseph_sys

What "umask" option should I use in fstab in order to have ext2 formated usb stick writable?

The option below, will mount it but I can not write anything to it.

```
/dev/sdb1               /media/stick    auto    noauto,rw,users,exec  0 0
```

I had USB stick formated as FAT32 but over period of time the space is being used by something and 1/3 of the USB stick is useless; as an example my 4Gb stick was showing as:

```
/dev/sdb1             3.8G  1.0G  2.8G  27% /media/stick
```

 and there is nothing on it, no hidden files no /.trash, nothingLast edited by Joseph_sys on Wed Jul 13, 2011 9:19 pm; edited 1 time in total

----------

## Joseph_sys

When I mount, Vfat usb stick it mounts as:

drwxr-xr-x 11 joseph root 8192 Dec 31  1969 stick

If I mount ext2 formated usb stick, it mounts as:

drwxr-xr-x 2 root root 4096 Nov 28  2009 stick

Is there a way to control it via fstab options?

----------

## Etal

Not sure if this will help, but I notice you have an "s" in users. It should be just "user".

----------

## Joseph_sys

 *Etal wrote:*   

> Not sure if this will help, but I notice you have an "s" in users. It should be just "user".

 

I've tried it with user and users make no difference.

I solve the problem but I don't understand why it works.

When the drive was mounted: as root:root

I change the ownership to: joseph:root

When I unmounted and mounted again the owner ship was correct: joseph:users 

I don't understand why it works.

----------

## DirtyHairy

No mystery here: as FAT doesn't support user / group information, the filesystem driver has to decide which uid / gid is returned, and I am pretty sure the defaults are the uid / gid of the mounting user. Ext2 on the other hand stores uid / gid in the filesystem, and if the root of the stick belongs to root:root (and isn't writable for all) you won't be able to change anything there (unless you create a directory for your user as root). All you did is change the owner of the filesystem root and, voila, you can write  :Wink: 

----------

## Joseph_sys

 *DirtyHairy wrote:*   

> No mystery here: as FAT doesn't support user / group information, the filesystem driver has to decide which uid / gid is returned, and I am pretty sure the defaults are the uid / gid of the mounting user. Ext2 on the other hand stores uid / gid in the filesystem, and if the root of the stick belongs to root:root (and isn't writable for all) you won't be able to change anything there (unless you create a directory for your user as root). All you did is change the owner of the filesystem root and, voila, you can write 

 

Yes, FAT work working as it should be, the owner of the file is the one who mounts the file system.

With ext2 it seems to me the owner is the last person who mounted it.

I login as a different user and after mounting USB stick the owner was still joseph:root 

Is there a way to manipulate it via fstab what the owner of the file system should be the person who mount it?

----------

## Jaglover

So why is your user member of root, sending all security down the pipes. Haven't you ever heard root privileges are used only for system management and should be dropped as soon as there is no need for it?

You should use a group, as users. Then you should use file creation mask that gives write rights to the users group. You'll be able to alter files as you like.

----------

## Joseph_sys

 *Jaglover wrote:*   

> So why is your user member of root, sending all security down the pipes. Haven't you ever heard root privileges are used only for system management and should be dropped as soon as there is no need for it?
> 
> You should use a group, as users. Then you should use file creation mask that gives write rights to the users group. You'll be able to alter files as you like.

 

I'm in the group "wheel" my users don't have those privileges, so there is no security issue here.

However, when my users mount the ext2 usb stick it mount is as joseph:root so they can not write to it.

my fstab entry:

/dev/sdb1		/media/stick	auto    	noauto,rw,users,exec 	 0 0

How do I use group as users?

I've tried in fstab:

noatime,user,exec,dev,suid,gid=users,umask=000  0  0

but I get an error message, 

mount: wrong fs type, bad option, bad superblock on /dev/sdb1,

----------

## Joseph_sys

It seems is to me Linux OS remember the state of the last mounted device.

Simply changing `chmod 770 /media/stick, chown root:users /media/stick` with ext2 (while

mounted).

ext2 stores this and will use the same permissions the next mount.  It seems to me this information is linked to USB device ID: 

lsusb

While this will work for a particular device, I'll end up with the same problem when I try to mount different USB stick formated with ext2.

I wish it could be controlled by fstab.

----------

## Ant P.

Any reason why you're not using UDF instead, if you don't want the filesystem to store permissions?

----------

## DirtyHairy

Nothing is being linked to the USB ID, and there is no mysterious "remembering" involved; on an ext2/3/4 (and many others) filesystem, every file and directory has an owner, identified via uid/gid and stored directly in the filesystem. Using chmod, you change this information, plain and simple. If this doesn't suit you for your pendrive, then you should use another filesystem.

----------

## Joseph_sys

 *DirtyHairy wrote:*   

> Nothing is being linked to the USB ID, and there is no mysterious "remembering" involved; on an ext2/3/4 (and many others) filesystem, every file and directory has an owner, identified via uid/gid and stored directly in the filesystem. Using chmod, you change this information, plain and simple. If this doesn't suit you for your pendrive, then you should use another filesystem.

 

I think you are correct.

I mounted the USB ext2 stick on a different system and it mounted with the same permissions.

So, FAT file system can be controlled via fstab entry when it comes ownership and permission with ext2/4/3 it is written into the file-system, in this case usb stick.

----------

