Created
November 12, 2017 13:38
-
-
Save gronke/d266ca526241d6c6007b7ee2ae77ef00 to your computer and use it in GitHub Desktop.
Provision Debian for libvirt with debootstrap on a Hetzner host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# - expects ZFS on the target host | |
# - expects ZFS on the target host | |
# Usage Example | |
# | |
# ./debootstrap-debian-hetzner.sh www \ | |
# <ADDITIONAL_IP4_ADDR> \ | |
# <IP4_ADDR_HOST> \ | |
# <IP6_NETWORK> | |
DEBOOTSTRAP_NAME="$1" | |
IP4_GUEST="$2" | |
IP4_HOST="$3" # Gateway and DNS IPv4 | |
IP6_GUEST="$4::2" | |
IP6_HOST="$4::1" # Gateway and DNS IPv6 | |
IP6_NETMASK="80" | |
MIRROR_URL="https://mirror.hetzner.de/debian/packages" | |
ZFS_POOL="tank" | |
VOLUME_SIZE="16G" | |
DEBIAN_VERSION="stretch" | |
zfs create -s -V "$VOLUME_SIZE" $ZFS_POOL/vm/$DEBOOTSTRAP_NAME | |
fdisk /dev/zvol/$ZFS_POOL/vm/$DEBOOTSTRAP_NAME | |
mkfs.ext4 /dev/zvol/$ZFS_POOL/vm/$DEBOOTSTRAP_NAME-part1 | |
DISK_UUID_STRING=$(blkid /dev/zvol/$ZFS_POOL/vm/$DEBOOTSTRAP_NAME-part1 | awk '{ print $2 }') | |
CHROOT_DIR=`mktemp -d` | |
mount /dev/zvol/$ZFS_POOL/vm/$DEBOOTSTRAP_NAME-part1 $CHROOT_DIR | |
debootstrap --include=resolvconf,vim,rsync,openssh-server,acpid $DEBIAN_VERSION $CHROOT_DIR $MIRRIR_URL | |
echo "proc $CHROOT_DIR/proc proc defaults 0 0" >> $CHROOT_DIR/etc/fstab | |
echo "sysfs $CHROOT_DIR/sys sysfs defaults 0 0" >> $CHROOT_DIR/etc/fstab | |
echo "$DISK_UUID_STRING / ext4 errors=remount-ro 0 1" >> $CHROOT_DIR/etc/fstab | |
mount --bind /dev /mnt/dev/dev | |
mount --bind /dev/pts /mnt/dev/pts/dev/pts | |
mount -t proc proc /mnt/proc | |
mount -t sysfs sys /mnt/sys | |
cp /etc/hosts $CHROOT_DIR/etc/hosts | |
cp /proc/mounts $CHROOT_DIR/etc/mtab | |
echo "auto lo | |
iface lo inet loopback | |
# The primary network interface | |
allow-hotplug eth0 | |
iface eth0 inet static | |
address $IP4_GUEST | |
gateway $IP4_HOST | |
netmask 255.255.255.255 | |
dns-nameservers $IP4_HOST | |
pointopoint $IP4_HOST | |
iface eth0 inet6 static | |
address $IP6_GUEST | |
netmask 80 | |
gateway $IP6_HOST | |
dns-nameservers $IP6_HOST | |
" > $CHROOT_DIR/etc/network/interfaces | |
chroot $CHROOT_DIR /bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment