Creating Solaris 11 VMs with Vagrant

Currently i’m working on updating the Solaris Cheatsheet to 11.4. As i’m testing the entries with each update, i need a lot of VMs created and destroyed. So the idea to automate the creation of them is quite obvious. I would like to demonstrate how this works with Vagrant.

Step 0: Install a Solaris 11.4 into an Oracle VM.

I’m using this VM as a golden master. I have named it “Solaris 11 master” in my example. If you use a different name you have to substitute each appearance of “Solaris 11 master” with your name. Install everything you want in there. Install SRUs, keys and certs for SRU and configure your repositories.

Everything i’m doing now will be relative to my working directory.

>cd /Users/joerg/cheatsheet/

Step 1: Create vagrant user on a golden master

Vagrant needs a user on the system to do it’s magic. You have to create a user vagrant. The password doesn’t really matter for vagrant as it using passwordless ssh.

joerg@MBPvonc0t0d0s0 cheatsheet % ssh jmoekamp@192.168.30.227
Password: 
Last login: Tue May 19 03:29:56 2020 on console
Oracle Corporation   SunOS 5.11   11.4  March 2020
jmoekamp@master:~$ ls
jmoekamp@master:~$ su root
Password: 
root@master:~# useradd -m vagrant
80 blocks
root@master:~# passwd vagrant
New Password: 
Re-enter new Password: 
passwd: password successfully changed for vagrant
root@master:~# exit
jmoekamp@master:~$ exit

Add the vagrant user to sudo for passwordless sudo

 echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant

Step 2: Create ssh keys

Now you have to create the SSH key vagrant will use. Please ensure that you don’t overwrite you normal key and write the key in /Users/joerg/cheatsheet/key

joerg@MBPvonc0t0d0s0 cheatsheet % cd /Users/joerg/cheatsheet/keys
joerg@MBPvonc0t0d0s0 keys % ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/joerg/.ssh/id_rsa): <strong>vagrantkey</strong>   
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in vagrantkey.
Your public key has been saved in vagrantkey.pub.
The key fingerprint is:
SHA256:u9xNRHBePNVhKt0UIl03rtqAYqf0UvnQrzskeEjEid4 joerg@MBPvonc0t0d0s0
The key's randomart image is:
+---[RSA 3072]----+
|   o . ..oooO*|
|   . +  +ooX +|
|  . o  .oo + |
|   . E +.. . |
|   .+S* o..  |
|   oo*+oo=  |
|    oo.oo.o  |
|    ..o +.  |
|    o .o+  |
+----[SHA256]-----+
joerg@MBPvonc0t0d0s0 keys % ls
vagrantkey	vagrantkey.pub
joerg@MBPvonc0t0d0s0 keys % ssh-copy-id -i vagrantkey vagrant@192.168.30.227
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "vagrantkey.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Password: 
Number of key(s) added:    1
Now try logging into the machine, with:  "ssh 'vagrant@192.168.30.227'"
and check to make sure that only the key(s) you wanted were added.
joerg@MBPvonc0t0d0s0 keys % ssh -i vagrantkey vagrant@192.168.30.227 
Last login: Tue May 19 03:33:14 2020 from 192.168.30.228
Oracle Corporation   SunOS 5.11   11.4  March 2020
vagrant@master:~$ exit
Abgemeldet


Step 3: Install the Guest Additions inside of the golden Master.

Vagrant needs the Virtualbox Guest additions to work. Thus we have to install them into the VM.

joerg@MBPvonc0t0d0s0 keys % ssh -i vagrantkey vagrant@192.168.30.227
Last login: Tue May 19 03:33:30 2020 from 192.168.30.228
Oracle Corporation   SunOS 5.11   11.4  March 2020
vagrant@master:~$ sudo bash
{}
root@master:/export/home/vagrant# cd /media/VBOXADDITIONS_6.1.8_137981/
root@master:/media/VBOXADDITIONS_6.1.8_137981# ls
AUTORUN.INF            runasroot.sh            VBoxSolarisAdditions.pkg
autorun.sh             TRANS.TBL             VBoxWindowsAdditions-amd64.exe
cert                VBoxDarwinAdditions.pkg      VBoxWindowsAdditions-x86.exe
NT3x                VBoxDarwinAdditionsUninstall.tool VBoxWindowsAdditions.exe
OS2                VBoxLinuxAdditions.run
root@master:/media/VBOXADDITIONS_6.1.8_137981# pkgadd -d VBoxSolarisAdditions.pkg 
The following packages are available:
 1 SUNWvboxguest   Oracle VM VirtualBox Guest Additions
            (i386) 6.1.8,REV=r137981.2020.05.14.21.43
