Created
January 28, 2017 11:20
-
-
Save stuartwakefield/fd3519e5aaf26498d7f8ca7f61f3e380 to your computer and use it in GitHub Desktop.
Cloud init service block to conditionally format an unformatted volume.
This file contains 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
name: format-volume.service | |
command: start | |
content: | | |
[Unit] | |
Description=Formats the volume drive | |
Requires=dev-vdb.device | |
After=dev-vdb.device | |
ConditionFirstBoot=true | |
[Service] | |
Type=oneshot | |
RemainAfterExit=yes | |
ExecStart=/usr/bin/bash -xc "\ | |
(/usr/bin/lsblk --fs | /usr/bin/grep vdb1 | /usr/bin/grep --silent ext4) || (\ | |
/usr/sbin/parted --machine --script /dev/vdb mklabel gpt &&\ | |
/usr/sbin/parted --machine --script --align=opt /dev/vdb mkpart primary ext4 0% 100% &&\ | |
/usr/sbin/mkfs.ext4 -L VOLUME-A /dev/vdb1)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment