Last active
October 17, 2022 03:07
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The service instance name is the name of the VDO device as it appears in
vdoconf.yml
or the vdo line ofdmsetup.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.