Automount USB drives with udev rules using disk label
October 18, 2015 11:11PM
The following are my udev rules for automounting (hotplug) USB drives with the disk partition label. If you know what udev rules are and wish to use udev to automount USB drives, then this is for you. If you are not sure about udev rules, then I'd suggest looking into usbmount, autofs, ... to install one of these Debian packages to handle the automounting.

1. udev rules

The udev rules below will mount all USB drives, uncluding mounting USB drives format with HFSplus file system in Read/Write mode.

Please be aware that HFSplus fie system driver is experimental and unsupported by mainline Linux (there is risk of data corruption by potential unknown bugs). If you don't use HFSplus file system then it is OK to use this rules file as is. To remove HFSplus Write capability, comment out the 3 rules lines in blue (it will mount Read-Only as usual).

Create the automount rules file (or edit your current rules) /etc/udev/rules.d/70-automount.rules. Copy and paste the following rules below.

# NOTE: 
#       1. use pmount --sync if drive label ends with Sync/SYNC/sync in add action to allow removal without corruption
#       2. avoid mounting EFI partition for a HFS+ drive
#       3. force mount HFS+ partition as read-write
#       4. mount USB hardrive (which is identified as SSCI)

KERNEL!="sd*", GOTO="media_label_end"
ENV{ID_TYPE}!="disk", GOTO="media_label_end"

IMPORT{program}="/sbin/blkid -o udev -p %N", ENV{name}="%E{ID_FS_LABEL}"
ENV{ID_FS_TYPE}=="", GOTO="media_label_end"

ENV{ID_FS_LABEL}!="EFI", GOTO="continue"
ENV{ID_PART_TABLE_TYPE}=="gpt", GOTO="media_label_end"

LABEL="continue"

ENV{name}=="", ENV{name}="%k"

KERNEL=="sd*", SYMLINK+="usb-storage/%E{name}"

ENV{name}=="*SYNC", ENV{mode}="--sync"
ENV{name}=="*Sync", ENV{mode}="--sync"
ENV{name}=="*sync", ENV{mode}="--sync"
ENV{name}!="*SYNC", ENV{mode}=""

ENV{ID_FS_TYPE}=="hfsplus", ENV{mode2}="--read-write"
ENV{ID_FS_TYPE}=="hfsplus", ENV{mode3}="/bin/mount -v -o remount,force,rw /media/%E{name}"
ENV{ID_FS_TYPE}!="hfsplus", ENV{mode3}="/usr/bin/pmount"

ACTION=="add", RUN+="/usr/bin/pmount -t %E{ID_FS_TYPE} %E{mode} %E{mode2} --noatime --umask 000 %k %E{name}"
ACTION=="add", RUN+="%E{mode3}"
ACTION=="remove", RUN+="/usr/bin/pumount --yes-I-really-want-lazy-unmount %E{name}"

LABEL="media_label_end"


2. (DEPRECATED) Aumounting USB drives during system startup

bodhi's Update: this is not need anymore with my latest released kernels and rootfs. Keeping here for posterity.

A long time ago, we've found that udevs rules for automounting USB drives were not enough

During system startup, the rules were not triggered, so the USB drives were not aumounted (except for the rootfs, which is always mounted by the kernel). Perhaps with recent udev versions there might be a better way than using a script.

The script below is to help automounting all USB drives that were not mounted by udev rules during system startup. This script should be executed in /etc/rc.local (preferably at the beginning).

usb-storage.pmount
#!/bin/bash
 
logger -s -i "Pmounting all unmounted USB drives"

PMOUNT=`which pmount`
if [ -z "$PMOUNT" ]
then
  logger -s -i  "Error: $0 cant find pmount!" 1>&2
 exit 1
fi

ROOT="/dev/usb-storage"
DEV_LIST=`ls -1 $ROOT`

logger -s -i "Mounting all unmounted USB disks: $DEV_LIST (skip rootfs)"

for DEV in $DEV_LIST; do
   
   if [ "$DEV" != "rootfs" ]; then
   
      if  ! /bin/mountpoint /media/$DEV -q ; then
         $PMOUNT --noatime --umask 000 --read-write $ROOT/$DEV $DEV
         
      fi
   fi

done

