Hot swapping SATA devices (ThinkPad) / fstab questions

Hello everybody,

I want to solve the following problem: I have a ThinkPad W510 which has a SATA hot swap bay (Serial Ultrabay Enhanced). And yes I can swap stuff like a madman on windows at runtime, so it technically works.

I use this Bay for:

a. occasionally an optical drive (for ripping Audio CDs and the occasional Data CD)
b. my SSD with the Win10 Install that was my main until a few weeks ago
c. another SSD soley dedicated to Timeshift Snapshots (and other backup stuff)

My Manjaro Install is on a 1TB SSD in the hardwired slot of my machine.

If those devices are installed at boot time, they all get recognized fine and work the way they should. I also updated my fstab accordingly so that’s all good.

When the Bay is empty at boot and I plug in the hot swap casette while manjaro is running, it also get’s detected and mounted correctly. I also set the checkbox in the thunar-volman that media should be hot pluggable, it’s also enabled in BIOS (I don’t have a UEFI).

Only when I unplug a device and put another one in while manjaro is running, nothing new get’s recognized.

So my question is how do I put the system in a state like at boot time where it checks SATA devices and mounts them? I can’t find anything about a scenario like that, only for eSATA (which it isn’t).

Of course I could reboot when I want to swap a module but that’s lame and it wouldn’t be a hot swap anymore :frowning:

Also regarding the pass number in my fstab. I see everybody setting the number to 0 when mounting other drives. The fstab manual says it should be set to 2 though. I understand that I don’t want my external media HDD checked at boot, but at which point do I want a drive to be tested at startup?
Do I want to check my backup partition? Do I want to check the second patition on my 1TB SSD where I store only bulk data like music, ISOs and games? Does it take longer to boot if it tries to check for two partitions that might not be there? Or is it just a millisecond type of thing?
Since all those devices are swappable, wouldnt I WANT to check all of them and just add the “nofail” option in case they aren’t there? And what would be the worst case if a partition that isn’t checked should have been checked?

thanks for helping out, I appreciate it!

here is my fstab in case it helps:

#---------------------------------------------------------------------------------------------------------------------------------------#
# /etc/fstab: static file system information.                                                                                           #
#                                                                                                                                       #
# Use 'blkid' to print the universally unique identifier for a device; this may                                                         #
# be used with UUID= as a more robust way to name devices that works even if                                                            #
# disks are added and removed. See fstab(5).                                                                                            #
#                                                                                                                                       #
#---------------------------------------------------------------------------------------------------------------------------------------#
#       <file system>                                   <mount point>           <type>  <options>                       <dump>  <pass>  #
#---------------------------------------------------------------------------------------------------------------------------------------#

        UUID=eee373c9-515b-4422-860c-f60577e95841       /                       ext4    defaults,noatime                0       1
        UUID=c9dca860-472e-4d7e-8dd9-b14538d9a53f       swap                    swap    defaults,noatime                0       0
        tmpfs                                           /tmp                    tmpfs   defaults,noatime,mode=1777      0       0

        UUID=dd91319d-c731-4939-a3c8-c4b472c2a958       /media/Data             ext4    defaults,nofail                 0       2
        UUID=24b34b91-f83f-4239-af3d-211dd1104bee       /media/Backup           ext4    defaults,nofail                 0       2
        UUID=373ADDA6610597A5                           /media/Windows          ntfs    defaults,nofail                 0       0

        UUID=AFE5A3B58FCBD714                           /mnt/WinSysRes          ntfs    defaults,nofail,noauto          0       0

        UUID=BC2CF6852CF639CA                           /media/ExterneHN        ntfs    defaults,nofail                 0       0


#---------------------------------------------------------------------------------------------------------------------------------------#

https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices

the focus should be setting up a udev-rule in this manner:
https://www.thinkwiki.org/wiki/How_to_hotswap_Ultrabay_devices#Using_libata-acpi_and_udev

Hey Olli,

thanks for the quick help. Sadly the script is very broken.

  1. I have ahci installed
  2. The “CONFIG_ATA_ACPI” Flag is set to yes (=y)
  3. I added the .rules file in the correct directory and changed the permissions accordingly
  4. I added the ultrabay_eject script in the correct directory and changed the permissions accordingly
  5. I substituted the if-statement to find out the DEVPATH, with the fixed path I found out with the described command, so this:
