I'm working on automating creation of BTRFS filesystems for my purposes in the cloud. The process is a little annoying to be honest, and I'd like to cut out a few steps in the process.
My process looks currently like this:
parted /dev/sdX mklabel gpt
parted /dev/sdX mkpart primary 2048s 100%
mkfs.btrfs /dev/sdXYor do LVM hacks:
vgcreate mygroup /dev/sdXY
lvcreate -l 100%FREE -n mylv mygroup
mount -t btrfs -o defaults,ssd,compress=lzo /dev/sdXY $MOUNTDIR
btrfs subvolume create $MOUNTDIR/root
echo "UUID=$(blkid -s UUID -o value /dev/sdXY) /mount/dir btrfs defaults,ssd,compress=lzo,subvol=root 0 0" >> /etc/fstab
This process is ugly, but it works.
Is there a way that I can get rid of steps 4-7 by creating a subvolume without the filesystem being mounted?