logger -s -i "Done Pmounting USB drives"

exit 0

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 7 time(s). Last edit at 03/08/2020 08:51PM by bodhi.
Re: Automount USB drives with udev rules using disk label
October 28, 2015 06:03AM
Bodhi,
I noticed that one of the added capabilities of the 4.0.0 kernel for the Oxnas OX820 devises shows "1. Automount (AUTOFS), pNFS, XFS". Does this kernel automatically locate and associate the rootfs, rendering this rule unnecessary for kernal 4.0.0 and above? Or am I just not quite understanding the Automount capability of 4.0.0?
Re: Automount USB drives with udev rules using disk label
October 28, 2015 12:16PM
cbalde04,

Autofs is a convenient utility to automount NFS, USB, HDD, ... file systems, where you will set it up to automount certain file systems that you want. udev rules is a lower level kind of device handling. If you dont want to deal with udev, then use autofs.

Or you can also use both. For example, if you use these rules here, then don't use autofs to automount USB drives.

For automount NFS, autofs is pretty convenient. I use it so that the shares are mounted when I start typing the names at the command line. And they time out and disappear after a period of time.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Bodhi,
It seems the latest 4.1 kernel breaks the udev rules. Would you please confirm? It works great for 3.17 kernel. After upgraded to 4.1 kernel automount script with udev no longer work.
I forgot to mention I am using Pogo Pro with Debian.
Re: Automount USB drives with udev rules using disk label
December 19, 2015 03:05PM
Thang,

Upgrade should not break any of the custom rules that you have in the system. With the exception that sometime the new version could change the rules, e.g. persistent network rules are usually affected by kernel and package upgrade.

Is /etc/udev/rules.d/70-automount.rules still there, the content is the same? is there any other automount rules file that were created in this directory after the upgrade ?

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
The 70-automount.rules still remain the same. I have tried to recopy and paste it. 70-persistent-net.rules is the auto generated one after each reboot. A total of two files.

This is the content of the 70-persistent-net.rules:
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# Unknown net device (/devices/platform/40400000.ethernet/net/eth0) (stmmaceth)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:31:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x1814:/sys/devices/platform/47c00000.pcie-controller/pci0000:00/0000:00:00.0 (rt2800pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="48:5d:60:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

I ran udevadm monitor and see that the trigger command is working but it just won't mount. I am mounting FAT32 at the moment. FAT32 did not work with kernel 3.17. I think someone forgot to include the module. It didnot even mount manually. I can manually mount with 4.1 but not working with udev and udev script.

lsblk -o name,size,type,fstype,label,mountpoint
NAME SIZE TYPE FSTYPE LABEL MOUNTPOINT
sda 1.9G disk
`-sda1 1.9G part vfat USBFAT32
sdb 14.5G disk
`-sdb1 14.5G part ext3 rootfs /
mtdblock0 14M disk
mtdblock1 114M disk
Re: Automount USB drives with udev rules using disk label
December 19, 2015 03:39PM
Ah, I remember discussing a similar problem here with another forum member, and it might be it. We'll need to mount the USB drives using label in rc.local in some case. It's been a long time so I can't remember the details. The solution was to create a shell script and mount all USB drives with label when the system is running rc.local.

But first, slightly off topic, your persistent network rules should be commented out (everything). This is to avoid future problem in using the rootfs on anther box.

# Unknown net device (/devices/platform/40400000.ethernet/net/eth0) (stmmaceth) 
###SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:31:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" 

# PCI device 0x1814:/sys/devices/platform/47c00000.pcie-controller/pci0000:00/0000:00:00.0 (rt2800pci) 
###SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="48:5d:60:xx:xx:xx", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Bodhi,
This is the thread you are referring to?
http://forum.doozan.com/read.php?2,6410,6417#msg-6417
It is quite old. Not sure if it is still valid.

The persistent network rule regenerate after each reboot even when I comment it out. I will make note to delete this file when backing up rootfs.
Nope, that is not the thread. I applied the script and no boot. :-P Good thing for usb rootfs!!!
Re: Automount USB drives with udev rules using disk label
December 19, 2015 05:29PM
I've updated the 1st post to provide the script for automounting USB.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Bodhi,
The new code work perfectly. Thank you so much!!! At one point, I decided to go back to 3.17 and reload everything from the 3.17 rootfs. I couldn't not get udev working again as work prior to kernel upgrade. I consider the issue is an intermittent. I am very appreciate your continuing support for the community!
Re: Automount USB drives with udev rules using disk label
June 05, 2016 01:32PM
I placed the first script where it should be. The results:
I logged into xfce but did not find any mounted media.
I clicked on "media" and "mnt;" nothing.

