Automount ext4 partition with user permission/ownership (fstab?) [duplicate]

  1. I just installed Lubuntu 12.10 "Quantal Quetzal" on my Acer Aspire One D257, creating the partitions:

    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda5        15G  2.1G   12G  15% /
    ...
    /dev/sda1      1008M   62M  896M   7% /boot
     /dev/sda6        15G  180M   14G   2% /home
    /dev/sda4       195G  188M  185G   1% /media/data
    

    (or see partitions.png:)

    partitions.png

    (I know boot partitions were useful for old bios, but now they are also useful for encryption, LVM... (though differerent from a dedicated GRUB partition !))

  2. I renamed the "data" partition (=sda4) flag/name (using utility Disks).

  3. I have been trying for hours now to find a solution to:

    How to get my data partition (not my home partition!) to auto-mount at boot time somewhere (if possible in /media/data) with me (user = christophe) as owner and the permissions as rwxrwxr-x (=user:rwx, group:rwx, other:r-x)?

  4. My problems are that every time I reboot:

    • /media/data is back under root ownership
    • /media/data is back under rwxr-xr-x permissions
    • /media/data content is back as just lost+found (!!!)
    • frequently, when trying options in /etc/fstab, I had "an error occurred while mounting /media/data" at boot time.
  5. I tried mostly to edit my /etc/fstab file. Now it is:

    $ cat /etc/fstab
    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    # / was on /dev/sda5 during installation
    UUID=8325697c-2c27-49dd-99f8-2a1a3e1467be /               ext4    errors=remount-ro 0       1
    # /boot was on /dev/sda1 during installation
    UUID=3ba24cc6-e38b-48d9-b526-68358783d980 /boot           ext4    defaults        0       2
    # /home was on /dev/sda6 during installation
    UUID=1ef16ece-0965-4611-a2e5-dd687f4ee5ff /home           ext4    defaults        0       2
    # /media/data was on /dev/sda4 during installation
    # UUID=0598f54b-dcf8-4508-97de-94d9f2c5e2a8 /media/data   ext4    defaults        0       2
    UUID=0598f54b-dcf8-4508-97de-94d9f2c5e2a8 /media/data     ext4    rw,suid,dev,exec,auto,user,async,errors=remount-ro,relatime,uid=1000,gid=1000        0       2
    # swap was on /dev/sda2 during installation
    UUID=04f73159-479d-4a4b-a78c-37a406909225 none            swap    sw              0       0
    
  6. In a way, I'd like my data partition to automount like my home partition.

  7. I do not want a solution where I would have to chmod or chown or do something every time I (re)boot!

Thanks.


Solution 1:

There are no uid options for ext[234]. If you want to change the permissions of the files, you have to use chown/chmod.

sudo chown -R myname.myname /media/data/

Solution 2:

I think the key was to mount in either /mnt/data or /media/username/data (username = christophe in my case) !!! I don't know why it works, but it seems to do so...

Definition of "works" :

  1. Get my data partition to auto-mount at boot time in location (media/christophe/data or /mnt/data) with user_name (= me = christophe) as owner. (Note: I have not dealt yet with the permissions (as rwxr--r-- (= user:rwx, group:r--, other:r--))).

  2. Every time I reboot:

    • the owner of location is not root, but user_name (me, christophe)
    • the content of location content is not wiped-out, but is persistent
    • there is no "an error occurred while mounting ..." at boot time.
    • the solution is a one-time solution, not every-time

Solutions:

  1. Solution in /mnt/.

    • Edit /etc/fstab (for example $ sudo nano /etc/fstab) and add the line:

      UUID=your_uuid_value  /mnt/data       ext4    defaults        0       2
      
    • Double check before rebooting:

      $ ls -l /mnt/
      total 0
      
    • Reboot

    • Double check after rebooting:

      $ ls -l /mnt/
      total 4
      drwxr--r-- 2 christophe christophe 4096 Dec 26 04:02 data
      $ ls -l /mnt/data/
      total 4
      -rw-rw-r-- 1 christophe christophe 6 Dec 26 04:07 1.txt
      
    • Conclusion: It does work BUT it does not appear as a media in file manager (nautilus, PCManFM, ...) [see file_manager.png]

  2. Solution in /media/username:

    • In terminal:

      $ sudo mkdir -p /media/username/
      

      Or, in my case:

      $ sudo mkdir -p /media/christophe/
      
    • Double check before rebooting:

      $ ls -l /media/
      total 4
      drwxr-xr-x 3 root root 4096 Dec 26 04:25 christophe
      $ ls -l /media/christophe/
      total 0
      
    • Edit /etc/fstab (for example $ sudo nano /etc/fstab) and add the line:

      UUID=your_uuid_value  /media/christophe/data       ext4    defaults        0       2
      
    • Reboot

    • Double check after rebooting:

      $ ls -l /media/
      total 4
      drwxr-xr-x 3 root root 4096 Dec 26 04:25 christophe
      $ ls -l /media/christophe/
      total 4
      drwxr--r-- 2 christophe christophe 4096 Dec 26 04:31 data
      $ ls -l /media/christophe/data/
      total 4
      -rw-rw-r-- 1 christophe christophe 6 Dec 26 04:37 2.txt
      
    • Conclusion: It does work AND it does indeed appear as a media in file manager (nautilus, PCManFM, ...) [see file_manager.png]file_manager.png

Please feel free to add any comments, problems, or suggestions to this thread. I lost so many hours in that, I hope it will help others. In particular, I'd be curious to know why it works...

Cheers.