Skip to content

Instantly share code, notes, and snippets.

@mislav
Last active January 11, 2022 11:33
Show Gist options
  • Save mislav/de29f665bb0eae38fdd3 to your computer and use it in GitHub Desktop.
Save mislav/de29f665bb0eae38fdd3 to your computer and use it in GitHub Desktop.
How to create a base Vagrant box using VirtualBox

Create the partition:

sgdisk --zap-all /dev/sda
cgdisk /dev/sda
mkfs.ext4 /dev/sda1
mount /dev/sda1 /mnt

Edit the mirror list to bring the preferred mirror to the top:

vi /etc/pacman.d/mirrorlist

Install the base system

pacstrap /mnt base base-devel

Generate an fstab

genfstab -U -p /mnt >> /mnt/etc/fstab
vi /mnt/etc/fstab

Chroot into the new system

arch-chroot /mnt /bin/bash

Set hostname

echo arch > /etc/hostname

Set root password to "vagrant"

passwd

Set up DHCP

systemctl enable dhcpcd@enp0s3.service

Create "vagrant" user

useradd -G wheel -m vagrant
passwd vagrant

Setup bootloader

pacman -S gptfdisk syslinux
syslinux-install_update -iam

Edit boot configuration in /boot/syslinux/syslinux.cfg:

LABEL arch
    ...
    APPEND root=/dev/sda1 rw

Setup ssh:

pacman -S openssh rsync
systemctl enable sshd.service

Edit /etc/ssh/sshd_config

UseDNS no

Clean package cache

pacman -Sc

exit chroot environment and reboot.

Set hostname:

hostname centos65

Edit /etc/sysconfig/network-scripts/ifcfg-eth0

ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=dhcp

Edit /etc/ssh/sshd_config

UseDNS no

Add "vagrant" user:

useradd -G wheel vagrant

Enable passwordless sudo using visudo

%wheel  ALL=(ALL)  ALL
%wheel  ALL=(ALL)  NOPASSWD: ALL

# Defaults  requiretty

Restart the VM:

shutdown -r now

Install Vagrant's SSH key:

su - vagrant
mkdir -p .ssh
curl -kL https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub > .ssh/authorized_keys
chmod -R go-rwx .ssh
exit

Install basic provisioning tools, rsync & scp:

yum install rsync openssh-clients
yum clean all

Halt the VM:

shutdown -h now

Build base box:

vagrant package --output centos65.box --base "CentOS 6.5"

(Setting up VirtualBox guest additions + Google Chrome, not preparing for Vagrant.)

Click on “Install Guest Additions…” from the VirtualBox Devices menu, then:

sudo su
apt-get update
apt-get install build-essential module-assistant
m-a prepare
sh /media/cdrom/VBoxLinuxAdditions.run
reboot

To install Google Chrome:

sudo vi /etc/apt/sources.list.d/google-chrome.list 

Add these contents:

deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main

Then:

sudo apt-get update

If it fails with the message that a public key is missing for some key IDs, obtain those signatures with:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <KEY>

Finally:

sudo apt-get install google-chrome-stable

To boot Fedora into text-only mode:

  1. Press "e" at the boot menu,
  2. Arrow down to the line that starts with "linux",
  3. Replace last two words with text 3.
  4. Ctrl+X.

Edit /etc/ssh/sshd_config

UseDNS no

Enable passwordless sudo using visudo

%wheel  ALL=(ALL)  ALL
%wheel  ALL=(ALL)  NOPASSWD: ALL

# Defaults  requiretty

Install rsync:

yum install -y rsync
yum clean all

Edit /etc/ssh/sshd_config

UseDNS no

Install essential packages:

pkg install -y sudo bash rsync curl

Enable passwordless sudo using visudo

%wheel  ALL=(ALL)  ALL
%wheel  ALL=(ALL)  NOPASSWD: ALL

Add "vagrant" user:

adduser -G wheel
chsh -s bash vagrant

Install Vagrant's SSH key:

su - vagrant
mkdir -p .ssh
curl -kL https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub >> .ssh/authorized_keys
chmod -R go-rwx .ssh
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment