Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Is it possible to use variables in fstab?

  1. #1
    Join Date
    Feb 2010
    Location
    Italy
    Beans
    177
    Distro
    Lubuntu 12.04 Precise Pangolin

    Is it possible to use variables in fstab?

    I would like to add a line like this in fstab

    Code:
    /media/data/USERNAME/to-be-mounted	mountingpoint	none	bind
    Everything is going right if I put my name in place of USERNAME.
    But how to use a variable instead, in order it to be the name of the logged current user.

    Thanks

  2. #2
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Is it possible to use variables in fstab?

    This isn't possible.

    The fstab file gets processed during start-up before any users are logged on so there is no way of knowing what USERNAME should correspond to.
    Cheesemill

  3. #3
    Join Date
    Mar 2007
    Location
    Portsmouth, UK
    Beans
    Hidden!
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Is it possible to use variables in fstab?

    I assume you could have a mount script later in the boot process (after the user has been identified).

  4. #4
    Join Date
    Feb 2010
    Location
    Italy
    Beans
    177
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Is it possible to use variables in fstab?

    Thanks for your replies.
    Yes .. I thought about a mounting script on boot, but I need sudo to mount .. so the user will see a popup on boot asking to retype password for admin tasks I guess (and the user must be a sudoer) .. is there a way to avoid all this? All I want to do is to auto mount some folders on boot depending on username

  5. #5
    Join Date
    Feb 2007
    Beans
    185

    Re: Is it possible to use variables in fstab?

    automounts via autofs support this type of functionality.

  6. #6
    Join Date
    Feb 2010
    Location
    Italy
    Beans
    177
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Is it possible to use variables in fstab?

    I'm glad to hear about that!
    Can you also give me a short example please?

  7. #7
    Join Date
    Feb 2010
    Location
    Italy
    Beans
    177
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Is it possible to use variables in fstab?

    It seems to me that automount won't help me in my goal. Instead I tested that a boot script has root privileges, (thank you Grenage) so it can come helpful.

    Now I'm try to write such a script, the routine as you might know is to create a bash script named foo in /etc/init.d/ and then run
    Code:
    sudo update-rc.d foo defaults
    Easy up here.
    The problem is: how to get the username of the user just logged-in?

    I'm using a test script like
    Code:
    #! /bin/sh
    # /etc/init.d/blah
    
    touch /var/lock/blah
    username=$(id -n -u)
    touch /var/lock/${username}
    
    exit 0
    The result is that two files are created on /var/lock: blah and root!

    If I logged-in with user 'john' how can I get this info?

    Thanks

  8. #8
    Join Date
    Apr 2008
    Location
    LOCATION=/dev/random
    Beans
    5,767
    Distro
    Ubuntu Development Release

    Re: Is it possible to use variables in fstab?

    Code:
    whoami
    Cheesemill

  9. #9
    Join Date
    Jun 2009
    Location
    SW Forida
    Beans
    Hidden!
    Distro
    Kubuntu

    Re: Is it possible to use variables in fstab?

    I auto edit fstab on a new install, but do have to have sudo.

    Code:
    # make mount points for other partitions
    echo $USER
    mkdir /mnt/cdrive
    #mkdir /mnt/backup
    
    # windows shared NTFS
    mkdir /mnt/shared
    chown $USER:$USER /mnt/shared
    chmod 777 /mnt/shared
    mkdir /mnt/data
    chown $USER:$USER /mnt/data
    chmod 777 /mnt/data
    #The big "X" will also not make files executable unless they were executable to begin with.Morbius1
    #sudo chmod -R a+rwX /mnt/data
    
    # edit fstab to add mounts, UUIDs of data partitions do not change
    cp /etc/fstab /etc/fstab.backup
    #Edit fstab first Need to change from UUID to labels, so it works on both portable & DT
    str1="# Entry for /dev/sdc6 :"
    str2="UUID=a55e6335-616f-4b10-9923-e963559f2b05  /mnt/data    ext3         auto,users,rw,relatime               0  2  "
    str3="# Entry for /dev/sda1 :"
    str4="UUID=04B05B70B05B6768                      /mnt/cdrive           ntfs-3g  ro   0  0  "
    str5="# Entry for /dev/sdc2 :"
    str6="UUID=44332FD360AA9657                      /mnt/shared  ntfs-3g   defaults,uid=1000,nls=utf8,windows_names   0  0  "
    fname=/etc/fstab
    echo $str1 >> $fname
    echo $str2 >> $fname
    echo $str3 >> $fname
    echo $str4 >> $fname
    echo $str5 >> $fname
    echo $str6 >> $fname
    # Verify no errors in fstab & remount with new mounts
    mount -a
    UEFI boot install & repair info - Regularly Updated :
    https://ubuntuforums.org/showthread.php?t=2147295
    Please use Thread Tools above first post to change to [Solved] when/if answered completely.

  10. #10
    Join Date
    Feb 2010
    Location
    Italy
    Beans
    177
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Is it possible to use variables in fstab?

    whoami leads to the same result

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •