Automount share

The example used in this blog is a CIFS share from a Samba server running on a Raspberry Pi mounted on demand by a client running Debian.

Goal

The goal is to have a share on a client that is dynamically mounted. The share should only be mounted when an app needs to access.

In my case I do have a server with a data storage share connected. The storage is made available to clients in the network. To not have the share being mounted by the clients all the time, the share should be mounted only when real demand exists. For instance, an app needs to read data from the share. If the share is not needed by the client, it should not be mounted.

Process

To understand the scenario better, take a look at the picture below. The process can be separated into 4 steps.

  • Step 1: the client is configured, but the share is inactive.
  • Step 2: An app is accessing the share. This can be an app as simple as ls /mnt/share
  • Step 3: The client is connecting to the server and mounting the share to the local mount point /mnt/share. The data is now available to the app.
  • Step 4: The app is not using the data from the share any longer. After a timeout, the client disconnects the share.

The example is using for the server a Raspberry Pi with Raspbian and for the client a Debian based system (Proxmox). As share type, CIFS is used. On the client, Samba is running and configured to give access to a named user to the data storage.

Installation

Server

Install Samba and configure access for a named user. This is not part of this blog.

Client

Autofs is the package and tool taking of mounting shares automatically. Install it using apt-get.

apt-get update
apt-get install autofs

Configuration of autofs

Autofs needs to be configured. To make it easier, the packages comes with templates. I am going to use the autofs master template as my starting point. Take a look at the master template as it contains an explanation of what is needed.

cd /etc/auto.master
more /etc/auto.master

To add an auto mount share a new line must be added to the file. The format is: mount-point file options.

Before adding the line, you first must understand how the template and autofs works and what you want to achieve. First parameter is for the local mount point. The directory informed here is the parent. The actual shares mounted are created as sub-folders in that directory. For instance, if you choose /mnt/server and the remote share is data, the final mount point will be /mnt/server/data. I am going to mount the remote share to /mnt/server.

The seconds parameter is for the configuration file for that mount point. The third parameter specifies how autofs is treating the mount point. To unmount the share after 1 minute of inactivity, use option –timeout=60. The ghost option will create the subfolder even in case the server is not reachable.

Edit master template

Add a new configuration line for mounting the server share

/media/net /etc/autofs/auto.net --timeout=60 --ghost

Mount configuration

The actual mount configuration for the share is specified in the file /etc/auto.server. Create file /etc/auto.server and edit it.

touch /etc/auto.server
vim /etc/auto.server

Insert mount options.

  • [username] – name of user used to connect to Samba share
  • [password] – password of the user
  • [remote_server] – IP / server name of the Samba server
  • /data – name of the share configured at Samba. In case you have a share configured named Music, or Fotos, or Work, substitute data with the correct share name.
data -fstype=cifs,username=[username],password=[password] ://[remote_server]/data

Save file

Change permission

chmod 0644 auto.server

Start autofs as service

Stop autofs and start it in debug mode to see if the configuration works.

If it worked, exit and start the service.

systemctl start autofs.service

Test

To test, go through the 4 steps described in the picture at the top of this blog.

Step 1

Client is ready. Check the mounted volumes. You will see that no CIFS volume is available.

Using mount, you can see that the mount point is available.

