#!/bin/sh

echo "====== Delete old partitions ======"
sfdisk --delete /dev/sda
echo -e "===================================\n"

echo "====== Create new lvm partition /dev/sda1 ======"
sfdisk /dev/sda <<EOF
,,8e
EOF
if [ $? -eq 1 ]; then
  echo "====== ABORT: Partition in use right now ======"
  exit 1
fi
echo -e "===================================\n"

echo "====== Create volumegroup ======"
vgremove -f -y vg0 >/dev/null 2>&1
vgcreate -f -y vg0 /dev/sda1
echo -e "===================================\n"

echo "====== Create volume ======"
lvcreate -y -l 100%VG -n lv_var vg0
echo -e "===================================\n"

echo "====== Create ext4 filesystem ======"
mkfs.ext4 /dev/vg0/lv_var
echo "==================================="

echo "====== Please reboot the system ======"
