Add btrfs support
This commit is contained in:
parent
ef1d5e6c5d
commit
189a1ff13a
|
@ -9,11 +9,13 @@ else
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
## Computer hostname
|
## Computer hostname
|
||||||
new_hostname="2g"
|
new_hostname="ks10"
|
||||||
## Volume Group name to use for LVM
|
## Volume Group name to use for LVM
|
||||||
vgname="ovhsys"
|
vgname="ovhsys"
|
||||||
## If the script should manage the partitions (delete, add,…)
|
## If the script should manage the partitions (delete, add,…)
|
||||||
manage_part=0
|
manage_part=0
|
||||||
|
## If the script should use BTRFS
|
||||||
|
manage_btrfs=1
|
||||||
## Colors definition {{{
|
## Colors definition {{{
|
||||||
BLACK='\033[49;30m'
|
BLACK='\033[49;30m'
|
||||||
BLACKB='\033[49;90m'
|
BLACKB='\033[49;90m'
|
||||||
|
@ -62,24 +64,37 @@ mkfs.ext3 -F -L boot -- "${hdd}"1
|
||||||
|
|
||||||
## }}}
|
## }}}
|
||||||
## Create Logical Volumes {{{
|
## Create Logical Volumes {{{
|
||||||
[ ! -b /dev/mapper/"${vgname}"-home ] && lvcreate -n home -L 20g "${vgname}"
|
if [ "${manage_btrfs}" -eq 0 ]; then
|
||||||
[ ! -b /dev/mapper/"${vgname}"-opt ] && lvcreate -n opt -L 2g "${vgname}"
|
### Create only 1 LV for btrfs base system
|
||||||
[ ! -b /dev/mapper/"${vgname}"-root ] && lvcreate -n root -L 5g "${vgname}"
|
[ ! -b /dev/mapper/"${vgname}"-home ] && lvcreate -n root -L 100g "${vgname}"
|
||||||
[ ! -b /dev/mapper/"${vgname}"-srv ] && lvcreate -n srv -L 2g "${vgname}"
|
else
|
||||||
[ ! -b /dev/mapper/"${vgname}"-tmp ] && lvcreate -n tmp -L 10g "${vgname}"
|
### Otherwise create differents LVs
|
||||||
[ ! -b /dev/mapper/"${vgname}"-usr ] && lvcreate -n usr -L 15g "${vgname}"
|
[ ! -b /dev/mapper/"${vgname}"-home ] && lvcreate -n home -L 20g "${vgname}"
|
||||||
[ ! -b /dev/mapper/"${vgname}"-var ] && lvcreate -n var -L 10g "${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}"
|
||||||
|
fi
|
||||||
|
### Create extra LVs
|
||||||
[ ! -b /dev/mapper/"${vgname}"-vz ] && lvcreate -n vz -L 150g "${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}"-bkp ] && lvcreate -n bkp -L 150g "${vgname}"
|
||||||
[ ! -b /dev/mapper/"${vgname}"-swap ] && lvcreate -n swap -L 2g "${vgname}"
|
[ ! -b /dev/mapper/"${vgname}"-swap ] && lvcreate -n swap -L 2g "${vgname}"
|
||||||
|
|
||||||
### Format the LV in ext4
|
### Format LVs in ext4
|
||||||
cd -- /dev/"${vgname}" || exit 1
|
cd -- /dev/"${vgname}" || exit 1
|
||||||
for lvname in *; do
|
for lvname in *; do
|
||||||
mkfs.ext4 -F -L "${lvname}" -- "${lvname}"
|
mkfs.ext4 -F -L "${lvname}" -- "${lvname}"
|
||||||
done
|
done
|
||||||
cd -- - || exit 1
|
cd -- - || exit 1
|
||||||
|
|
||||||
|
### (re)format Btrfs LV
|
||||||
|
if [ "${manage_btrfs}" -eq 0 ]; then
|
||||||
|
### Ensure to format Btrfs LV
|
||||||
|
mkfs.btrfs --force -L root -- /dev/"${vgname}"/root
|
||||||
|
fi
|
||||||
|
|
||||||
### And format the swap
|
### And format the swap
|
||||||
mkswap -L sw01 -- /dev/mapper/"${vgname}"-swap
|
mkswap -L sw01 -- /dev/mapper/"${vgname}"-swap
|
||||||
## }}}
|
## }}}
|
||||||
|
@ -97,36 +112,45 @@ mkdir -p -- /target/boot
|
||||||
mountpoint -q /target/boot || mount -- ${hdd}1 /target/boot
|
mountpoint -q /target/boot || mount -- ${hdd}1 /target/boot
|
||||||
printf '%b\n' "${hdd}1 /boot ext3 defaults 0 0" >> /tmp/target.fstab
|
printf '%b\n' "${hdd}1 /boot ext3 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
|
||||||
### home LV
|
### Prepare the base system tree according to the expected file system
|
||||||
mkdir -p -- /target/home
|
if [ "${manage_btrfs}" -eq 0 ]; then
|
||||||
mountpoint -q /target/home || mount -- /dev/mapper/"${vgname}"-home /target/home
|
#### Download an extra script for Btrfs
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-home /home ext4 defaults 0 0" >> /tmp/target.fstab
|
wget -O /tmp/part.btrfs.sh "https://git.101010.fr/gardouille-dotfiles/scripts/raw/master/debian/part.btrfs.sh"
|
||||||
### opt LV
|
#### Create several subvolumes
|
||||||
mkdir -p -- /target/opt
|
chmod +x /tmp/part.btrfs.sh && /tmp/part.btrfs.sh
|
||||||
mountpoint -q /target/opt || mount -- /dev/mapper/"${vgname}"-opt /target/opt
|
else ### Or for ext4, create mountpoint and mount LV
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-opt /opt ext4 defaults 0 0" >> /tmp/target.fstab
|
#### home LV
|
||||||
### srv LV
|
mkdir -p -- /target/home
|
||||||
mkdir -p -- /target/srv
|
mountpoint -q /target/home || mount -- /dev/mapper/"${vgname}"-home /target/home
|
||||||
mountpoint -q /target/srv || mount -- /dev/mapper/"${vgname}"-srv /target/srv
|
printf '%b\n' "/dev/mapper/${vgname}-home /home ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-srv /srv ext4 defaults 0 0" >> /tmp/target.fstab
|
#### opt LV
|
||||||
#### bkp LV
|
mkdir -p -- /target/opt
|
||||||
|
mountpoint -q /target/opt || mount -- /dev/mapper/"${vgname}"-opt /target/opt
|
||||||
|
printf '%b\n' "/dev/mapper/${vgname}-opt /opt ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
#### srv LV
|
||||||
|
mkdir -p -- /target/srv
|
||||||
|
mountpoint -q /target/srv || mount -- /dev/mapper/"${vgname}"-srv /target/srv
|
||||||
|
printf '%b\n' "/dev/mapper/${vgname}-srv /srv ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
#### tmp LV
|
||||||
|
mkdir -p -- /target/tmp
|
||||||
|
chmod 0777 -- /target/tmp
|
||||||
|
mountpoint -q /target/tmp || mount -- /dev/mapper/"${vgname}"-tmp /target/tmp
|
||||||
|
printf '%b\n' "/dev/mapper/${vgname}-tmp /tmp ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
#### usr LV
|
||||||
|
mkdir -p -- /target/usr
|
||||||
|
mountpoint -q /target/usr || mount -- /dev/mapper/"${vgname}"-usr /target/usr
|
||||||
|
printf '%b\n' "/dev/mapper/${vgname}-usr /usr ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
#### var LV
|
||||||
|
mkdir -p -- /target/var
|
||||||
|
mountpoint -q /target/var || mount -- /dev/mapper/"${vgname}"-var /target/var
|
||||||
|
printf '%b\n' "/dev/mapper/${vgname}-var /var ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
fi
|
||||||
|
|
||||||
|
### Extra bkp LV
|
||||||
mkdir -p -- /target/srv/backup
|
mkdir -p -- /target/srv/backup
|
||||||
mountpoint -q /target/srv/backup || mount -- /dev/mapper/"${vgname}"-bkp /target/srv/backup
|
mountpoint -q /target/srv/backup || mount -- /dev/mapper/"${vgname}"-bkp /target/srv/backup
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-bkp /srv/backup ext4 defaults 0 0" >> /tmp/target.fstab
|
printf '%b\n' "/dev/mapper/${vgname}-bkp /srv/backup ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
### tmp LV
|
### Extra vz LV
|
||||||
mkdir -p -- /target/tmp
|
|
||||||
chmod 0777 -- /target/tmp
|
|
||||||
mountpoint -q /target/tmp || mount -- /dev/mapper/"${vgname}"-tmp /target/tmp
|
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-tmp /tmp ext4 defaults 0 0" >> /tmp/target.fstab
|
|
||||||
### usr LV
|
|
||||||
mkdir -p -- /target/usr
|
|
||||||
mountpoint -q /target/usr || mount -- /dev/mapper/"${vgname}"-usr /target/usr
|
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-usr /usr ext4 defaults 0 0" >> /tmp/target.fstab
|
|
||||||
### var LV
|
|
||||||
mkdir -p -- /target/var
|
|
||||||
mountpoint -q /target/var || mount -- /dev/mapper/"${vgname}"-var /target/var
|
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-var /var ext4 defaults 0 0" >> /tmp/target.fstab
|
|
||||||
#### vz LV
|
|
||||||
mkdir -p -- /target/var/lib/vz
|
mkdir -p -- /target/var/lib/vz
|
||||||
mountpoint -q /target/var/lib/vz || mount -- /dev/mapper/"${vgname}"-vz /target/var/lib/vz
|
mountpoint -q /target/var/lib/vz || mount -- /dev/mapper/"${vgname}"-vz /target/var/lib/vz
|
||||||
printf '%b\n' "/dev/mapper/${vgname}-vz /var/lib/vz ext4 defaults 0 0" >> /tmp/target.fstab
|
printf '%b\n' "/dev/mapper/${vgname}-vz /var/lib/vz ext4 defaults 0 0" >> /tmp/target.fstab
|
||||||
|
|
Loading…
Reference in New Issue