Created
January 7, 2016 17:04
-
-
Save dasjoe/09ecf8190c523bf7a7dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# apt-add-repository ppa:zfs-native/stable | |
# apt-get update | |
# apt-get install ubuntu-zfs | |
# apt-get install debootstrap | |
HOST=vm1 | |
DISKS="/dev/disk/by-id/ata-Samsung_SSD_850_EVO_120GB_S21UNSAG310692M" | |
zpool create \ | |
-f \ | |
-d \ | |
-o ashift=13 \ | |
-o feature@async_destroy=enabled \ | |
-o feature@empty_bpobj=enabled \ | |
-o feature@lz4_compress=enabled \ | |
-o feature@spacemap_histogram=enabled \ | |
-o feature@enabled_txg=enabled \ | |
-O normalization=formD \ | |
-O atime=off \ | |
-O canmount=off \ | |
-O compression=lz4 \ | |
-O mountpoint=/ \ | |
-R /mnt \ | |
"$HOST"-rpool \ | |
"$DISKS" | |
zfs set sync=disabled "$HOST"-rpool | |
zfs create -o canmount=off -o mountpoint=none "$HOST"-rpool/ROOT | |
zfs create -o canmount=noauto -o mountpoint=/ "$HOST"-rpool/ROOT/trusty | |
zfs mount "$HOST"-rpool/ROOT/trusty | |
zpool set bootfs="$HOST"-rpool/ROOT/trusty "$HOST"-rpool | |
for disk in $DISKS; do | |
parted -s "$disk" mkpart GRUB2 48s 2047s | |
parted -s $disk set 2 bios_grub on | |
done | |
debootstrap trusty /mnt | |
cat > /mnt/etc/hosts << EOF | |
127.0.0.1 localhost | |
127.0.1.1 $HOST | |
::1 ip6-localhost ip6-loopback | |
fe00::0 ip6-localnet | |
ff00::0 ip6-mcastprefix | |
ff02::1 ip6-allnodes | |
ff02::2 ip6-allrouters | |
ff02::3 ip6-allhosts | |
EOF | |
for if in eth0 eth1 eth2 eth3; do | |
cat > /mnt/etc/network/interfaces.d/$if << EOF | |
allow-hotplug $if | |
iface $if inet dhcp | |
EOF | |
done | |
echo "$HOST" > /mnt/etc/hostname | |
cat > /mnt/etc/udev/rules.d/70-zfs-grub-fix.rules << 'EOF' | |
KERNEL=="sd*[a-z]1|cciss*[a-z]1", ENV{DEVTYPE}=="partition", ENV{ID_SERIAL}=="?*", SYMLINK+="$env{ID_BUS}-$env{ID_SERIAL}" | |
EOF | |
cat > /mnt/etc/default/grub << EOF | |
GRUB_DEFAULT=0 | |
GRUB_HIDDEN_TIMEOUT_QUIET=true | |
GRUB_TIMEOUT=5 | |
GRUB_DISTRIBUTOR=\`lsb_release -i -s 2> /dev/null || echo Debian\` | |
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" | |
GRUB_CMDLINE_LINUX="boot=zfs rpool=$HOST-rpool" | |
EOF | |
cat > /mnt/etc/apt/sources.list << EOF | |
deb http://de.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse | |
deb http://de.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse | |
deb http://de.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse | |
deb http://de.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse | |
EOF | |
cat > /mnt/etc/apt/apt.conf.d/01norecommend << EOF | |
APT::Install-Recommends "0"; | |
APT::Install-Suggests "0"; | |
EOF | |
cat > /mnt/etc/resolv.conf << EOF | |
nameserver 192.168.188.1 | |
search fritz.box | |
EOF | |
echo "Europe/Berlin" > /mnt/etc/timezone | |
for disk in /dev/disk/by-id/ata*-part1; do ln -s $disk /dev/$(echo $disk | sed 's,.*/\(.*\)-part1,\1,g'); done | |
for f in /sys /proc /dev; do mount --rbind $f /mnt/$f; done | |
cat > /mnt/root/install-chroot.sh << __EOF__ | |
for locale in en_US.UTF-8 de_DE.UTF-8; do locale-gen \$locale; done | |
grep -v rootfs /proc/mounts > /etc/mtab | |
dpkg-reconfigure -f noninteractive tzdata | |
apt-get update | |
apt-get --yes dist-upgrade | |
apt-get install --yes linux-generic-lts-wily build-essential tasksel software-properties-common | |
for task in server openssh-server virt-host; do tasksel install \$task; done | |
apt-add-repository --yes ppa:zfs-native/stable | |
apt-get update | |
apt-get --yes dist-upgrade | |
apt-get install --yes ubuntu-zfs | |
apt-get install --yes zfs-initramfs | |
adduser --disabled-password --gecos "" username | |
usermod -a -G adm,sudo username | |
echo "username:password" | chpasswd | |
apt-get install --yes htop | |
DEBIAN_FRONTEND=noninteractive apt-get --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install grub-pc | |
for disk in $DISKS; do | |
grub-install \$disk | |
done | |
update-grub | |
__EOF__ | |
chroot /mnt /bin/bash -x /root/install-chroot.sh | |
umount /mnt/proc | |
umount /mnt/sys/fs/fuse/connections | |
umount /mnt/sys/kernel/* | |
umount /mnt/sys/fs/cgroup/* | |
umount /mnt/sys/fs/cgroup | |
umount /mnt/sys/fs/pstore | |
umount /mnt/sys | |
umount /mnt/dev/pts | |
umount /mnt/dev | |
umount /mnt/tmp | |
umount /mnt | |
zfs inherit sync "$HOST"-rpool | |
zfs snapshot "$HOST"-rpool/ROOT/trusty@installed | |
zpool export "$HOST"-rpool |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment