#!/bin/sh # Vars ## Define the hard drive to use if [ -b '/dev/sda' ]; then hdd="/dev/sda" else printf '%b\n' "Please check the hard drive to use" exit 0 fi ## Volume Group name to use for LVM vgname="ovhsys" ## If the script should manage the partitions (delete, add,…) manage_part=0 # Partitionning {{{ if [ "${manage_part}" -eq 0 ]; then ## Remove all old partitions for part_number in 1 2 3 4 5 6 7 8; do [ -b "${hdd}""${part_number}" ] && parted "${hdd}" rm "${part_number}" done ## Recreate partition (/boot and LV) {{{ ### Partition type parted "${hdd}" mklabel msdos ### /boot parted "${hdd}" mkpart primary 0% 512MB parted "${hdd}" set 1 boot on ### LV parted "${hdd}" mkpart primary 4194kB 100% parted "${hdd}" set 2 lvm on sudo pvcreate "${hdd}"2 sudo vgcreate "${vgname}" "${hdd}"2 fi mkfs.ext3 -F -- "${hdd}"1 ## }}} ## Create Logical Volumes {{{ [ ! -b /dev/mapper/"${vgname}"-home ] && lvcreate -n home -L 20g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-opt ] && lvcreate -n opt -L 2g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-root ] && lvcreate -n root -L 5g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-srv ] && lvcreate -n srv -L 2g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-tmp ] && lvcreate -n tmp -L 10g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-usr ] && lvcreate -n usr -L 15g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-var ] && lvcreate -n var -L 10g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-vz ] && lvcreate -n vz -L 150g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-bkp ] && lvcreate -n bkp -L 150g "${vgname}" [ ! -b /dev/mapper/"${vgname}"-swap ] && lvcreate -n swap -L 2g "${vgname}" ### Format the LV in ext4 for lvname in /dev/mapper/"${vgname}"-*; do mkfs.ext4 -F -- "${lvname}" done ### And format the swap mkswap /dev/mapper/"${vgname}"-swap ## }}} # }}}