# Try to guess DEVPATH. It works with optical drive or Hard disk (or SSD)
if [ "$DEVPATH" = "" ]; then
        # try to guess for CD
        DEVPATH=$(udevadm info --query=path --name=/dev/sr0 | perl -pe 's!/block/...$!!')
        if [ "$DEVPATH" = "" ]; then
                echo "No optical device attached?"
                echo "Try for harddisk"
                # try to guess for sdb
                DEVPATH=$(udevadm info --query=path --name=/dev/sdb | perl -pe 's!/block/...$!!')
        fi
fi

became this:

if [ "$DEVPATH" = "" ]
then
   DEVPATH="/devices/pci0000:00/0000:00:1f.2/ata2/host1/target1:0:0/1:0:0:0"
fi

There are also none of the notify or echo outputs on my terminal. I then used the updated script which is linked in the thinkwiki article in case the notify doesn’t work but it does not change anything.


Now if I have a SSD installed the following happens:

I run the script, the correct drive gets unmounted and the entry is removed from the explorer.
The problem is it stops at “issuing sleep command” in the terminal. Even if I kill the Terminal, the process is so persistent, that I can’t even shut down or reboot my machine other than hard resetting it. If I take out the Ultraybay module, my System Speaker starts to beep periodically. It doesn’t even stop while it is trying to shut down (the PC get’s stuck after logging out). Obviously, if I try to insert another Module / Drive it does not get recognized. I also can’t even kill the task with “sudo kill PID” which is very concerning.

The Terminal output looks like this:

[hannes@thinkpadhannes sbin]$ sudo ./ultrabay_eject

Fehler beim Erzeugen der Befehlszeile »dbus-launch --autolaunch=c8d6764bf338441f88600ffbebe3e65f --binary-syntax --close-stderr«: Der Kindprozess wurde mit Status 1 beendet

/dev/sdb:
 issuing sleep command

If I have my CD-Drive installed, the sleep command get’s issued, then there is this error

[hannes@thinkpadhannes sbin]$ sudo ./ultrabay_eject

/dev/sr0:
 issuing sleep command

Fehler beim Erzeugen der Befehlszeile »dbus-launch --autolaunch=c8d6764bf338441f88600ffbebe3e65f --binary-syntax --close-stderr«: Der Kindprozess wurde mit Status 1 beendet

[hannes@thinkpadhannes sbin]$ sudo ./ultrabay_eject

I’m now back at the command prompt and there is no funny stuff like beeping or not being able to shut down happening. But I still can not put another ultrabay module in so it get’s recognized.


The error translated is “Error spawning command line >>>dbus-launch --autolaunch --binary-syntax --close-stderr<<< Child process exited with code 1”

Do you have any idea what might cause this problem and if it is even safe to run this script under those conditions? It does not behave well at all. If you have additional sources where I can read and about the problem I would really appreciate it.