/etc/auto.server on /mnt/server type autofs (rw,relatime,…

In the parent mount point for the CIFS share, autofs created the folder data.

Step 2 & 3

Run an app that is accessing the share

ls /mnt/share/data

Accessing now the content of /mnt/server/data will automatically mount the CIFS share.

df -h

Mount

//192.168.0.164/data on /mnt/server/data type cifs (rw,relatime

Step 4

Assure that no app is using the share and wait until the specified timeout occurs. Check with mount and df to see that the share is umounted.

Additional information

Start / stop autofs service

Start service

systemctl stop autofs.service

Stop service

systemctl stop autofs.service

Links

https://wiki.archlinux.org/index.php/autofs

 

Uncompressing a multi-part 7zip file in Debian

7zip is a popular compression program for Windows. It allows to effectively compress files, split them into several archives and to add protection by using a password. This all works fine if you are a Windows user. In case you now want to extract such a multi part password protected file in Linux, you’ll find out that this isn’t a standard use case. Uncompressing these files involves some work. 7zip is not made available for Linux by the developer. Gzip or zip won’t work with 7zip compressed files. But: an unofficial version is available and it is possible to extract 7zip files in Debian/Linux.

You have some options available for installing 7zip for Debian, like apt or by compilation. The version you get with apt is quite old: 9.2. In case the version of 7zip used to compress the file on Windows is higher than the one available for Debian, uncompressing may not work. An algorithm may be used that is not available on the lower version. In that case, 7zr will exit with an error and showing Unsupported Method.

Compilation from source

This option will give you the latest available version of 7zip for Linux. Especially useful when you try to unzip a file and get the message: Unsupported Method. To solve this, try to install a higher version of p7zip by downloading the source and compile p7zip.

Get the latest version of p7zip from SourceForge. Unzip it and then run make. After the compilation is done, you’ll have the executable 7za in the bin folder. This version should be able to work with files compressed by 7zip for Windows. Make sure to read the README.

Copy the correct makefile. 7zip provides several makefiles, for each target platform / architecture. In case of Linux, the default one should work. To start compilation, a simple make is sufficient.

make

This gives you the binary ./bin/7za

Unzip a file multi-part password protected file.

7za x h1.7z

APT

Install the 7zip program for Debian. This installs version 9.2.

sudo apt-get install p7zip

Let’s say we have 1 file that was zipped to file h1.7z using 7zip and splitter into 650 MB. 7zip produces 2 archives:

  • h1.7z.001
  • h1.7z.002

To list the archive:

7zr l h1.7z.001 -tsplit

We can see that the split archives contain one file named h1.7z. That is the zip file created by 7zip under Windows.

To unzip the file, use

7zr x h1.7z.001 -tsplit

RIP Subsonic, Hello Libresonic

Some while ago I posted a blog detailing how to install Subsonic on a Raspberry Pi 1. If you google for “subsonic raspberry pi” my blog shows up as a top search result (normally 3rd place, but even second is possible). In addition, each day I get more than one access from somewhere in the world to that blog. There is definitely interest in running Subsonic on a RP.

Subsonic now closed source

Since the last time some things have changed. I updated to a RP2 and Subsonic was updated up to 5.3. I won`t update to version 6 and beyond. The developer of Subsonic changed the license of 6.x and made it closed source. Not a big problem for you as an end user. You can still download and install Subsonic 6 as a binary without problems. The license change however makes it unclear what the future of Subsonic will be. Is it going to be premium only, forcing you to buy a license? Currently the premium features are of no interest to me. Although not having Ads in the UI would be nice. Either way, I do not want to change software (got used to it), and staying in 5.3 for the rest of my life isn`t an option too (yes, I DO update).

Moving to Libresonic

Good news: one person is offering his own fork of Subsonic since a while: Eugene E. Kashpureff Jr. Started originally to take away the license check feature of Subsonic, he started a new project based on Subsonic 5.3: Libresonic. Available on Github, the source code is freely available and continues to offer the functionality of Subsonic. Community already started to give feedback on this new software. The name is no surprise, considering LibreOffice, Libreelec and now Libresonic.

Installation

No surprises here. It`s the same procedure as with 5.x. Ensure you have the pre-requisites installed like maven, Java, Debian tools.

git clone https://github.com/Libresonic/libresonic.git
cd libresonic/
mvn package
mvn -P full -pl libresonic-booter -am install
mvn -P full -pl libresonic-installer-debian/ -am install
sudo dpkg -i ./libresonic-installer-debian/target/libresonic-*.deb

Configuration

The name of the project changed to Libresonic, and so did the location of the configuration files and executables. The conf file is now located at: /etc/default/libresonic. The name of the parameters changed too, while the values are the same. So copy over the values of the old Subsonic conf file.

LIBRESONIC_ARGS="--max-memory=150 --port=8080 --context-path=/libresonic"
LIBRESONIC_USER=libresonic

To start Libresonic, it`s now /etc/init.d/libresonic and the program files are at /var/libresonic. After you have done this, you can access Libresonic again via web interface.

Uninstall Subsonic

I upgraded to EugeneKay fork some time ago when it was still Subsonic without license check. Therefore, I installed it using dpkg. The package is still installed and it won`t work nicely together with Libresonic because of sharing the same configuration (port, etc.). To uninstall your officially downloaded Subsonic DEB file, just follow the same steps.

dpkg –l subsonic

To uninstall that package:

sudo dpkg –r subsonic

This removes the package, but leaves the config files (can be seen when running dpkg –l subsonic again):

To remove also the config files:

sudo dpkg –P subsonic

The directory /var/subsonic containing some files wasn`t removed, you`ll have to do this manually.