I placed the second script where it should be by simply coping and pasting the entire thing. The results:
The pogo started but without LED.
I removed it and the Pogo starts with LED.

Issuing "mount" gives:
root@debian:/media# mount  /media
mount: can't find /media in /etc/fstab

After removing the second script, and issued mount, I get:

root@debian:/media# 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,relatime,size=10240k,nr_inodes=30447,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=25092k,mode=755)
/dev/sda1 on / type ext2 (rw,noatime,errors=remount-ro,user_xattr,acl)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=50160k)
tmpfs on /tmp type tmpfs (rw,relatime)
rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw,relatime)

But even by this time, the drive, sda1 was not mounted in the file manager, even after issuing this:

root@debian:/media# mount /dev/sda1
mount: /dev/sda1 is already mounted or / busy
       /dev/sda1 is already mounted on /

All this was done using a USB stick, formatted in ext4 and plugged into the front usb port of the pogo.

I'm hoping to simply be able to plug in drives and have them automount and ready to serve files.

Thanks, as always, for your kind help.
Re: Automount USB drives with udev rules using disk label
June 05, 2016 04:09PM
notoneofmyseeds,

Note that I said in the other thread that there are many ways to set up USB automounting in Linux.

The hardest way to set up is using udev rules (sometime you want to control the automounting at a lower level). That's why I posted the instruction here. However, the easier way to set up is using usbmount or autofs.

Quote

~# apt-cache show usbmount
Package: usbmount
Version: 0.0.22
Installed-Size: 116
Maintainer: Rogério Brito <rbrito@ime.usp.br>
Architecture: all
Depends: lockfile-progs, udev, util-linux (>> 2.16)
Recommends: pmount
Description-en: automatically mount and unmount USB mass storage devices
This package automatically mounts USB mass storage devices (typically
USB pens) when they are plugged in, and unmounts them when they are
removed. The mountpoints (/media/usb[0-7] by default), filesystem types
to consider, and mount options are configurable. When multiple devices
are plugged in, the first available mountpoint is automatically
selected. If the device provides a model name, a symbolic link
/var/run/usbmount/MODELNAME pointing to the mountpoint is automatically
created.
.
The script that does the mounting is called by the udev daemon.
Therefore, USBmount requires a 2.6 (or newer) Linux kernel.
.
Firewire devices are also supported by USBmount.
.
USBmount is intended as a lightweight solution which is independent of
a desktop environment. Users which would like an icon to appear when an
USB device is plugged in should use the pmount and hal packages
instead.
Description-md5: 665bf065788bff1ada4b796e26321438
Homepage: http://usbmount.alioth.debian.org/
Tag: admin::filesystem, hardware::storage, hardware::usb, interface::daemon,
role::program, scope::utility, use::configuring
Section: admin
Priority: extra
Filename: pool/main/u/usbmount/usbmount_0.0.22_all.deb
Size: 17666
MD5sum: 1d62c98011ac6452d1e9b3be7b56b272
SHA1: 9a4d4d88ac7f609a27db15235bed605f3f6dadc1
SHA256: 764462e65a544fc6a03ca4f90157898a4f289c3f3bea866c5b739ff9184d6c93

