Follow-up to systemd services questions a little while ago

Hi all,

I had a conversation here recently with another user about difficulties I was having running a drive-sync service on Garuda.

Before we start, I’ll say that I have RTFM, so snarky push-backs not appreciated. I’m trying to learn here, as an old bloke.

Anyway, here’s the mandatory thingy:

System:
  Kernel: 6.9.7-zen1-1-zen arch: x86_64 bits: 64 compiler: gcc v: 14.1.1
    clocksource: tsc avail: acpi_pm
    parameters: BOOT_IMAGE=/@/boot/vmlinuz-linux-zen
    root=UUID=a647ace3-ddca-4e7d-9dc2-e18c06df28dd rw rootflags=subvol=@
    loglevel=3 ibt=off
  Desktop: KDE Plasma v: 6.1.2 tk: Qt v: N/A info: frameworks v: 6.3.0
    wm: kwin_wayland vt: 1 dm: SDDM Distro: Garuda base: Arch Linux
Machine:
  Type: Laptop System: TUXEDO product: TUXEDO InfinityBook S Gen8 v: N/A
    serial: <superuser required> Chassis: type: 10 serial: <superuser required>
  Mobo: NB01 model: NS5X_NS7XAU serial: <superuser required>
    part-nu: IBSGEN8 uuid: <superuser required> UEFI: INSYDE v: 1.07.10RTR1
    date: 03/08/2024
Battery:
  ID-1: BAT0 charge: 73.9 Wh (100.0%) condition: 73.9/73.9 Wh (100.0%)
    volts: 8.7 min: 7.7 model: Notebook BAT type: Li-ion serial: <filter>
    status: full
CPU:
  Info: model: 13th Gen Intel Core i7-1360P bits: 64 type: MST AMCP
    arch: Raptor Lake level: v3 note: check built: 2022+ process: Intel 7 (10nm)
    family: 6 model-id: 0xBA (186) stepping: 2 microcode: 0x4121
  Topology: cpus: 1x cores: 12 mt: 4 tpc: 2 st: 8 threads: 16 smt: enabled
    cache: L1: 1.1 MiB desc: d-8x32 KiB, 4x48 KiB; i-4x32 KiB, 8x64 KiB
    L2: 9 MiB desc: 4x1.2 MiB, 2x2 MiB L3: 18 MiB desc: 1x18 MiB
  Speed (MHz): avg: 536 high: 809 min/max: 400/5000:3700 scaling:
    driver: intel_pstate governor: powersave cores: 1: 400 2: 724 3: 400 4: 783
    5: 747 6: 400 7: 809 8: 400 9: 400 10: 733 11: 400 12: 400 13: 795 14: 400
    15: 400 16: 400 bogomips: 83558
  Flags: avx avx2 ht lm nx pae sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx
  Vulnerabilities: <filter>
Graphics:
  Device-1: Intel Raptor Lake-P [Iris Xe Graphics] vendor: CLEVO/KAPOK
    driver: i915 v: kernel alternate: xe arch: Gen-13 process: Intel 7 (10nm)
    built: 2022+ ports: active: DP-5 off: eDP-1 empty: DP-1, DP-2, DP-3,
    DP-4, DP-6, DP-7, HDMI-A-1 bus-ID: 00:02.0 chip-ID: 8086:a7a0
    class-ID: 0300
  Display: wayland server: X.org v: 1.21.1.13 with: Xwayland v: 24.1.0
    compositor: kwin_wayland driver: X: loaded: modesetting
    alternate: fbdev,intel,vesa dri: iris gpu: i915 display-ID: 0
  Monitor-1: DP-5 res: 1920x1080 size: N/A modes: N/A
  API: EGL v: 1.5 hw: drv: intel iris platforms: device: 0 drv: iris
    device: 1 drv: swrast surfaceless: drv: iris wayland: drv: iris x11:
    drv: iris inactive: gbm
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: intel mesa v: 24.1.3-arch1.1
    glx-v: 1.4 direct-render: yes renderer: Mesa Intel Graphics (RPL-P)
    device-ID: 8086:a7a0 memory: 15.16 GiB unified: yes display-ID: :1.0
  API: Vulkan v: 1.3.279 layers: 3 device: 0 type: integrated-gpu
    name: Intel Graphics (RPL-P) driver: mesa intel v: 24.1.3-arch1.1
    device-ID: 8086:a7a0 surfaces: xcb,xlib,wayland device: 1 type: cpu
    name: llvmpipe (LLVM 18.1.8 256 bits) driver: mesa llvmpipe
    v: 24.1.3-arch1.1 (LLVM 18.1.8) device-ID: 10005:0000
    surfaces: xcb,xlib,wayland
