Trying to use USB as home directory

If none of the more specific forums is the right place to ask

Trying to use USB as home directory

Postby bedtime » 2018-04-03 19:56

The system is fully loaded in ram, and I would like to use my separate USB flash drive as my home directory. I am able to mount the USB to /mnt and copy it's info into the home directory, but I'd prefer to have it mounted under /home/user so I don't have to keep backing things up and restoring them each time I shut down.

I can mount the home directory with the USB (or at least it seems so), using:
Code: Select all
# mount -t vfat -o umask=777,gid=1000,uid=1000,user /dev/sda /home/


It's when I exit back into user that I have the problems:
Code: Select all
$ cd /home/user
cd:cd:6: permission denied: /home/grml


I've confirmed that my user id is 1000. And all directories within and including /home/user are owned by the user; but, it seems that all the files have no permissions at all. I tried doing a 'chmod -R 755 /home/user' with no error, but no avail. Seems like a place to start.

Code: Select all
root@grml /home # ls -la                 
total 32
d---------  3 grml grml 16384 Jan  1  1970 .
drwxr-xr-x  1 root root   180 Apr  3 20:17 ..
d--------- 22 grml grml 16384 Apr  3 19:16 grml

where 'grml' is the user name.

/etc/fstab:
Code: Select all
# /etc/fstab - static file system information
#
# This file was deployed via grml-live's
# ${GRML_FAI_CONFIG}/config/scripts/GRMLBASE/30-fstab script, using
# ${GRML_FAI_CONFIG}/config/files/etc/fstab/GRMLBASE
#
# <filesystem> <mountpoint>   <type> <options>                             <dump> <pass>
proc           /proc            proc   rw,nosuid,nodev,noexec                0      0
none           /proc/bus/usb    usbfs  defaults,noauto                       0      0
sysfs          /sys             sysfs  rw,nosuid,nodev,noexec                0      0
devpts         /dev/pts         devpts noauto,mode=0622                      0      0
/dev/fd0       /media/floppy    auto   user,noauto,exec                      0      0
/dev/external  /media/external  auto   user,noauto,exec,rw,uid=grml,gid=grml 0      0
/dev/external1 /media/external1 auto   user,noauto,exec,rw,uid=grml,gid=grml 0      0
/dev/cdrom     /media/cdrom     auto   user,noauto,exec,ro                   0      0
/dev/dvd       /media/dvd       auto   user,noauto,exec,ro                   0      0
# some other examples:
# /dev/hda1      /Grml         ext3    dev,suid,user,noauto 0  2
# //1.2.3.4/pub  /smb/pub      smbfs   defaults,user,noauto,uid=grml,gid=grml 0 0
# linux:/pub     /beer         nfs     defaults             0  0
# tmpfs          /tmp          tmpfs   size=300M            0  0
# none           /proc/bus/usb usbfs   defaults,nodev,noexec,nosuid,noauto,devgid=1001,devmode=664 0 0
# 192.168.1.101:/backups /media/nfs nfs  defaults,user,wsize=8192,rsize=8192 0 0
#
# Warning! Please do *not* change any lines below because they are auto-generated by.
# If you want to disable rebuildfstab set CONFIG_FSTAB='no' in /etc/grml/autoconfig!
# See 'man grml-udev-rebuildfstab' for more details about the following entries.
overlay / overlay rw 0 0
tmpfs /tmp tmpfs nosuid,nodev 0 0
# Added by GRML /dev/sda
/dev/usb-sda /media/usb-sda vfat noauto,user,dev,suid,exec,dmask=000,fmask=111,uid=1000,gid=users 0 0 # /dev/sda




Can anyone see what I'm missing here?
bedtime
 
Posts: 55
Joined: 2012-12-16 19:34

Re: Trying to use USB as home directory

Postby p.H » 2018-04-03 20:43

umask is the complement to the permission bits, so umask=777 means permissions=000=no permission.
I guess you want something like umask=022.

Also, these permissions should apply to /home/grml only, not the whole /home (which should be owned by root), so the filesystem should be mounted on /home/grml, not /home.

Also be warned that FAT does not support not only standard Unix permissions but also other standard properties of Unix filesystems such as special files (symbolic links, named pipes, sockets...) and hard links so I am not sure it is suitable for /home.
p.H
 
Posts: 402
Joined: 2017-09-17 07:12

Re: Trying to use USB as home directory

Postby bedtime » 2018-04-03 21:23

p.H wrote:umask is the complement to the permission bits, so umask=777 means permissions=000=no permission.
I guess you want something like umask=022.

Also, these permissions should apply to /home/grml only, not the whole /home (which should be owned by root), so the filesystem should be mounted on /home/grml, not /home.

Also be warned that FAT does not support not only standard Unix permissions but also other standard properties of Unix filesystems such as special files (symbolic links, named pipes, sockets...) and hard links so I am not sure it is suitable for /home.

I moved the /mnt/grml directory to /mnt and ran:
Code: Select all
...
# mkfs.ext4 /dev/sda
...
# mount -t ext4 -o umask=022,gid=1000,uid=1000,user /dev/sda /home/grml