Package: usbmount
Status: deinstall ok config-files
Priority: extra
Section: admin
Installed-Size: 112
Maintainer: Rogério Brito <rbrito@ime.usp.br>
Architecture: all
Version: 0.0.21
Config-Version: 0.0.21
Depends: udev, lockfile-progs, util-linux (>> 2.16)
Recommends: pmount
Conffiles:
/etc/usbmount/umount.d/00_remove_model_symlink 06304855418cfe29f6cec46042bdd857
/etc/usbmount/mount.d/00_create_model_symlink 13ef81167c202627ca43b1fe6c7cd0bf
/etc/usbmount/usbmount.conf a78d1be4f28c20bdb0b88b23cc01cf5d
Description-en: automatically mount and unmount USB mass storage devices
This package automatically mounts USB mass storage devices (typically
USB pens) when they are plugged in, and unmounts them when they are
removed. The mountpoints (/media/usb[0-7] by default), filesystem types
to consider, and mount options are configurable. When multiple devices
are plugged in, the first available mountpoint is automatically
selected. If the device provides a model name, a symbolic link
/var/run/usbmount/MODELNAME pointing to the mountpoint is automatically
created.
.
The script that does the mounting is called by the udev daemon.
Therefore, USBmount requires a 2.6 (or newer) Linux kernel.
.
Firewire devices are also supported by USBmount.
.
USBmount is intended as a lightweight solution which is independent of
a desktop environment. Users which would like an icon to appear when an
USB device is plugged in should use the pmount and hal packages
instead.
Description-md5: 665bf065788bff1ada4b796e26321438
Homepage: http://usbmount.alioth.debian.org/

To install
apt-get install usbmount

I'd recommend trying the ready made solution usbmount first. udev rules takes a lot of time to troubleshoot when it does not work like you expect.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 06/05/2016 05:38PM by bodhi.
Re: Automount USB drives with udev rules using disk label
June 08, 2016 04:46PM
bodhi Wrote:
-------------------------------------------------------
> notoneofmyseeds,
>
> Note that I said in the other thread that there
> are many ways to set up USB automounting in Linux.
>
>
> The hardest way to set up is using udev rules
> (sometime you want to control the automounting at
> a lower level). That's why I posted the
> instruction here. However, the easier way to set
> up is using usbmount or autofs.
>
>
Quote

> ~# apt-cache show usbmount
> Package: usbmount
> Version: 0.0.22
> Installed-Size: 116
> Maintainer: Rogério Brito <rbrito@ime.usp.br>
> Architecture: all
> Depends: lockfile-progs, udev, util-linux (>>
> 2.16)
> Recommends: pmount
> Description-en: automatically mount and unmount
> USB mass storage devices
> This package automatically mounts USB mass
> storage devices (typically
> USB pens) when they are plugged in, and unmounts
> them when they are
> removed. The mountpoints (/media/usb[0-7] by
> default), filesystem types
> to consider, and mount options are configurable.
> When multiple devices
> are plugged in, the first available mountpoint is
> automatically
> selected. If the device provides a model name, a
> symbolic link
> /var/run/usbmount/MODELNAME pointing to the
> mountpoint is automatically
> created.
> .
> The script that does the mounting is called by
> the udev daemon.
> Therefore, USBmount requires a 2.6 (or newer)
> Linux kernel.
> .
> Firewire devices are also supported by USBmount.
> .
> USBmount is intended as a lightweight solution
> which is independent of
> a desktop environment. Users which would like an
> icon to appear when an
> USB device is plugged in should use the pmount
> and hal packages
> instead.
> Description-md5: 665bf065788bff1ada4b796e26321438
> Homepage: http://usbmount.alioth.debian.org/
> Tag: admin::filesystem, hardware::storage,
> hardware::usb, interface::daemon,
> role::program, scope::utility, use::configuring
> Section: admin
> Priority: extra
> Filename:
> pool/main/u/usbmount/usbmount_0.0.22_all.deb
> Size: 17666
> MD5sum: 1d62c98011ac6452d1e9b3be7b56b272
> SHA1: 9a4d4d88ac7f609a27db15235bed605f3f6dadc1
> SHA256:
> 764462e65a544fc6a03ca4f90157898a4f289c3f3bea866c5b
> 739ff9184d6c93
>
> Package: usbmount
> Status: deinstall ok config-files
> Priority: extra
> Section: admin
> Installed-Size: 112
> Maintainer: Rogério Brito <rbrito@ime.usp.br>
> Architecture: all
> Version: 0.0.21
> Config-Version: 0.0.21
> Depends: udev, lockfile-progs, util-linux (>>
> 2.16)
> Recommends: pmount
> Conffiles:
> /etc/usbmount/umount.d/00_remove_model_symlink
> 06304855418cfe29f6cec46042bdd857
> /etc/usbmount/mount.d/00_create_model_symlink
> 13ef81167c202627ca43b1fe6c7cd0bf
> /etc/usbmount/usbmount.conf
> a78d1be4f28c20bdb0b88b23cc01cf5d
> Description-en: automatically mount and unmount
> USB mass storage devices
> This package automatically mounts USB mass
> storage devices (typically
> USB pens) when they are plugged in, and unmounts
> them when they are
> removed. The mountpoints (/media/usb[0-7] by
> default), filesystem types
> to consider, and mount options are configurable.
> When multiple devices
> are plugged in, the first available mountpoint is
> automatically
> selected. If the device provides a model name, a
> symbolic link
> /var/run/usbmount/MODELNAME pointing to the
> mountpoint is automatically
> created.
> .
> The script that does the mounting is called by
> the udev daemon.
> Therefore, USBmount requires a 2.6 (or newer)
> Linux kernel.
> .
> Firewire devices are also supported by USBmount.
> .
> USBmount is intended as a lightweight solution
> which is independent of
> a desktop environment. Users which would like an
> icon to appear when an
> USB device is plugged in should use the pmount
> and hal packages
> instead.
> Description-md5: 665bf065788bff1ada4b796e26321438
> Homepage:
> http://usbmount.alioth.debian.org/
>
> To install
>
> apt-get install usbmount
>
>
> I'd recommend trying the ready made solution
> usbmount first. udev rules takes a lot of time to
> troubleshoot when it does not work like you
> expect.