Audio:
  Device-1: Intel Raptor Lake-P/U/H cAVS vendor: CLEVO/KAPOK
    driver: snd_hda_intel v: kernel alternate: snd_soc_avs,snd_sof_pci_intel_tgl
    bus-ID: 00:1f.3 chip-ID: 8086:51ca class-ID: 0403
  Device-2: HP USB Audio driver: hid-generic,snd-usb-audio,usbhid type: USB
    rev: 2.0 speed: 480 Mb/s lanes: 1 mode: 2.0 bus-ID: 3-6.2:5
    chip-ID: 03f0:056b class-ID: 0300 serial: <filter>
  API: ALSA v: k6.9.7-zen1-1-zen status: kernel-api tools: N/A
  Server-1: PipeWire v: 1.2.0 status: active with: 1: pipewire-pulse
    status: active 2: wireplumber status: active 3: pipewire-alsa type: plugin
    4: pw-jack type: plugin tools: pactl,pw-cat,pw-cli,wpctl
Network:
  Device-1: Intel Raptor Lake PCH CNVi WiFi driver: iwlwifi v: kernel
    bus-ID: 00:14.3 chip-ID: 8086:51f1 class-ID: 0280
  IF: wlp0s20f3 state: down mac: <filter>
  Device-2: Realtek RTL8111/8168/8211/8411 PCI Express Gigabit Ethernet
    vendor: CLEVO/KAPOK driver: r8169 v: kernel pcie: gen: 1 speed: 2.5 GT/s
    lanes: 1 port: 3000 bus-ID: 2d:00.0 chip-ID: 10ec:8168 class-ID: 0200
  IF: enp45s0 state: down mac: <filter>
  Device-3: Realtek RTL8153 Gigabit Ethernet Adapter driver: r8152 type: USB
    rev: 3.0 speed: 5 Gb/s lanes: 1 mode: 3.2 gen-1x1 bus-ID: 2-1.4:5
    chip-ID: 0bda:8153 class-ID: 0000 serial: <filter>
  IF: enp0s13f0u1u4 state: up speed: 1000 Mbps duplex: full mac: <filter>
  IF-ID-1: tun0 state: unknown speed: 10000 Mbps duplex: full mac: N/A
  Info: services: NetworkManager, systemd-timesyncd, wpa_supplicant
Bluetooth:
  Device-1: Intel AX211 Bluetooth driver: btusb v: 0.8 type: USB rev: 2.0
    speed: 12 Mb/s lanes: 1 mode: 1.1 bus-ID: 3-10:3 chip-ID: 8087:0033
    class-ID: e001
  Report: btmgmt ID: hci0 rfk-id: 1 state: down bt-service: enabled,running
    rfk-block: hardware: no software: no address: <filter> bt-v: 5.3 lmp-v: 12
    status: discoverable: no pairing: no
Drives:
  Local Storage: total: 2.73 TiB used: 1.29 TiB (47.4%)
  SMART Message: Unable to run smartctl. Root privileges required.
  ID-1: /dev/nvme0n1 maj-min: 259:0 vendor: Samsung model: SSD 980 PRO 1TB
    size: 931.51 GiB block-size: physical: 512 B logical: 512 B speed: 63.2 Gb/s
    lanes: 4 tech: SSD serial: <filter> fw-rev: 5B2QGXA7 temp: 30.9 C
    scheme: GPT
  ID-2: /dev/sda maj-min: 8:0 vendor: Samsung model: PSSD T7
    size: 931.51 GiB block-size: physical: 512 B logical: 512 B type: USB
    rev: 3.2 spd: 5 Gb/s lanes: 1 mode: 3.2 gen-1x1 tech: SSD serial: <filter>
    scheme: GPT
  ID-3: /dev/sdb maj-min: 8:16 vendor: Samsung model: PSSD T7
    size: 931.51 GiB block-size: physical: 512 B logical: 512 B type: USB
    rev: 3.2 spd: 5 Gb/s lanes: 1 mode: 3.2 gen-1x1 tech: SSD serial: <filter>
    scheme: MBR