Select package(s) you wish to process (or 'all' to process
all packages). (default: all) [?,??,q]: all
Processing package instance <SUNWvboxguest> from </media/VBOXADDITIONS_6.1.8_137981/VBoxSolarisAdditions.pkg>
Oracle VM VirtualBox Guest Additions(i386) 6.1.8,REV=r137981.2020.05.14.21.43
Oracle Corporation
Using </> as the package base directory.
## Processing package information.
## Processing system information.
## Verifying package dependencies.
WARNING:
  The <SUNWuiu8> package "Iconv modules for UTF-8 Locale"
  is a prerequisite package and should be installed.
Do you want to continue with the installation of <SUNWvboxguest> [y,n,?] y
## Verifying disk space requirements.
## Checking for conflicts with packages already installed.
## Checking for setuid/setgid programs.
This package contains scripts which will be executed with super-user
permission during the process of installing this package.
Do you want to continue with the installation of <SUNWvboxguest> [y,n,?] y
Installing Oracle VM VirtualBox Guest Additions as <SUNWvboxguest>
## Installing part 1 of 1.
/etc/fs/vboxfs/mount <symbolic link>
[…]
Configuring VirtualBox guest kernel module...
VirtualBox guest kernel module loaded.
VirtualBox pointer integration module loaded.
Creating links...
(*) X.Org not found, skipped configuring X.Org guest additions.
Installing 64-bit shared folders module...
Installing 32-bit shared folders module...
Configuring services (this might take a while)...
Enabling services...
Updating boot archive...
Done.
If you have just un-installed the previous guest additions a REBOOT is required.
Installation of <SUNWvboxguest> was successful.
root@master:/media/VBOXADDITIONS_6.1.8_137981# halt


Step 4: Create box file and import it to Vagrant

You have to shut down the master completly down before creating the box file. After this please execute the following steps.

joerg@MBPvonc0t0d0s0 keys % cd /Users/joerg/cheatsheet/
joerg@MBPvonc0t0d0s0 cheatsheet % vagrant package --base "Solaris 11 master" --output solaris114.box
==> Solaris 11 master: Exporting VM...
==> Solaris 11 master: Compressing package to: /Users/joerg/cheatsheet/solaris114.box
joerg@MBPvonc0t0d0s0 cheatsheet % vagrant box add solaris114 solaris114.box         
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'solaris114' (v0) for provider: 
  box: Unpacking necessary files from: file:///Users/joerg/cheatsheet/solaris114.box
==> box: Successfully added box 'solaris114' (v0) for 'virtualbox'!

Step 5: Create Vagrant File

We have to initialize an vagrant environment and thus create a vagrant file.

joerg@MBPvonc0t0d0s0 cheatsheet % vagrant init
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

Step 6: Modify vagrant file

Go to the line with config.vm.box and insert the following snippet. The path of the private key must be adapted to the actual location of the key you just creeated

 config.vm.box = "solaris114"
 config.ssh.private_key_path = "/Users/joerg/cheatsheet/keys/vagrantkey"
 config.ssh.insert_key = false

Step 7: Vagrant for fun and profit

joerg@MBPvonc0t0d0s0 cheatsheet % vagrant up                             
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'solaris114'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: cheatsheet_default_1589868970173_17738
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
  default: Adapter 1: nat
==> default: Forwarding ports...
  default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
  default: SSH address: 127.0.0.1:2222
  default: SSH username: vagrant
  default: SSH auth method: private key
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
  default: /vagrant => /Users/joerg/cheatsheet
joerg@MBPvonc0t0d0s0 cheatsheet % vagrant ssh
Last login: Tue May 19 06:17:12 2020 from 10.0.2.2
Oracle Corporation   SunOS 5.11   11.4  March 2020
vagrant@master:~$ exit
Abgemeldet
Connection to 127.0.0.1 closed.
joerg@MBPvonc0t0d0s0 cheatsheet % vagrant halt
==> default: Attempting graceful shutdown of VM...