Works perfectly; all user permissions are there, and the user can access (r+w) all their files.

Now it's just a case of running the latter command (and possibly installing a few apps if required) and the user is all set up! No more copying and restoring... So apps run in ram and the app info (in home dir) on usb. :)

Thanks and if you guys have any more tips, I'd like to hear them. I'm new to this area of Linux. :wink:
bedtime
 
Posts: 55
Joined: 2012-12-16 19:34

Re: Trying to use USB as home directory

Postby bedtime » 2018-04-03 22:22

I've been trying to get user or root to execute a file in the home directory and it says:
Code: Select all
grml@grml ~ % ls -la run.sh
-rwxrwxrwx 1 grml root 1622 Apr  3 22:43 run.sh
grml@grml ~ % ./run.sh
zsh: permission denied: ./run.sh


I can execute with root under /mnt when the USB is mounted to it.

I tried running:
Code: Select all
mount -t ext4 -o umask=000,rw,exec,gid=1000,uid=1000,user /dev/sdc /home/grml


And obviously I cannot execute as mount even says so:
Code: Select all
% mount
/dev/sdc on /mnt type ext4 (rw,relatime,data=ordered)
/dev/sdc on /home/grml type ext4 (rw,nosuid,nodev,noexec,relatime,data=ordered,user)


How to allow execution on /home/grml?
bedtime
 
Posts: 55
Joined: 2012-12-16 19:34

Re: Trying to use USB as home directory

Postby p.H » 2018-04-04 08:37

Ext4 natively supports Unix permission thus does not need nor support mount options such as uid, gid and umask. At best unknown options are ignored, at worst they can cause a mount error.

Why do you need the "user" option ? AFAIK this option is used only in /etc/fstab to allow an ordinary user to mount and unmount a given filesystem on a predefined mount point. Also, the mount(8) man page states :
This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).

It means that "exec" must be after "user". In your command it was before.

If you are going to define the mount in /etc/fstab, I recommend to use the UUID or LABEL instead of the device name /dev/sdc because USB device names are not stable.
p.H
 
Posts: 402
Joined: 2017-09-17 07:12

Re: Trying to use USB as home directory

Postby bedtime » 2018-04-04 14:10

p.H wrote:Ext4 natively supports Unix permission thus does not need nor support mount options such as uid, gid and umask. At best unknown options are ignored, at worst they can cause a mount error.

Why do you need the "user" option ? AFAIK this option is used only in /etc/fstab to allow an ordinary user to mount and unmount a given filesystem on a predefined mount point. Also, the mount(8) man page states :
This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid).

It means that "exec" must be after "user". In your command it was before.

If you are going to define the mount in /etc/fstab, I recommend to use the UUID or LABEL instead of the device name /dev/sdc because USB device names are not stable.

Omitting 'user' or putting it after still results in an error...

Code: Select all
 mount -t ext4 -o umask=000,rw,exec,gid=1000,uid=1000 /dev/sda /home/grml


Code: Select all
grml@grml ~ % ./run.sh
mount: only root can use "--options" option
./run.sh: 4: ./run.sh: ,rw,user,exec,gid=1000,uid=1000: not found


..., but it does seem like a step in the right direction (see bottom of code below):
Code: Select all
grml@grml ~ % mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=1946152k,nr_inodes=486538,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=622,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=392100k,mode=755)
/dev/shm on /lib/live/mount/medium type tmpfs (rw,relatime,size=563348k)
/dev/loop0 on /lib/live/mount/rootfs/grml64-full.squashfs type squashfs (ro,noatime)
tmpfs on /lib/live/mount/overlay type tmpfs (rw,relatime)
overlay on / type overlay (rw,noatime,lowerdir=//grml64-full.squashfs/,upperdir=/live/overlay//rw,workdir=/live/overlay//work)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=15936)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,relatime)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=392096k,mode=700,uid=1000,gid=1000)
/dev/sda on /mnt type ext4 (rw,relatime,data=ordered)
/dev/sda on /home/grml type ext4 (rw,relatime,data=ordered)


I'm not able, or at least it doesn't seem possible to edit the fstab file as the system is run in ram on a usb, and I believe the usb is read only.

Thank you for your timely replies. So far, I've learned quite a lot. :)
bedtime
 
Posts: 55
Joined: 2012-12-16 19:34

Re: Trying to use USB as home directory

Postby p.H » 2018-04-04 18:24

What are you trying to achieve exactly ?
Are you trying to mount, as an ordinary user, a filesystem on that user's home directory ? This makes not sense !

Also, if the mount cannot be configured in fstab, then it must be done as root before the ordinary user logs in, otherwise they will see the unmounted contents of the home directorty.

It appears that the filesystem is mounted twice, on /mnt and /home/grml. Do you need it to be mounted on /mnt ?
p.H
 
Posts: 402
Joined: 2017-09-17 07:12


Return to General Questions

Who is online

Users browsing this forum: No registered users and 6 guests

fashionable