Partition:
  ID-1: / raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
    used: 24.17 GiB (2.6%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
  ID-2: /boot/efi raw-size: 300 MiB size: 299.4 MiB (99.80%)
    used: 584 KiB (0.2%) fs: vfat dev: /dev/nvme0n1p1 maj-min: 259:1
  ID-3: /home raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
    used: 24.17 GiB (2.6%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
  ID-4: /var/log raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
    used: 24.17 GiB (2.6%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
  ID-5: /var/tmp raw-size: 931.22 GiB size: 931.22 GiB (100.00%)
    used: 24.17 GiB (2.6%) fs: btrfs dev: /dev/nvme0n1p2 maj-min: 259:2
Swap:
  Kernel: swappiness: 133 (default 60) cache-pressure: 100 (default) zswap: no
  ID-1: swap-1 type: zram size: 31.05 GiB used: 0 KiB (0.0%) priority: 100
    comp: zstd avail: lzo,lzo-rle,lz4,lz4hc,842 max-streams: 16 dev: /dev/zram0
Sensors:
  System Temperatures: cpu: 39.0 C mobo: N/A
  Fan Speeds (rpm): N/A
Info:
  Memory: total: 32 GiB note: est. available: 31.05 GiB used: 3.64 GiB (11.7%)
  Processes: 350 Power: uptime: 10m states: freeze,mem,disk suspend: s2idle
    avail: deep wakeups: 0 hibernate: platform avail: shutdown, reboot,
    suspend, test_resume image: 12.41 GiB services: org_kde_powerdevil,
    power-profiles-daemon, upowerd Init: systemd v: 256 default: graphical
    tool: systemctl
  Packages: 1513 pm: pacman pkgs: 1507 libs: 432 tools: octopi,pamac,paru
    pm: flatpak pkgs: 6 Compilers: gcc: 14.1.1 Shell: garuda-inxi default: fish
    v: 3.7.1 running-in: konsole inxi: 3.3.35
Garuda (2.6.26-1):
  System install date:     2024-06-24
  Last full system update: 2024-07-21
  Is partially upgraded:   Yes
  Relevant software:       snapper NetworkManager dracut
  Windows dual boot:       No/Undetected
  Failed units:            

I’ve been trying to set up a systemd service to clone SSD1 (/dev/sda) to SSD2 (/dev/sda2) which are mounted respectively as “/run/media/keith/BACKUP” and “/run/media/keith/EXTRA”.

A lovely person here suggested a little while back that I add this to my
/etc/systemd/system/drive-mirroring.service

RequiresMountsFor=/run/media/keith/BACKUP
RequiresMountsFor=/run/media/keith/EXTRA

That works perfectly on the second run, but the initial run on start-up still complains about this:

Aug 02 19:36:27 Tuxedo drive-mirroring[1270]: rsync: [sender] change_dir "/run/media/keith/BACKUP" failed: No
such file or directory (2)
Aug 02 19:36:27 Tuxedo drive-mirroring[1274]: rsync: [Receiver] change_dir#3 "/run/media/keith" failed: No suc
h file or directory (2)

I’d love to learn how to start this service seamlessly each time I kick the machine into life. Is there a command I could add which would ‘stall’ the service until those drives are available and read/writable? Or a better solution?

If I need to provide further info which might help, please let me know. Snarky RTFM comments will be ignored. Thx!

For the purposes of completeness, here is all of the three files involved in this service:

First, /etc/systemd/system/drive-mirroring.service:

[Unit]
Description=Drive sync
RequiresMountsFor=/run/media/keith/BACKUP
RequiresMountsFor=/run/media/keith/EXTRA

[Service]
Type=simple
ExecStart=/usr/local/bin/drive-mirroring

Then we have the timer at
/etc/systemd/system/drive-mirroring.timer:

[Unit]
Description=Drive sync

[Timer]
#OnCalendar=hourly
OnCalendar=*:0/10
Persistent=trueRequiresMountsFor

[Install]
WantedBy=timers.target

Finally, we have the actual service itself here:
/usr/local/bin/drive-mirroring

Which has this

echo "########### Drive mirroring starting at `date` ###########"

SOURCE=/run/media/keith/BACKUP/
DEST=/run/media/keith/EXTRA

rsync -ahvAE --delete --stats $SOURCE $DEST 2>&1

echo "########### Drive mirroring completed at `date` ###########"

I had hoped, or assumed, that adding the “RequiresMountsFor” things might have resolved that, but apparently not.

Any suggestions or ideas are always welcome!

I think the issue is that RequiresMountsFor only ensures that the service doesn’t start until the mount points are available, but it doesn’t guarantee that the filesystems are fully mounted and ready for use. Let’s try adding Wants= and After= dependencies for the local-fs.target, which should hold off until all local filesystems are actually mounted.

[Unit]
Description=Drive sync
RequiresMountsFor=/run/media/keith/BACKUP
RequiresMountsFor=/run/media/keith/EXTRA
Wants=local-fs.target
After=local-fs.target

[Service]
Type=simple
ExecStart=/usr/local/bin/drive-mirroring
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.