Thanks a lot bohdi, that solved the problem after a restart and walking away from the project some few days.
Now a ext4 formatted USB auto, yes, automounted. I cd to it, made a directory, checked and it's all good.
I came to desktop installed, xfce, via Remmina, and did the same. All was good. It's mounted to USB0. That's fine.
I hope once I move to setting up drives permanently, no problems.
And so thanks a lot. The automounting issue is gone, for now.
Now I move to configuration. Samba is not behaving. But I will now post on the relevant thread.
Re: Automount USB drives with udev rules using disk label
August 31, 2017 10:45PM
bodhi Wrote:
-------------------------------------------------------
> The following udev rules are for automounting (hot
> plug) USB drives with the disk partition label. If
> you know what udev rules are and wish to use udev
> to automount USB drives, then this is for you. [co
> lor=#3333FF]If you are not sure about udev rules,
> then I'd suggest looking into usbmount,
> autofs
,[/color] ... to install one of these De
> bian packages to handle the automounting.

I found an alternative approach that uses shell scripts triggered from minimal udev rules. For someone who doesn't know much about udev, isn't this more manageable?

You can quickly find all the scripts mentioned in the above post here.


bodhi Wrote:
-------------------------------------------------------
> A long time ago, we've found that udevs rules for automounting USB drives were
> not enough. During system startup, the rules were not triggered, so the USB
> drives were not aumounted (except for the rootfs, which is always mounted by the
> kernel). Perhaps with recent udev versions there might be a better way than
> using a script.

Do you think this is still an issue?
Re: Automount USB drives with udev rules using disk label
September 01, 2017 12:01AM
haridsv ,

I actually discouraged people from using udev rules. It just that it has the least footprint on a system, so it might be useful to somebody. I think most people should use Debian packages.

Quote

If you are not sure about udev rules, then I'd suggest looking into usbmount, autofs, ... to install one of these Debian packages to handle the automounting.

> During system startup, the rules wer
> e not triggered, so the USB
> > drives were not aumounted (except for the rootfs
> , which is always mounted by the
> > kernel). Perhaps with recent udev versions there
> might be a better way than
> > using a script.
>
> Do you think this is still an issue?

I don't believe it is still an issue anymore in the latest kernel linux-4.12.8-kirkwood-tld-1. You could try the udev rules without the usb-storage.pmount script and let me know!

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 09/01/2017 12:03AM by bodhi.
Re: Automount USB drives with udev rules using disk label
September 01, 2017 12:08AM
bodhi Wrote:
-------------------------------------------------------
> I actually discouraged people from using udev rule
> s. It just that it has the least footprint on a sy
> stem, so it might be useful to somebody.

Got it! I experimented with the scripts and it worked, except that I had to remove locale option or I was getting this error:

[137246.680981] ntfs: driver 2.1.32 [Flags: R/W MODULE].
[137246.687304] ntfs: (device sdb1): parse_options(): Unrecognized mount option locale

bodhi Wrote:
-------------------------------------------------------
> I don't believe it is still an issue anymore in th
> e latest kernel linux-4.12.8-kirkwood-tld-1. You c
> ould try the udev rules without the usb-storage.pm
> ount script and let me know!

I haven't rebooted yet, but I will check and report.
Re: Automount USB drives with udev rules using disk label
October 29, 2018 02:33PM
bodhi Wrote:
-------------------------------------------------------
> To install
>
> apt-get install usbmount
>


It seems, that usbmount is not longer supported and was removed from repository....

> E: Unable to locate package usbmount

https://wiki.debian.org/usbmount

> Note (made in 2013): currently the author of the package is unable to maintain it and no one else has taken it on yet.

On the other hand - the gitHub repository seems to be alive ...

https://github.com/rbrito/usbmount
Re: Automount USB drives with udev rules using disk label
October 29, 2018 04:09PM
Martin,

Debian autofs is a really good tool, which usually peope use it to automount NFS. It can also automount USB.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Martin from Dortmund
Re: Automount USB drives with udev rules using disk label
October 30, 2018 03:08AM
I am working through the HowTos concerning the syntax of the autofs configuration files ...

My first approach was, to mount the 4TB USB HDD actually residing at my Linux PC using fstab entries.

But I have "gparted" the HDD to three partitions, one ext2 of 1 TB as replacement of an elder 1 TB USB HDD, and two ext4 partitions witch 1.5 TB each using my Linux Mint PC.

Unfortunately it seems, that mounting takes place prior to opening the SSH port of the dockstar, so a fsck run during mount process keeps the dockstar inacccesible after power on for a while...

The fsck is only visible on the serial console of the dockstar. Log in is not possible via serial console until fsck has finished ...
The two 1.5 TB ext4 partitions are not mounted ...
Re: Automount USB drives with udev rules using disk label
November 01, 2018 02:39AM
Martin,

> My first approach was, to mount the 4TB USB HDD
> actually residing at my Linux PC using fstab
> entries.
>
>
> Unfortunately it seems, that mounting takes place
> prior to opening the SSH port of the dockstar, so
> a fsck run during mount process keeps the dockstar
> inacccesible after power on for a while...

If you mount the partition accross the network using fstab, you need to use ASYNC option so that it does not stop at that point.

Mounting NFS rootfs must be done a differrent way (at kernel boot).

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Automount USB drives with udev rules using disk label
November 01, 2018 05:07AM
bodhi Wrote:
-------------------------------------------------------
>
> If you mount the partition accross the network
> using fstab, you need to use ASYNC option so that
> it does not stop at that point.
>

The 4 Terabyte USB HDD is intended to be attached via USB to the dockstar permanenty. As long as I am on the way to create an environment on the dockstar to do so, I have attached it to my Linux Mint PC temporarily, and made it accessible in my home network on this way via SMB.

But my target is to remove it from the Linux PC to avoid the power consumption running the PC 24/7....

Formatting and partitioning has taken place on the Linux PC, that has given long UUIDs to each partition as Label.

There are some flaws, on the way to move it.

1) I have once moved the drive from PC to dockstar, and the dockstar triggers a fsck of the first partition. After success on fsck I moved the drive to PC .... and the PC triggers a fsck (with some orphan inodes as result)

