Last active
October 4, 2016 22:22
-
-
Save lpenz/35a60d560888ae0d74b714506f73c53d to your computer and use it in GitHub Desktop.
Use debootstrap to create a chroot that can be turned into a vagrant-compatible (virtualbox, wheezy 32) VM
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 | |
DIR=${1?usage: $0 <dir>} | |
NAME=${DIR##*/} | |
set -e -x | |
rm -rf "$DIR" | |
trap 'set +e; umount "$DIR/proc"; umount "$DIR/sys"; rm -rf "$DIR"' EXIT INT | |
debootstrap --variant=minbase --arch=i386 --include=linux-image-686-pae,extlinux,acpi-support-base,isc-dhcp-client,sudo,openssh-server,ifupdown,virtualbox-guest-utils wheezy "$DIR" http://ftp.us.debian.org/debian | |
cat > "$DIR"/boot/syslinux.cfg <<END | |
DEFAULT linux | |
LABEL linux | |
KERNEL /boot/vmlinuz-3.2.0-4-686-pae | |
INITRD /boot/initrd.img-3.2.0-4-686-pae | |
APPEND ro root=/dev/sda1 | |
END | |
echo "$NAME" > "$DIR/etc/hostname" | |
chroot "$DIR" /bin/sh -c ' | |
set -e -x | |
: basic config | |
echo "UseDNS no" >> /etc/ssh/sshd_config | |
echo "auto eth0" >> /etc/network/interfaces | |
echo "iface eth0 inet dhcp" >> /etc/network/interfaces | |
: vagrant user setup | |
adduser --disabled-password --gecos "" vagrant | |
mkdir -m 0700 /home/vagrant/.ssh | |
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys | |
chmod 0600 /home/vagrant/.ssh/authorized_keys | |
chown -R vagrant:vagrant /home/vagrant | |
: root and sudo setup | |
echo "vagrant:vagrant" | chpasswd | |
echo "root:vagrant" | chpasswd | |
echo "vagrant ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/10_vagrant | |
chmod 0400 /etc/sudoers.d/10_vagrant | |
' | |
trap '' EXIT INT | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment