Skip to content

Instantly share code, notes, and snippets.

@AfroThundr3007730
Last active October 17, 2022 03:07
Show Gist options
  • Save AfroThundr3007730/dfc869a88c825a7b1651db33efcf7cfe to your computer and use it in GitHub Desktop.
Save AfroThundr3007730/dfc869a88c825a7b1651db33efcf7cfe to your computer and use it in GitHub Desktop.
Automount a VDO device at boot (useful when root is on the VDO)
#!/bin/bash
[[ $1 == start && ! -b /dev/mapper/$2 ]] && {
[[ -d /sys/module/kvdo ]] || modprobe kvdo
target=$(readlink -f $(awk -v dev=$2 '$1~dev && $4~"vdo" {print $6}' /etc/dmsetup.table))
[[ $target =~ /dev/dm- ]] && target=$(find /dev/mapper -type l -lname "*${target##*/}")
table=$(awk -v dev=$2 -v target=$target '$1~dev && $4~"vdo" {sub($1FS,""); sub($5,target); print $0}' /etc/dmsetup.table)
echo dmsetup create $2 --table "$table"
[[ -b /dev/mapper/$2 ]] || exit 1
}
[[ $1 == stop && -b /dev/mapper/$2 ]] && {
echo dmsetup remove $2
[[ ! -b /dev/mapper/$2 ]] || exit 1
}
exit 0
[Unit]
Description=VDO device setup for %i
DefaultDependencies=no
IgnoreOnIsolate=true
OnFailure=emergency.target
Conflicts=umount.target
Before=unmount.target
Before=local-fs.target
After=cryptsetup.target
Requires=cryptsetup.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/sbin/dmsetup-vdo start %i
ExecStop=/usr/local/sbin/dmsetup-vdo stop %i
[Install]
RequiredBy=local-fs.target
@AfroThundr3007730
Copy link
Author

AfroThundr3007730 commented Oct 17, 2022

The service instance name is the name of the VDO device as it appears in vdoconf.yml or the vdo line of dmsetup.table before the colon.

The service assumes the VDO device is on a crypt device (directly or indirectly). If that's not the case, remove the cryptsetup.target lines.

The table can be created with dmsetup table > /etc/dmsetup.table, then enable the service and include it (plus symlinks) in the initrd.

The kvdo module will also need to be included, as well as the script and generated table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment