homelab/packer/files/filesystem.sh

22 lines
451 B
Bash
Raw Permalink Normal View History

2024-01-28 08:31:39 +00:00
#!/bin/bash
set -euo pipefail
# required env
# - LABEL filestystem label
# partitions
dd if=/dev/zero of=/dev/sda bs=1MiB count=1 status=none
xargs -L1 parted --script /dev/sda -- <<EOF
mklabel msdos
mkpart primary linux-swap 1MiB 2GiB
mkpart primary btrfs 2GiB 100%
set 1 boot on
EOF
# filesystems
mkswap -L swap /dev/sda1
swapon /dev/sda1
mkfs.btrfs --force --label "${LABEL}" /dev/sda2
mount -o compress=lzo,commit=90,autodefrag /dev/sda2 /mnt