scripts/debian/chroot.install

117 lines
3.9 KiB
Plaintext
Raw Normal View History

#!/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
2019-04-03 09:46:09 +02:00
## Package to exclude from debootstrap install
dbs_pkg_exclude="vim"
## Package to include to debootstrap install
dbs_pkg_include="bzip2,debconf-i18n,dialog,dmsetup,htop,isc-dhcp-client,isc-dhcp-common,locales,lvm2,pciutils,tmux,vim-nox,wget,zsh"
# 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
2019-04-02 20:15:10 +02:00
sudo vgcreate "${vgname}" "${hdd}"2
fi
2019-04-02 21:20:34 +02:00
mkfs.ext3 -F -L boot -- "${hdd}"1
2019-04-02 20:15:10 +02:00
2019-04-02 18:37:01 +02:00
## }}}
## 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
2019-04-02 21:20:34 +02:00
cd -- /dev/"${vgname}" || exit 1
for lvname in *; do
mkfs.ext4 -F -L "${lvname}" -- "${lvname}"
2019-04-02 18:37:01 +02:00
done
2019-04-02 21:20:34 +02:00
cd -- - || exit 1
2019-04-02 18:37:01 +02:00
### And format the swap
2019-04-02 21:20:34 +02:00
mkswap -L sw01 -- /dev/mapper/"${vgname}"-swap
## }}}
# }}}
# Debootstrap {{{
## Create and mount the system {{{
### Root
mkdir -p -- /target
mountpoint -q /target || mount -- /dev/mapper/"${vgname}"-root /target
### boot - grub
mkdir -p -- /target/boot
mountpoint -q /target/boot || mount -- ${hdd}1 /target/boot
### home LV
mkdir -p -- /target/home
mountpoint -q /target/home || mount -- /dev/mapper/"${vgname}"-home /target/home
### opt LV
mkdir -p -- /target/opt
mountpoint -q /target/opt || mount -- /dev/mapper/"${vgname}"-opt /target/opt
### srv LV
mkdir -p -- /target/srv
mountpoint -q /target/srv || mount -- /dev/mapper/"${vgname}"-srv /target/srv
#### bkp LV
mkdir -p -- /target/srv/backup
mountpoint -q /target/srv/backup || mount -- /dev/mapper/"${vgname}"-bkp /target/srv/backup
### tmp LV
mkdir -p -- /target/tmp
mountpoint -q /target/tmp || mount -- /dev/mapper/"${vgname}"-tmp /target/tmp
### usr LV
mkdir -p -- /target/usr
mountpoint -q /target/usr || mount -- /dev/mapper/"${vgname}"-usr /target/usr
### var LV
mkdir -p -- /target/var
mountpoint -q /target/var || mount -- /dev/mapper/"${vgname}"-var /target/var
#### vz LV
mkdir -p -- /target/var/lib/vz
mountpoint -q /target/var/lib/vz || mount -- /dev/mapper/"${vgname}"-vz /target/var/lib/vz
### Swap
swapon -- /dev/mapper/"${vgname}"-swap
### System
mkdir -p -- /target/dev/pts
mountpoint -q /target/dev/pts || mount -o bind -- /dev/pts /target/dev/pts
mkdir -p -- /target/proc
mountpoint -q /target/proc || mount -t proc -- proc /target/proc
mkdir -p -- /target/sys
mountpoint -q /target/sys || mount -o bind -- /sys /target/sys
## }}}
2019-04-03 09:46:09 +02:00
## Run debootstrap
debootstrap --arch amd64 --include="${dbs_pkg_include}" --exclude="${dbs_pkg_exclude}" stretch /target http://ftp.fr.debian.org/debian
# }}}