Ejecting and remounting external USB-Drive

bo2xs

New Member
May 26, 2025
2
0
1
Hi all,

I have the following scenario in my home lab:
Connected to my Proxmox server I have a USB drive (2bay ICY-Box as ZFS Mirror) used as a target for my Urbackup server (weekly backups of various computers around the house). I want to eject said drive to power it off via WiFi-Socket (power savings, noise etc.) when the backups are done and remount it when the next backup is scheduled. Therefore I wrote two scripts (eject, remount) which I will execute via cron:

Eject-Script:
#! /bin/bash

# Shutting down Urbackup
pct shutdown 108

sleep 5

pvesm set ZFS_Backup_Pool --disable 1
umount -R /ZFS_Backup_Pool/

hdparm -Y /dev/sdb
hdparm -Y /dev/sdc

Is that a good way to "eject" the USB-drive before I cut the power?

Remount-Script:
pvesm set ZFS_Backup_Pool --disable 0
mount /dev/sdb /mnt/backup_storage
pct start 108

Where I struggle is the remount script because as soon as the USB-drive is powered on again it is not sdb and sdc anymore, but sdd and sde. Also I don't know how to go about the remount since I have two drives and a simple "mount /dev/sdb /mnt/backup_storage" doesn't cut it.
Do you have suggestions for my two scripts?

Thank's in advance!
 
Use /dev/disk/by-id/... or /dev/disk/by-.../... instead of /dev/sd* to refer to disks.
As for unmounting I figure umount is smart enough to sync before unmounting and that should be enough.
Perhaps drop in a sync before and a eject /dev/disk/... call afterwards to make sure. Somewhat redundant but perhaps it makes you feel better.
Since this is a ZFS pool you probably want to export/import the pool instead and it should take care of the (un)mounting itself
 
Last edited:
  • Like
Reactions: bo2xs and leesteken
Thanks a lot! That was the missing link.

For anyone trying to do the same here are the two simple scripts:
Eject-Script:
#! /bin/bash

# Shutting down Urbackup
pct shutdown 108

sleep 5

pvesm set ZFS_Backup_Pool --disable 1
zpool export ZFS_Backup_Pool

hdparm -Y /dev/sdb
hdparm -Y /dev/sdc

Remount-Script:
pvesm set ZFS_Backup_Pool --disable 0
zpool import ZFS_Backup_Pool
pct start 108

Actually pretty simple if you know about zfs export/import ;-)
Also zfs import is handling the mounting very well so you don't have to care about /dev/sdc etc.
 
Also zfs import is handling the mounting very well so you don't have to care about /dev/sdc etc.
Except the next time you run the Eject-script those:
hdparm -Y /dev/sdb
hdparm -Y /dev/sdc
won't be right.