I also read through the discussion section of the thinkwiki page but besides the newer script nothing changed. Also the last entry is from 2010. Which is before my Thinkpad was even released. (last one in the list is W500, I have a W510. I also have a different Ultrabay version (I have Serial Ultrabay Enhanced, the W500 has Serial Ultrabay Slim. They are both full SATA Bays though so I think the behave similarly.

Thanks a lot for your time and have a nice day,
Hannes

Hmm - booting with entries in fstab which may or may not be available - is not worth the trouble.

Using systemd mount / automount units

Replace the entries with a systemd unit combo.

/etc/fstab

#UUID=dd91319d-c731-4939-a3c8-c4b472c2a958       /media/Data             ext4    defaults,nofail                 0       2
#UUID=24b34b91-f83f-4239-af3d-211dd1104bee       /media/Backup           ext4    defaults,nofail                 0       2
#UUID=373ADDA6610597A5                           /media/Windows          ntfs    defaults,nofail                 0       0
#UUID=AFE5A3B58FCBD714                           /mnt/WinSysRes          ntfs    defaults,nofail,noauto          0       0
#UUID=BC2CF6852CF639CA                           /media/ExterneHN        ntfs    defaults,nofail                 0       0

Data

 $ cat /etc/systemd/system/media-Data.mount
[Unit]
Description=Data partition on /media

[Mount]
TimeoutSec=10
What=/dev/disk/by-uuid/dd91319d-c731-4939-a3c8-c4b472c2a958
Where=/media/Data
Type=ext4
Options=defaults,rw,noatime
 $ cat /etc/systemd/system/media-Data.automount
[Unit]
Description=Automount Data partition on /media

[Automount]
Where=/media/Data
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

Backup

 $ cat /etc/systemd/system/media-Backup.mount
[Unit]
Description=Backup partition on /media

[Mount]
TimeoutSec=10
What=/dev/disk/by-uuid/24b34b91-f83f-4239-af3d-211dd1104bee
Where=/media/Backup
Type=ext4
Options=defaults,rw,noatime
 $ cat /etc/systemd/system/media-Backup.automount
[Unit]
Description=Automount Backup partition on /media

[Automount]
Where=/media/Backup
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

Windows

 $ cat /etc/systemd/system/media-Windows.mount
[Unit]
Description=Windows partition on /media

[Mount]
TimeoutSec=10
What=/dev/disk/by-uuid/373ADDA6610597A5
Where=/media/Windows
Type=ntfs
Options=defaults,rw,noatime
 $ cat /etc/systemd/system/media-Windows.automount
[Unit]
Description=Automount Windows partition on /media

[Automount]
Where=/media/Windows
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

WinSysRes

 $ cat /etc/systemd/system/mnt-WinSysRes.mount
[Unit]
Description=WinSysRes partition on /mnt

[Mount]
TimeoutSec=10
What=/dev/disk/by-uuid/AFE5A3B58FCBD714
Where=/mnt/WinSysRes
Type=ntfs
Options=defaults,rw,noatime
 $ cat /etc/systemd/system/mnt-WinSysRes.automount
[Unit]
Description=Automount WinSysRes partition on /mnt

[Automount]
Where=/mnt/WinSysRes
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

ExterneHN

 $ cat /etc/systemd/system/media-ExterneHN.mount
[Unit]
Description=ExterneHN partition on /media

[Mount]
TimeoutSec=10
What=/dev/disk/by-uuid/BC2CF6852CF639CA
Where=/media/ExterneHN
Type=ntfs
Options=defaults,rw,noatime
 $ cat /etc/systemd/system/media-ExterneHN.automount
[Unit]
Description=Automount ExterneHN partition on /media

[Automount]
Where=/media/ExterneHN
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target

Enable the automount unit only (assuming folders exist)

sudo systemctl enable --now \
    media-Data.automount \
    media-Backup.automount \
    media-Windows.automount \
    mnt-WinSysRes.automount \
    media-ExterneHN.automount

When ever you access the folder the system will mount the relevant device if accessible and unmount after 10s inactivity.

The idle time before unmount is in the automount unit TimeoutIdleSec property
The wait time for device ready is in the mount unit TimeoutSec property

The solution is fairly failsafe as you will not be able to access the mount point unless the device is in fact present.

A caveat for NTFS whether you use fstab or mount unit is the kernel vs userspace driver.

The kernel space driver will refuse to mount if it thinks the filesystem is dirty.

To work around such issue you will need to blacklist the kernel driver and ensure the userspace driver is installed.

2 Likes

Thank you so much for the fast answer and all your help!!! I just came around to trying it out and it works great, there is only one issue:

My explorer (thunar) is now really(!) slow. If I want to open it, it takes at least around 15-20 seconds every time. Also if I want to cd via bash into a mount point whose device isn‘t plugged in, it takes the same amount of time (something under a minute) between entering the command and the error message output. The same is for every program that opens thunar when it does so (open file, open project, etc.).

I came across this oddity: in the mount unit the path to the device is in the “by-uuid” folder. I looked into that and found, that only the exfat devices are represented there as a file. There are no files for my NTFS devices, maybe that is the problem?

I also set the TimeoutSec-Variable from ten to one second but that didn’t change anything.

Do you have any idea what the problem could be?

Thanks again for your help!
Greetings,
Hannes

For the mount unit - the TimeoutSec=10 is the time for the system to wait for the device to become available.

The reason for chosing 10s is - if the device is not there - you are forced to wait the defined seconds before you get a mount error - thus 10s seemed a reasonable time for a removable disk to come online.

I have been using similar units for years attaching network locations which worked just like if they were local disks.

For the autmount unit - the TimeoutIdleSec=10 is the time of inactivity before the device is taken offline.

I intentionally left out the [Install] for mount unit - as this should not be necessary when it is activated by an automount.

You can however add the lines below to the mount units - see if it makes a difference. You will need to reload the system daemon after saving the unit

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload

If you are having issues with long waits - there must other reasons

  • it could be that the ID’s are not correct - I only assumed they were as you posted the content of your fstab
  • it could be the system is slow to respond
  • it could be disk errors

I used the UUID but you can use a label instead

What=/dev/disk/by-label/ExterneHN