2) As the 3,5 " drive was a spontaneous buy (It was a special offer in a shopping mall) I have not checked all characteristics before buying it.... Now I encountered, that the HDD housing has an push-button, that must be pushed (after inserting the wall power supply) to switch the drive on - the insertion alone does not power up. Not very helpful for unattended dockstar power up after an areal power break down...

3) First partition is a dd-ed one duplicating a 1 TB USB hdd (perhaps that's the reason that it is a ext2 file system). The other ones are ext4, and were not mounted... (perhaps due to ownership problems?)

Perhaps it is not necessary to automount the partitions of the drive ... fstab entries might be sufficient - if there is a way to avoid the stopping of the boot process of the dockstar - since the hdd remains turned off until operating the push-button after a temporary power loss ...



Edited 3 time(s). Last edit at 11/01/2018 05:19AM by Martin aus Dortmund.
Re: Automount USB drives with udev rules using disk label
November 01, 2018 06:04AM
Got success with following fstab options


LABEL=rootfs    /               ext4    noatime,errors=remount-ro 0 1
tmpfs          /tmp            tmpfs   defaults          0       0
UUID=04aae5de-6bed-4faa-999c-68ba85b591a4  /mnt/data  ext2  rw,suid,dev,exec,nouser,async,auto  0  2
UUID=44d90f04-3a0e-4fac-8993-853b3d60afd3  /mnt/unterhaltung  ext4  rw,suid,dev,exec,nouser,async,auto  0  2
UUID=e7f3cfb0-6abf-4591-9d18-2ae7bc92be2e  /mnt/backup  ext4  rw,suid,dev,exec,nouser,async,auto,  0  2


... but the problem remains, trouble, if USB hdd is not found at startup...
Re: Automount USB drives with udev rules using disk label
November 01, 2018 06:06AM
Martin,

> But my target is to remove it from the Linux PC to
> avoid the power consumption running the PC
> 24/7....

I see.

> Perhaps it is not necessary to automount the
> partitions of the drive ... fstab entries might be
> sufficient - if there is a way to avoid the
> stopping of the boot process of the dockstar -
> since the hdd remains turned off until operating
> the push-button after a temporary power loss ...

As long as the rootf is on a different partition. You could :

1. Have only rootfs partition in fstab, and then do the fsck explicitly for other partitions much later in /etc/rc.local. And mount them there.
or
2. Have all partitions in fstab, but tell it to ignore the error for non-rootfs partition so it won't try to check them, and do the fsck explicitly much later in /etc/rc.local.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Automount USB drives with udev rules using disk label
November 01, 2018 06:07AM
And regarding

Quote

... but the problem remains, trouble, if USB hdd is not found at startup...

Where is the rootfs? is it on another drive?

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: Automount USB drives with udev rules using disk label
November 01, 2018 06:22AM
dockstar boot from usb stick.

I think, I will go forward using some hand-weaved script, mounting the USB-drive partition individually.
I have cleaned up the entries in fstab.


Powering the dockstar, waiting for login prompt, log in as root and then powering the USB hdd, afterwards

root@debian:~# mount UUID=04aae5de-6bed-4faa-999c-68ba85b591a4  /mnt/data
root@debian:~# mount UUID=44d90f04-3a0e-4fac-8993-853b3d60afd3  /mnt/unterhaltung
root@debian:~# mount UUID=e7f3cfb0-6abf-4591-9d18-2ae7bc92be2e  /mnt/backup

works well ...


I think some shell script magic will be sufficient.

EDIT:
Here my first approach for a medium secure mount combined with fsck before

#!/bin/sh
# secure mounting with file system check of mounted partitions

fsck UUID=04aae5de-6bed-4faa-999c-68ba85b591a4
if [ $? -eq 0 ]
then
  mount UUID=04aae5de-6bed-4faa-999c-68ba85b591a4 /mnt/data
else
  echo file system check failed, 'mnt/data' not mounted
fi
fsck UUID=44d90f04-3a0e-4fac-8993-853b3d60afd3
if [ $? -eq 0 ]
then
  mount UUID=44d90f04-3a0e-4fac-8993-853b3d60afd3 /mnt/unterhaltung
else
  echo file system check failed, 'mnt/unterhaltung' not mounted
fi
fsck UUID=e7f3cfb0-6abf-4591-9d18-2ae7bc92be2e
if [ $? -eq 0 ]
then
  mount UUID=e7f3cfb0-6abf-4591-9d18-2ae7bc92be2e /mnt/backup
else
  echo file system check failed, 'mnt/backup' not mounted
fi

Fast mount script will omit fsck, perhaps I will write a script for using "fsck -f"



Edited 2 time(s). Last edit at 11/01/2018 07:20AM by Martin aus Dortmund.
Re: Automount USB drives with udev rules using disk label
November 01, 2018 04:43PM
Martin,

Glad you've got a working system as expected! My suggestion is to use partition label for these. It is much more friendly and flexible. UUID is not bad, but it will limit the usage in some use cases.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: