├── .gitignore ├── config ├── isolinux.cfg └── preseed.cfg ├── scripts ├── utils.sh ├── poststrap.sh └── bootstrap.sh ├── LICENSE.md ├── README.md └── vagrant-debian /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | test/ 3 | 4 | .DS_Store 5 | 6 | *.box 7 | *.iso 8 | -------------------------------------------------------------------------------- /config/isolinux.cfg: -------------------------------------------------------------------------------- 1 | default unattended 2 | prompt 0 3 | timeout 0 4 | label unattended 5 | kernel /install/vmlinuz 6 | append vga=788 initrd=/install/initrd.gz quiet -- 7 | -------------------------------------------------------------------------------- /scripts/utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | txtblk=$'\e[0;30m' # Black - Regular 4 | txtred=$'\e[0;31m' # Red 5 | txtgrn=$'\e[0;32m' # Green 6 | txtylw=$'\e[0;33m' # Yellow 7 | txtblu=$'\e[0;34m' # Blue 8 | txtpur=$'\e[0;35m' # Purple 9 | txtcyn=$'\e[0;36m' # Cyan 10 | txtwht=$'\e[0;37m' # White 11 | txtrst=$'\e[0m' # Text Reset 12 | 13 | function abort { 14 | echo -e >&2 "${txtred}ERROR: $1${txtrst}" 15 | exit 1 16 | } 17 | 18 | function info { 19 | echo -e "${txtpur}INFO: $1${txtrst}" 20 | } 21 | 22 | function warn { 23 | echo -e "${txtylw}WARN: $1${txtrst}" 24 | } 25 | -------------------------------------------------------------------------------- /scripts/poststrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | dd if=/dev/zero of=/swapfile1 bs=1024 count=1024000 4 | mkswap /swapfile1 5 | swapon /swapfile1 6 | echo "/swapfile1 none swap sw 0 0" >> /etc/fstab 7 | 8 | apt-get install -y linux-headers-$(uname -r) 9 | mount /dev/cdrom /media/cdrom 10 | sh /media/cdrom/VBoxLinuxAdditions.run 11 | 12 | mv /etc/rc.local.bak /etc/rc.local 13 | 14 | # Oldstable 15 | if [ -x /sbin/shudown ]; then 16 | /sbin/shutdown -h now 17 | fi 18 | 19 | # Stable + 20 | if [ -x /bin/systemctl ]; then 21 | /bin/systemctl poweroff 22 | fi 23 | 24 | # Otherwise shutdown the machine manually 25 | -------------------------------------------------------------------------------- /scripts/bootstrap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # No password for sudo 4 | echo "%sudo ALL = NOPASSWD: ALL" >> /etc/sudoers 5 | 6 | # Public SSH key for vagrant user 7 | mkdir /home/vagrant/.ssh 8 | curl -s "https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub" -o /home/vagrant/.ssh/authorized_keys 9 | chmod 700 /home/vagrant/.ssh 10 | chmod 600 /home/vagrant/.ssh/authorized_keys 11 | chown -R vagrant:vagrant /home/vagrant/.ssh 12 | 13 | # Install ohai gem until CHEF-3778 is fixed 14 | gem install ohai 15 | gem install chef 16 | 17 | # Install guest additions on next boot 18 | # There is no /etc/rc.local in Debian Stretch 19 | if [ -f /etc/rc.local ]; then 20 | cp /etc/rc.{local,local.bak} 21 | fi 22 | cp /root/poststrap.sh /etc/rc.local 23 | 24 | # Wait for disk 25 | sync 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Carl Johan Crafoord, Benson Wong, William Tisäter 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Debian for Vagrant 2 | 3 | Tool for downloading and preseeding the latest versions of Debian. 4 | You can set version to *stable*, *testing* or a specific version like *6.0.10*. 5 | It will download the network installer, install Debian using a preseed 6 | config, install guest additions and export it to the Vagrant box format. 7 | 8 | ## macOS Guide 9 | 10 | Install [Vagrant](http://www.vagrantup.com/downloads.html) and 11 | [VirtualBox](https://www.virtualbox.org/wiki/Downloads). 12 | 13 | brew install fakeroot dvdrtools p7zip 14 | ./vagrant-debian 64 15 | 16 | ## Debian Stretch Guide 17 | 18 | Follow the [Virtualbox Debian wiki page](https://wiki.debian.org/VirtualBox). 19 | 20 | apt-get install fakeroot p7zip-full genisoimage vagrant virtualbox-5.1 21 | ./vagrant-debian 64 22 | 23 | ## Debian Jessie Guide 24 | 25 | apt-get install fakeroot p7zip-full genisoimage vagrant virtualbox virtualbox-guest-additions-iso 26 | ./vagrant-debian 64 27 | 28 | ## Arch Guide 29 | 30 | pacman -S base-devel p7zip cdrkit vagrant virtualbox virtualbox-guest-iso 31 | ./vagrant-debian 64 32 | 33 | ## Old and testing releases 34 | 35 | You can also build images for squeeze and testing using any of following commands: 36 | 37 | ./vagrant-debian 64 7.8.0 38 | 39 | or 40 | 41 | ./vagrant-debian 64 testing 42 | 43 | Forked off [joneskoo/vagrant-debian-squeeze-32](https://github.com/joneskoo/vagrant-debian-squeeze-32) 44 | -------------------------------------------------------------------------------- /config/preseed.cfg: -------------------------------------------------------------------------------- 1 | d-i debian-installer/locale string en_US 2 | d-i debian-installer/language string en 3 | d-i debian-installer/country string US 4 | d-i debian-installer/locale string en_US.UTF-8 5 | d-i debian-installer/exit/poweroff boolean true 6 | 7 | d-i console-tools/archs select at 8 | d-i console-keymaps-at/keymap select us 9 | 10 | d-i keyboard-configuration/xkb-keymap select us 11 | 12 | d-i netcfg/choose_interface select auto 13 | d-i netcfg/get_hostname string vagrant-debian 14 | d-i netcfg/get_domain string vagrantup.com 15 | d-i netcfg/wireless_wep string 16 | 17 | d-i hw-detect/load_firmware boolean true 18 | 19 | d-i mirror/country string manual 20 | d-i mirror/http/hostname string ftp.debian.org 21 | d-i mirror/http/directory string /debian 22 | d-i mirror/http/proxy string 23 | d-i mirror/suite string wheezy 24 | 25 | d-i passwd/root-login boolean true 26 | d-i passwd/make-user boolean true 27 | d-i passwd/root-password password vagrant 28 | d-i passwd/root-password-again password vagrant 29 | d-i passwd/user-fullname string Vagrant 30 | d-i passwd/username string vagrant 31 | d-i passwd/user-password password vagrant 32 | d-i passwd/user-password-again password vagrant 33 | d-i passwd/user-default-groups string audio cdrom video sudo 34 | 35 | d-i time/zone string UTC 36 | d-i clock-setup/ntp boolean true 37 | d-i clock-setup/utc boolean true 38 | 39 | d-i partman-auto/method string regular 40 | d-i partman-auto/choose_recipe select atomic 41 | d-i partman-partitioning/confirm_write_new_label boolean true 42 | d-i partman/choose_partition select finish 43 | d-i partman/confirm boolean true 44 | d-i partman/confirm_nooverwrite boolean true 45 | 46 | d-i apt-setup/cdrom/set-first boolean false 47 | d-i apt-setup/cdrom/set-next boolean false 48 | d-i apt-setup/cdrom/set-failed boolean false 49 | d-i apt-setup/services-select multiselect security, volatile 50 | d-i apt-setup/security_host string security.debian.org 51 | d-i apt-setup/volatile_host string volatile.debian.org 52 | 53 | d-i pkgsel/language-pack-patterns string 54 | d-i pkgsel/install-language-support boolean false 55 | d-i pkgsel/upgrade select safe-upgrade 56 | d-i pkgsel/include string build-essential ruby ruby-dev rubygems openssh-server ca-certificates puppet sudo less screen vim curl lsb-release dkms 57 | 58 | d-i preseed/early_command string rm /usr/lib/pre-pkgsel.d/20install-hwpackages 59 | d-i preseed/late_command string cp /cdrom/bootstrap.sh /cdrom/poststrap.sh /target/root/ && in-target /root/bootstrap.sh 60 | 61 | d-i finish-install/reboot_in_progress note 62 | d-i finish-install/keep-consoles boolean true 63 | 64 | d-i grub-installer/only_debian boolean true 65 | d-i base-installer/install-recommends boolean true 66 | d-i grub-installer/bootdev string /dev/sda 67 | 68 | tasksel tasksel/first multiselect 69 | popularity-contest popularity-contest/participate boolean false 70 | -------------------------------------------------------------------------------- /vagrant-debian: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | . scripts/utils.sh 5 | 6 | function usage { 7 | echo "usage: $0 <32|64> [stable|testing|{x.y.z}]" 8 | echo " where {x.y.z} is a valid Debian version (e.g. 7.8.0)" 9 | exit 10 | } 11 | 12 | function get-current-debian-version { 13 | PAGE=$(curl -s https://www.debian.org/CD/netinst/) 14 | if [[ $PAGE =~ \ /dev/null; do 124 | sleep 10 125 | done 126 | } 127 | 128 | function download_iso { 129 | if [ ! -f "${DEBIAN_ISO_FILE}" ]; then 130 | info "Downloading ${DEBIAN_ISO_NAME} from ${DEBIAN_ISO_URL} ..." 131 | if ! curl --progress-bar --output "${DEBIAN_ISO_FILE}" \ 132 | --location "${DEBIAN_ISO_URL}" --fail 133 | then 134 | abort "Download failed. Maybe the requested version doesn't exist?" 135 | fi 136 | fi 137 | } 138 | 139 | function customize_iso { 140 | info "Unpacking ${DEBIAN_ISO_NAME}..." 141 | 7z x "${DEBIAN_ISO_FILE}" -o"${FOLDER_BUILD}/custom" > /dev/null 142 | 143 | info "Grant write permission..." 144 | chmod -R u+w "${FOLDER_BUILD}/custom" 145 | 146 | info "Customizing ISO files..." 147 | FOLDER_INSTALL=$(ls -1 -d "${FOLDER_BUILD}/custom/install."* | sed 's/^.*\///') 148 | cp -r "${FOLDER_BUILD}/custom/${FOLDER_INSTALL}/"* "${FOLDER_BUILD}/custom/install/" 149 | 150 | pushd "${FOLDER_BUILD}/initrd" 151 | gunzip -c "${FOLDER_BUILD}/custom/install/initrd.gz" | $(which fakeroot) cpio -id 152 | cp "${FOLDER_BASE}/config/preseed.cfg" "${FOLDER_BUILD}/initrd/preseed.cfg" 153 | find . | $(which fakeroot) cpio --create --format='newc' | gzip > "${FOLDER_BUILD}/custom/install/initrd.gz" 154 | popd 155 | 156 | cp "${FOLDER_BASE}/scripts/poststrap.sh" "${FOLDER_BUILD}/custom/" 157 | cp "${FOLDER_BASE}/scripts/bootstrap.sh" "${FOLDER_BUILD}/custom/" 158 | cp "${FOLDER_BASE}/config/isolinux.cfg" "${FOLDER_BUILD}/custom/isolinux/" 159 | 160 | info "Setting permissions on bootstrap scripts..." 161 | chmod 755 "${FOLDER_BUILD}/custom/poststrap.sh" 162 | chmod 755 "${FOLDER_BUILD}/custom/bootstrap.sh" 163 | 164 | info "Packing ISO files..." 165 | MKISOFS=$(which mkisofs || which genisoimage) 166 | $MKISOFS -r -V "Custom Debian Install CD" -cache-inodes -quiet -J -l \ 167 | -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot \ 168 | -boot-load-size 4 -boot-info-table -o "${FOLDER_BUILD}/custom.iso" \ 169 | "${FOLDER_BUILD}/custom" 170 | } 171 | 172 | function vbox_unregister { 173 | if VBoxManage showvminfo "${BOX}" >/dev/null 2>/dev/null; then 174 | read -p "${txtred}Are you sure you want to destroy ${BOX}? ${txtrst}" 175 | if [ "$REPLY" == "y" ]; then 176 | VBoxManage unregistervm "${BOX}" --delete > /dev/null 177 | if [ $? -ne 0 ]; then 178 | abort "Failed to destroy ${BOX}. Aborting." 179 | fi 180 | else 181 | abort "VM ${BOX} already exist. Aborting." 182 | fi 183 | fi 184 | } 185 | 186 | function vbox_create_vm { 187 | info "Creating VM..." 188 | VBoxManage createvm --name "${BOX}" --ostype $OS_TYPE --register --basefolder "${FOLDER_VBOX}" 189 | VBoxManage modifyvm "${BOX}" --memory 360 --boot1 dvd --boot2 disk --boot3 none --boot4 none --vram 12 --pae off --rtcuseutc on 190 | } 191 | 192 | function vbox_create_storage { 193 | info "Creating storage devices..." 194 | VBoxManage storagectl "${BOX}" --name "IDE Controller" --add ide --controller PIIX4 --hostiocache on 195 | VBoxManage storagectl "${BOX}" --name "SATA Controller" --add sata --controller IntelAhci --portcount 1 --hostiocache off 196 | VBoxManage createhd --filename "${FOLDER_VBOX}/${BOX}/${BOX}.vdi" --size 40960 197 | VBoxManage storageattach "${BOX}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "${FOLDER_VBOX}/${BOX}/${BOX}.vdi" 198 | VBoxManage storageattach "${BOX}" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "${FOLDER_BUILD}/custom.iso" 199 | } 200 | 201 | function vbox_start_and_wait_for_shutdown { 202 | info "Booting VM..." 203 | VBoxManage startvm "${BOX}" 204 | wait_for_shutdown 205 | } 206 | 207 | function vbox_mount_guestadditions { 208 | info "Installing guest additions..." 209 | if [ -f $VBGA_DEBIAN_PATH ]; then 210 | VBOX_GUESTADDITIONS=$VBGA_DEBIAN_PATH 211 | elif [ -f $VBGA_ARCH_PATH ]; then 212 | VBOX_GUESTADDITIONS=$VBGA_ARCH_PATH 213 | else 214 | VBOX_GUESTADDITIONS=$VBGA_DARWIN_PATH 215 | fi 216 | VBoxManage storageattach "${BOX}" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "${VBOX_GUESTADDITIONS}" 217 | } 218 | 219 | function vagrant_package { 220 | info "Building Vagrant box..." 221 | vagrant package --base "${BOX}" --output "${BOX}.box" 222 | } 223 | 224 | ############################################################################### 225 | 226 | clean 227 | 228 | dep_vagrant 229 | dep_virtualbox 230 | dep_7z 231 | dep_mkisofs 232 | 233 | vbox_unregister 234 | 235 | download_iso 236 | customize_iso 237 | 238 | vbox_create_vm 239 | vbox_create_storage 240 | vbox_start_and_wait_for_shutdown 241 | 242 | vbox_mount_guestadditions 243 | vbox_start_and_wait_for_shutdown 244 | 245 | vagrant_package 246 | --------------------------------------------------------------------------------