Skip to content

Instantly share code, notes, and snippets.

@Strubbl
Last active August 29, 2015 14:05
Show Gist options
  • Save Strubbl/46858a0733c8739c8e7a to your computer and use it in GitHub Desktop.
Save Strubbl/46858a0733c8739c8e7a to your computer and use it in GitHub Desktop.
systemd service unit for mounting a dm-crypt device
[Unit]
Description=Mount share disk when available
After=cryptsetup.target
ConditionPathExists=/dev/sda
ConditionPathIsDirectory=/media/share
ConditionFileIsExecutable=/usr/bin/cryptsetup
ConditionFileIsExecutable=/usr/bin/mount
ConditionFileNotEmpty=/etc/keys/share.key
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/cryptsetup --key-file=/etc/keys/share.key luksOpen /dev/sda share
ExecStart=/usr/bin/mount -o defaults /dev/mapper/share /media/share
ExecStop=/usr/bin/umount /media/share
ExecStopPost=/usr/bin/cryptsetup luksClose share
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment