Skip to content

Instantly share code, notes, and snippets.

@stuartwakefield
Created January 28, 2017 11:20
Show Gist options
  • Save stuartwakefield/fd3519e5aaf26498d7f8ca7f61f3e380 to your computer and use it in GitHub Desktop.
Save stuartwakefield/fd3519e5aaf26498d7f8ca7f61f3e380 to your computer and use it in GitHub Desktop.
Cloud init service block to conditionally format an unformatted volume.
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