From a326c20ca209fd477d2e88bf32dd60de820c3feb Mon Sep 17 00:00:00 2001 From: root Date: Fri, 11 May 2018 17:56:35 +0200 Subject: [PATCH] WIP --- config/etc/crypttab | 2 ++ config/etc/fstab | 7 +++++ config/etc/mdadm/mdadm.conf | 0 debootstrap.sh | 30 -------------------- parted/ovh.sh | 5 +++- post-debootstrap-installer.sh | 26 ++++++++++++++++-- setup.sh | 52 +++++++++++++++++++++++++++++++++++ 7 files changed, 89 insertions(+), 33 deletions(-) create mode 100644 config/etc/crypttab create mode 100644 config/etc/fstab create mode 100644 config/etc/mdadm/mdadm.conf delete mode 100755 debootstrap.sh create mode 100755 setup.sh diff --git a/config/etc/crypttab b/config/etc/crypttab new file mode 100644 index 0000000..646ef98 --- /dev/null +++ b/config/etc/crypttab @@ -0,0 +1,2 @@ +# +md0-unlocked /dev/md0 none luks,discard diff --git a/config/etc/fstab b/config/etc/fstab new file mode 100644 index 0000000..7cb336d --- /dev/null +++ b/config/etc/fstab @@ -0,0 +1,7 @@ +# +# /etc/fstab: static file system information +# +# + +/dev/mapper/md0-unlocked / btrfs relatime,ssd 0 0 +/dev/md1 /boot btrfs relatime,ssd 0 0 diff --git a/config/etc/mdadm/mdadm.conf b/config/etc/mdadm/mdadm.conf new file mode 100644 index 0000000..e69de29 diff --git a/debootstrap.sh b/debootstrap.sh deleted file mode 100755 index fe4b15e..0000000 --- a/debootstrap.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -set -e - - -apt-get -y install mdadm btrfs-tools - -"./parted/${1}.sh" # "returns" /dev/md0 as root device - -echo -n 'Enter luks password: ' -read -s md0pwd -echo -n $md0pwd | cryptsetup -q luksFormat /dev/md0 -unset md0pwd - -cryptsetup open --type luks /dev/md0 md0-unlocked - -mkfs.btrfs /dev/mapper/md0-unlocked - -mkdir /mnt/md0-unlocked -mount /dev/mapper/md0-unlocked /mnt/md0-unlocked - -debootstrap --variant=minbase --arch=amd64 stretch /mnt/md0-unlocked https://deb.debian.org/debian/ - -mount -t proc none /mnt/md0-unlocked/proc -mount -t sysfs none /mnt/md0-unlocked/sys -mount -o bind /dev /mnt/md0-unlocked/dev - -cp docker.key /mnt/md0-unlocked/docker.key -cp -a post-debootstrap-installer.sh /mnt/md0-unlocked/post-debootstrap-installer.sh - -chroot /mnt/md0-unlocked /post-debootstrap-installer.sh diff --git a/parted/ovh.sh b/parted/ovh.sh index 290f2b8..0f0ea6e 100755 --- a/parted/ovh.sh +++ b/parted/ovh.sh @@ -4,7 +4,10 @@ set -e parted /dev/sda mklabel msdos parted /dev/sda mkpart primary 1 440GiB +parted /dev/sda mkpart primary 440GiB 2GiB parted /dev/sdb mklabel msdos parted /dev/sdb mkpart primary 1 440GiB +parted /dev/sdb mkpart primary 440GiB 2GiB -mdadm -C /dev/md0 -l1 -n2 /dev/sda1 /dev/sdb1 <<< yes +echo 'yes' | mdadm -C /dev/md0 -l1 -n2 /dev/sd[ab]1 +echo 'yes' | mdadm -C /dev/md1 -l1 -n2 /dev/sd[ab]2 diff --git a/post-debootstrap-installer.sh b/post-debootstrap-installer.sh index 683772a..0a883fc 100755 --- a/post-debootstrap-installer.sh +++ b/post-debootstrap-installer.sh @@ -1,6 +1,7 @@ #!/bin/bash set -e +# locales echo 'console-setup console-setup/charmap47 select UTF-8' | debconf-set-selections echo 'keyboard-configuration keyboard-configuration/variant select English (US)' | debconf-set-selections @@ -10,7 +11,25 @@ echo 'locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8' | d apt-get -y install locales -# add docker key + +# mdadm.conf + +#replace rescue system hostname with real hostname +mdadm --examine --scan | perl -pe 's/name\=.*?:/name='"$(cat /etc/hostname)"':/' > /etc/mdadm/mdadm.conf + + +# GRUB + +apt-get -y install + +update-grub +grub-install /dev/sda +grub-install /dev/sdb + + +# Docker + +#add docker key apt-get -y install gnupg2 apt-key add docker.key apt-get -y --purge autoremove gnupg2 @@ -18,6 +37,9 @@ apt-get -y --purge autoremove gnupg2 echo 'deb https://download.docker.com/linux/debian stretch stable' > /etc/apt/sources.list.d/docker.list apt-get update + +# tbd + apt-get -y install \ systemd \ - dropbear + dropbear \ diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..d6a1cdf --- /dev/null +++ b/setup.sh @@ -0,0 +1,52 @@ +#!/bin/bash +set -e + + +apt-get -y install mdadm btrfs-tools + +# returns /dev/md0 as root device +# returns /dev/md1 as boot device +"./parted/${1}.sh" + +# encrypt and unlock root device +echo 'Enter luks password: ' +read -s md0pwd +echo -n $md0pwd | cryptsetup -q luksFormat /dev/md0 +echo -n $md0pwd | cryptsetup open --type luks /dev/md0 md0-unlocked +unset md0pwd + + +# format + +chroot=/mnt/md0-unlocked + +# root device +mkfs.btrfs /dev/mapper/md0-unlocked +mkdir /mnt/md0-unlocked +mount /dev/mapper/md0-unlocked /mnt/md0-unlocked + +# boot device +mkfs.btrfs /dev/md1 +mkdir "$chroot/boot" +mount /dev/md1 "$chroot/boot" + + +# debootstrap + +debootstrap --variant=minbase --arch=amd64 stretch "$chroot" https://deb.debian.org/debian/ + +mount -t proc none "$chroot/proc" +mount -t sysfs none "$chroot/sys" +mount -o bind /dev "$chroot/dev" + +cp -a "$chroot/docker.key" \ + "$chroot/post-debootstrap-installer.sh" \ + /mnt/md0/unlocked/ + +# set hostname +echo "$2" > "$chroot/etc/hostname" + +chroot "$chroot" /post-debootstrap-installer.sh + +rm "$chroot/docker.key" \ + "$chroot/post-debootstrap-installer.sh"