Skip to content

Instantly share code, notes, and snippets.

@jl
Last active April 22, 2019 03:22
Show Gist options
  • Save jl/c05a556e4bab562ad82d to your computer and use it in GitHub Desktop.
Save jl/c05a556e4bab562ad82d to your computer and use it in GitHub Desktop.
How to setup a CentOS 7 vagrant base box

Mac OS X

  • install virtualbox
  • install vagrant
  • download CentOS 7 minimal ISO
  • create a new virtualbox instance "centos7base"
    • 512 mb ram
    • VDI, dynamically allocated, 8 gb
    • disable USB and audio controllers
    • insert the centos 7 iso into the virtual drive
  • start "centos7base"
    • activate nic in network (turn on)
    • activate ntp in date/time (turn on switch, upper-right)
    • click begin installation
    • set root password vagrant
    • add user vagrant password vagrant
    • reboot after installation completes
  • login as root
    • $ visudo
      • append line: vagrant ALL=(ALL) NOPASSWD: ALL
      • remove line: Defaults requiretty
    • exit
  • login as vagrant
    • authorize vagrant insecure key pair for ssh
$ mkdir -m 700 .ssh
$ curl -o authorized_keys https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub
$ chmod 600 authorized_keys
  • make sshd nicer when no internet
    • $ sudo vi /etc/ssh/sshd_config
    • insert line: UseDNS no
  • install updates
    • $ sudo yum -y upgrade && sudo reboot
  • install EPEL repository
    • $ sudo rpm -Uvh http://mirror.steadfast.net/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm
  • install virtualbox guest additions
    • insert the virtualbox linux additions cd
### in guest
$ sudo yum -y install kernel-devel dkms bzip2 && sudo reboot
$ sudo mkdir -m 000 /mnt/cdrom
$ sudo mount /dev/cdrom /mnt/cdrom
$ cd /mnt/cdrom
$ sudo sh VBoxLinuxAdditions.run
$ sudo shutdown -h now
  • now package the box from the host
### on host
$ vagrant package --base centos7base
### if you want to test it locally
$ vagrant box add package.box --name centos7base
@denisinla
Copy link

Why not a bash script that you can provision directly from the Vagrantfile?

@dicatalin
Copy link

For installing Virtual Box Guest additions you need compiler. In Centos 7 minimal i don't have any compiler installed so i just run
$sudo yum groupinstall 'Development Tools'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment