You are not logged in.

#1 2015-03-06 01:03:55

kaivai
Member
Registered: 2013-05-17
Posts: 21

Bind Mount If Not CIFS Mount (or if not on current network)

Hey Guys!

I have been trying to set up conditional-bind mounts on my laptop. The vast majority of the time I spend on my laptop I'm at home,
and using cifs mounts in my fstab works perfectly. Recently though, I was thinking that I could (rsync)backup of a handful of files so that
I could access them from elsewhere (even when I'm offline).  Little things like todo lists, emulator savegames, this month's accounting spreadsheet etc.

So far, I (think) have been able to get the job to run, but I've been having problems with using bind. I'm not married to this particular method,
if anyone has any other ideas.

#### /etc/systemd/system/conditionalmounts.service
[Unit]
Description=Network Dependent Mounts
Wants=local-fs.target
After=local-fs.target
Wants=remote-fs.target
After=remote-fs.target
Wants=network.target
After=network.target
Wants=network-online.target
After=network-online.target


[Service]
Type=oneshot
ExecStart=/home/cron/conditionalmounts

[Install]
WantedBy=multi-user.target
####
#### /home/cron/conditionalmounts
#!/usr/bin/env bash

curNetwork=`iwconfig wlp3s0 | grep ESSID | awk -F'"' '{print $2}'`

## All unmounting
umount /home/will/.dolphin-emu/Wii/title

## Home Network Dependent Mounts
if [[ "$curNetwork" == "Holocron" ]] ; then
    mount -t ext4 -o bind /mnt/saves/wii                /home/will/.dolphin-emu/Wii/title            #mount wii savegames

## Outside of Home Network Mounts
else 
    mount -t ext4 -o bind /home/games/backupsaves/wii    /home/will/.dolphin-emu/Wii/title            #mount wii savegames
####

Here is the error that I can see after executing `systemctl status conditionalmounts.service`.

● conditionalmounts.service - Network Dependent Mounts
   Loaded: loaded (/etc/systemd/system/conditionalmounts.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2015-03-05 19:33:42 EST; 1min 7s ago
  Process: 601 ExecStart=/home/cron/conditionalmounts (code=exited, status=32)
 Main PID: 601 (code=exited, status=32)

Mar 05 19:33:42 miranda systemd[1]: Starting Network Dependent Mounts...
Mar 05 19:33:42 miranda conditionalmounts[601]: umount: /home/will/.dolphin-emu/Wii/title: not mounted
Mar 05 19:33:42 miranda conditionalmounts[601]: mount: unknown filesystem type 'none'
Mar 05 19:33:42 miranda systemd[1]: conditionalmounts.service: main process exited, code=exited, status=32/n/a
Mar 05 19:33:42 miranda systemd[1]: Failed to start Network Dependent Mounts.
Mar 05 19:33:42 miranda systemd[1]: Unit conditionalmounts.service entered failed state.
Mar 05 19:33:42 miranda systemd[1]: conditionalmounts.service failed.

Last edited by kaivai (2015-03-06 01:13:22)

Offline

#2 2015-03-06 01:22:08

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Bind Mount If Not CIFS Mount (or if not on current network)

Is "-t ext4" really needed? Do those commands work outside the script?

Offline

#3 2015-03-06 01:50:18

kaivai
Member
Registered: 2013-05-17
Posts: 21

Re: Bind Mount If Not CIFS Mount (or if not on current network)

oh! Sorry I forgot that was still in there.
I was trying a few different flags to see if I could get it to run on startup without this part of the error:

Mar 05 19:33:42 miranda conditionalmounts[601]: mount: unknown filesystem type 'none'

it works without it if I run it once the system is up and running, which makes me think
it's a dependency issue of some kind. I wanted to rule out arguments as much as possible though,
that's why the ext4 is in there.

Offline

Board footer

Powered by FluxBB