LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   systemd mounts (https://www.linuxquestions.org/questions/linux-general-1/systemd-mounts-4175677622/)

marozsas 06-25-2020 02:25 PM

systemd mounts
 
Hi there,

A few weeks ago I came here with a problem that not all file systems being mounted at boot time (https://www.linuxquestions.org/quest...ot-4175677301/)

Turns out the probable cause, as suggested by @The Squash and @syg00 was the order the system mounts file systems and the fs that I wanted to mount depends on other fs to be mounted first (/home). This cause an erratic behavior. Sometimes it get mounted other times it don't, depending on which get mounted first.

So, to fix that I moved my mounts from /etc/fstab to a unit file to get mounted by systemd.

Code:

UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /                      btrfs  defaults                      0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /var                    btrfs  subvol=/@/var                0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /usr/local              btrfs  subvol=/@/usr/local          0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /tmp                    btrfs  subvol=/@/tmp                0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /srv                    btrfs  subvol=/@/srv                0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /root                  btrfs  subvol=/@/root                0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /opt                    btrfs  subvol=/@/opt                0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /home                  btrfs  subvol=/@/home                0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /boot/grub2/x86_64-efi  btrfs  subvol=/@/boot/grub2/x86_64-efi  0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /boot/grub2/i386-pc    btrfs  subvol=/@/boot/grub2/i386-pc  0  0
UUID=cda3f542-59ea-4e2f-be54-df8e4ffa1aa5  swap                    swap  defaults                      0  0
UUID=3d62e0b9-5a9c-43b2-954f-0a50077cbb25  /.snapshots            btrfs  subvol=/@/.snapshots          0  0
#
# Home Miguel extra folders on slow disk
# UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /mnt/btrfs                    btrfs  subvol=/                      0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/Documents  btrfs  subvol=/miguel/Documentos    0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/Downloads  btrfs  subvol=/miguel/Downloads      0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/Pictures  btrfs  subvol=/miguel/Imagens        0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/Misc      btrfs  subvol=/miguel/Misc          0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/Music      btrfs  subvol=/miguel/Musica        0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/ProgramasRFB      btrfs  subvol=/miguel/ProgramasRFB          0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/tmp        btrfs  subvol=/miguel/tmp          0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/Videos    btrfs  subvol=/miguel/Videos          0  0
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /home/miguel/src/UPSData      btrfs  subvol=/miguel/src/UPSData          0  0
#
# transmission-daemon
#UUID=af3bd7fe-5796-4248-9917-3e71a5a56ec6  /var/lib/transmission  btrfs  subvol=/transmission          0  0

And created several unit files like this one. The others are identical, except by the fs itself.
Code:

[Unit]
Description=Mount /home/miguel/Documentos
After=home.mount

[Mount]
What=/dev/disk/by-uuid/af3bd7fe-5796-4248-9917-3e71a5a56ec6
Where=/home/miguel/Documents
Type=btrfs
Options=defaults,subvol=/miguel/Documentos

[Install]
WantedBy=multi-user.target

The problem is it works only 1 or 2 in 7 boots. Very annoying. When it don't work after the boot, "systemctl start home-miguel-Documents.mount" mounts the fs as expected, no warnings, no messages....

I have no indication of failure, other than that strange pattern Mounted/Umounting/mount: succeeded/Umount at end of status and, of course, reported by "journalctl -b -u home-miguel-Documents.mount"...

Code:

systemctl status home-miguel-Documents.mount
● home-miguel-Documents.mount - Mount /home/miguel/Documentos
    Loaded: loaded (/etc/systemd/system/home-miguel-Documents.mount; enabled; vendor preset: disabled)
    Active: inactive (dead) since Thu 2020-06-25 15:43:03 -03; 27min ago
      Where: /home/miguel/Documents
      What: /dev/disk/by-uuid/af3bd7fe-5796-4248-9917-3e71a5a56ec6

Jun 25 15:43:02 kimera systemd[1]: Mounted Mount /home/miguel/Documentos.
Jun 25 15:43:03 kimera systemd[1]: Unmounting Mount /home/miguel/Documentos...
Jun 25 15:43:03 kimera systemd[1]: home-miguel-Documents.mount: Succeeded.
Jun 25 15:43:03 kimera systemd[1]: Unmounted Mount /home/miguel/Documentos.

I already tried with and without "After=home.mount" , no effect.
The current mount targets in my system (openSuSE tumbleweed) are:
(this one: Documents in status active is because I issued the start command in a console. Before it was inactive, like the others)
Code:

systemctl list-units --type=mount --all
  UNIT                          LOAD      ACTIVE  SUB    DESCRIPTION                                 
  -.mount                        loaded    active  mounted Root Mount                                 
  \x2esnapshots.mount            loaded    active  mounted /.snapshots                                 
  boot-grub2-i386\x2dpc.mount    loaded    active  mounted /boot/grub2/i386-pc                         
  boot-grub2-x86_64\x2defi.mount loaded    active  mounted /boot/grub2/x86_64-efi                     
● boot.mount                    not-found inactive dead    boot.mount                                 
  dev-hugepages.mount            loaded    active  mounted Huge Pages File System                     
  dev-mqueue.mount              loaded    active  mounted POSIX Message Queue File System             
  home-miguel-Documents.mount    loaded    active  mounted Mount /home/miguel/Documentos               
  home-miguel-Downloads.mount    loaded    inactive dead    Mount /home/miguel/Downloads               
  home-miguel-Misc.mount        loaded    inactive dead    Mount /home/miguel/Misc                     
  home-miguel-Music.mount        loaded    inactive dead    Mount /home/miguel/Musica                   
  home-miguel-Pictures.mount    loaded    inactive dead    Mount /home/miguel/Pictures                 
  home-miguel-ProgramasRFB.mount loaded    inactive dead    Mount /home/miguel/ProgramasRFB             
  home-miguel-src-UPSData.mount  loaded    inactive dead    Mount /home/miguel/src/UPSData             
  home-miguel-tmp.mount          loaded    inactive dead    Mount /home/miguel/tmp                     
  home-miguel-Videos.mount      loaded    inactive dead    Mount /home/miguel/Videos                   
  home.mount                    loaded    active  mounted /home                                       
  opt.mount                      loaded    active  mounted /opt                                       
  proc-sys-fs-binfmt_misc.mount  loaded    inactive dead    Arbitrary Executable File Formats File System
  root.mount                    loaded    active  mounted /root                                       
  run-user-1000-gvfs.mount      loaded    active  mounted /run/user/1000/gvfs                         
  run-user-1000.mount            loaded    active  mounted /run/user/1000                             
  srv.mount                      loaded    active  mounted /srv                                       
  sys-fs-fuse-connections.mount  loaded    active  mounted FUSE Control File System                   
  sys-kernel-config.mount        loaded    inactive dead    Kernel Configuration File System           
  sys-kernel-debug.mount        loaded    active  mounted Kernel Debug File System                   
  sys-kernel-tracing.mount      loaded    active  mounted Kernel Trace File System                   
● sysroot.mount                  not-found inactive dead    sysroot.mount                               
  tmp.mount                      loaded    active  mounted /tmp                                       
  usr-local.mount                loaded    active  mounted /usr/local                                 
● usr-share.mount                not-found inactive dead    usr-share.mount                             
● usr.mount                      not-found inactive dead    usr.mount                                   
● var-cache.mount                not-found inactive dead    var-cache.mount                             
  var-lib-transmission.mount    loaded    inactive dead    Mount /var/lib/transmission                 
  var-lock.mount                loaded    inactive dead    Lock Directory                             
  var-run.mount                  loaded    inactive dead    Runtime Directory                           
  var.mount                      loaded    active  mounted /var                                       

LOAD  = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

37 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

What I am doing wrong ?
Why I can not get theses extra filesystems get mounted at boot time 100% of time ?

I appreciate any comments,

cheeers,

Keith Hedger 06-25-2020 02:45 PM

Why not put the mount commands in your bashrc file ( or whatever startup files u are using ) so that the disks are mounted as soon as you login

rnturn 06-26-2020 12:18 AM

Quote:

Originally Posted by marozsas (Post 6137918)
Why I can not get theses extra filesystems get mounted at boot time 100% of time ?

Probably not helpful for your problem... I have a system running Leap (using nothing but ext4) and another running Tumbleweed (ext4 on md for "/", btrfs for everything else) and neither have had any problems mounting everything that's listed in /etc/fstab. Everything using ext4 is mounted by label. Everything btrfs is mounted by device name. Both up-to-date as of last weekend but both systems have mounted everything flawlessly since installation.

Note: None of my btrfs subvolumes use that "@" notation in /etc/fstab. Your's all do. I'm wondering if that's an important difference. I'm not suggesting you change that; just noting that it's different. (I've yet to find anything in the manpages that discusses its significance; only a couple of web pages that claim it's "part of the mount point name" without actually explaining how or why.)

Cheers...

marozsas 06-26-2020 06:21 AM

Quote:

Originally Posted by Keith Hedger (Post 6137923)
Why not put the mount commands in your bashrc file ( or whatever startup files u are using ) so that the disks are mounted as soon as you login

This is not a fix, it is a workaround.
I do not want a workaround, I want to understand why the things are not working as it was supposed to work, and them, fix it.

marozsas 06-26-2020 06:23 AM

Quote:

Originally Posted by rnturn (Post 6138044)
Probably not helpful for your problem... I have a system running Leap (using nothing but ext4) and another running Tumbleweed (ext4 on md for "/", btrfs for everything else) and neither have had any problems mounting everything that's listed in /etc/fstab. Everything using ext4 is mounted by label. Everything btrfs is mounted by device name. Both up-to-date as of last weekend but both systems have mounted everything flawlessly since installation.

Note: None of my btrfs subvolumes use that "@" notation in /etc/fstab. Your's all do. I'm wondering if that's an important difference. I'm not suggesting you change that; just noting that it's different. (I've yet to find anything in the manpages that discusses its significance; only a couple of web pages that claim it's "part of the mount point name" without actually explaining how or why.)

Cheers...

As I mentioned at my post, my first approach was listing the FS in fstab, but, due to hierarchical dependencies, it not worked either.

post edit: and about the '@' that is from the installer. I left to the installer create the default disk setup; Looks like is some SuSE convention, and as far I could understand it is just a ordinary character, with no special meaning to btrf, but it was created 'as it' by the tumbleweed installer.

dc.901 06-26-2020 06:31 AM

There are "Before" and "After" unit directives, that may work:
https://fedoramagazine.org/systemd-u...ies-and-order/

Full disclosure, I never tried this to mount filesystems - only to start service which was on different FS.

Guttorm 06-26-2020 06:46 AM

Hi

Systemd will mount with forking - kind of like "mount -a -F" vs. "mount -a".

But you can set up dependencies in fstab - adding x-systemd.requires-mounts-for= for each mount point that depends on another mount point. Here is some info:

https://www.golinuxcloud.com/mount-f...order-systemd/

rnturn 06-26-2020 09:32 AM

Quote:

Originally Posted by marozsas (Post 6138135)
As I mentioned at my post, my first approach was listing the FS in fstab, but, due to hierarchical dependencies, it not worked either.

That could be part of the problem you're seeing. My all-ext4 system has filesystems mounted on filesystems (sort of grew organically; I likely wouldn't do it that way again) but mounts haven't been an issue.

The system using btrfs is simpler but looks a lot like what you have. The major difference I see is your subvolume naming:
Code:

#
#  Local data
#
/dev/sdb        /localdata                btrfs        defaults                0 0
/dev/sdb        /home                        btrfs        subvol=home                0 0
/dev/sdb        /usr/local                btrfs        subvol=local                0 0
/dev/sdb        /opt/app/src                btrfs        subvol=src                0 0
/dev/sdb        /data/music                btrfs        subvol=music,noatime        0 0

I kept subvolume names simple (short, no special characters, less typing).

Quote:

post edit: and about the '@' that is from the installer. I left to the installer create the default disk setup; Looks like is some SuSE convention, and as far I could understand it is just a ordinary character, with no special meaning to btrf, but it was created 'as it' by the tumbleweed installer.
Yes. That's the explanation I've seen---that it was an installer default/convention. Special characters like that make me closely read the manpages looking for some special meaning. I added the btrfs storage after the initial install so did everything by hand. None of the documentation I read mentioned "@" characters. The last time I saw "@" used in fstab was for NFS mounts ("/exported-fs@somenfshost" ... long time ago)

marozsas 06-26-2020 10:19 AM

Quote:

Originally Posted by dc.901 (Post 6138136)
There are "Before" and "After" unit directives, that may work:
https://fedoramagazine.org/systemd-u...ies-and-order/

Full disclosure, I never tried this to mount filesystems - only to start service which was on different FS.

Yes, I am already tried "After=home.mount", no effect.

MadeInGermany 06-26-2020 03:18 PM

Traditionally fstab mounts are done in sequence, top-down.
If systemd doesn't do that then there is a compatibility bug in systemd.

syg00 06-26-2020 06:13 PM

All my testing indicates systemd handles the ordering just fine. I was mis-attributed above - my feeling as expressed in the referenced thread is that it's a mechanical issue with the spinning disk

ondoho 06-27-2020 04:26 AM

^ you mean one would need to add a delay to give the mounted disk time to actually become accessible?

syg00 06-27-2020 06:08 AM

Indeed as per the other thread, and also by @Guttorm above.

pan64 06-27-2020 07:20 AM

Quote:

Originally Posted by ondoho (Post 6138502)
^ you mean one would need to add a delay to give the mounted disk time to actually become accessible?

looks strange for me, mount itself should check the filesystem itself somehow (existence, type, dirty flag). Inaccessible filesystem cannot be mounted.

marozsas 06-27-2020 10:09 AM

Quote:

Originally Posted by syg00 (Post 6138340)
All my testing indicates systemd handles the ordering just fine. I was mis-attributed above - my feeling as expressed in the referenced thread is that it's a mechanical issue with the spinning disk

Hi, yes, you're right. Sorry.

About your specific comment, I think that it was the case, than I will not have the problem, because the fast home fs will be mounted first and the slow disk is mounted after a while, after the home is already ready to receive the sub-mounts, isn't ?

PS: Do you have hierarchical mounts, like me ? /home on a disk and /home/your-user/whatever in another disk ?


All times are GMT -5. The time now is 11:41 AM.