Add btrfs support

This commit is contained in:
Jeremy Gardais 2019-06-30 14:27:52 +02:00
parent ef1d5e6c5d
commit 189a1ff13a
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 60 additions and 36 deletions

96
debian/chroot.install vendored
View File

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