Skip to content

Creating An openSUSE 11.3 x32 Vagrant Box

fnichol edited this page Jan 31, 2011 · 10 revisions

Create New Virtual Machine

Customize Virtual Machine Settings

Preparing For First Boot

Installing openSUSE Operating System

Operating System Setup Preparation

Take A Snapshot (Optional)

Once the installation is complete, it should reboot and come up running the operating system. Login as the vagrant user and shut it down:

sudo /sbin/shutdown -hP now && exit

You might want to take a sanity snapshot backup at this point in case things go sideways. I've used a snapshot called "First boot". Now, power it back up and login with the vagrant user.

Update Sudoers

Login as the vagrant user. First let's fix up the sudoers file to remove password prompts:

sudo /usr/sbin/visudo

After these lines:

# User privilege specification
root    ALL=(ALL) ALL

Add this:

vagrant ALL=(ALL) NOPASSWD: ALL

Save and exit.

Change Hostname

Updating the hostname has 3 steps. First update /etc/HOSTNAME:

sudo bash -c "echo 'vagrant-opensuse-11_3x32' > /etc/HOSTNAME"

Then change the last line of /etc/hosts (the one starting with "127.0.0.2") to:

127.0.0.2             vagrant-opensuse-11_3x32.site vagrant-opensuse-11_3x32

Finally use hostname to set it until next reboot:

sudo hostname vagrant-opensuse-11_3x32

Now logout and log back in as the vagrant user.

Fix openSUSE VirtualBox Cloning Issues

openSUSE uses your device ID by default when it refers to its hard disks. Unfortunetly when VirtualBox clones a new machine these values update and you get a nasty "Waiting for device /dev/disk/by-id/...-part2" error. To fix this, we'll update fstab and menu.lst to reference by classic /dev/sda* device identifiers.

Edit /etc/fstab to replace this:

/dev/disk/by-id/ata-VBOX_HARDDISK_VBxxxx-xxxx...-part1 swap                 swap       defaults              0 0
/dev/disk/by-id/ata-VBOX_HARDDISK_VBxxxx-xxxx...-part2 /                    ext4       acl,user_xattr        1 1
/dev/disk/by-id/ata-VBOX_HARDDISK_VBxxxx-xxxx...-part3 /home                ext4       acl,user_xattr        1 2

with this:

/dev/sda1 swap                 swap       defaults              0 0
/dev/sda2 /                    ext4       acl,user_xattr        1 1
/dev/sda3 /home                ext4       acl,user_xattr        1 2

Similarily, edit /boot/grub/menu.lst to replace this (↵ character shows code continuing on one line but split for display on page):

    kernel /boot/vmlinuz-2.6.34.7-0.7-default ↵
root=/dev/disk/by-id/ata-VBOX_HARDDISK_VBxxxx-xxx-part2 ↵
resume=/dev/disk/by-id/ata-VBOX_HARDDISK_VBxxxx-xxx-part1 ↵
splash=silent quiet showopts vga=0x314

with this:

    kernel /boot/vmlinuz-2.6.34.7-0.7-default ↵
root=/dev/sda2 resume=/dev/sda1 ↵
splash=silent quiet showopts vga=0x314

The second issue is that openSUSE identifies the network card by its MAC address by default which also gets changed on a clone. To fix, we'll dive into the yast interface:

sudo /sbin/yast
  1. Choose the Network Devices menu
  2. Choose the Network Settings submenu
  3. Select the 82540EM Gigabit Ethernet Controller (should be the only device) and choose Edit
  4. Choose the Hardware tab
  5. In the Udev rules section choose Change
  6. Choose BusID from the menu and choose OK
  7. Choose Next back out in the Network Settings page
  8. Choose OK
  9. Choose Quit

Big thanks to Ján Kupec for his blog post which saved me from the agonizing confusion.

Update System Packages

Now update the system and reboot.

sudo zypper --non-interactive refresh
sudo zypper --non-interactive up
sudo /sbin/shutdown -r now && exit

Install VirtualBox Guest Additions

Install some pre-requisites needed for the Guest Additions package and remove the system-installed package:

sudo zypper --non-interactive install make gcc
sudo zypper --non-interactive install kernel-default-devel
sudo zypper --non-interactive remove virtualbox-ose-guest-kmp-default \
  virtualbox-ose-guest-tools xorg-x11-driver-virtualbox-ose

Now mount the Guest Additions from the Devices -> Install Guest Additions VirtualBox menu. Next, mount the iso and install the additions:

sudo mkdir -p /media/cdrom
sudo mount /dev/cdrom /media/cdrom
(cd /media/cdrom && sudo sh VBoxLinuxAdditions.run)
sudo umount /media/cdrom

Note: The installer will complain about not finding "the X.Org or XFree86 Window System" which is fine and expected.

Remove the disk from the virtual drive by clicking the CD-ROM icon and choosing from the flyout menu.

Prepare SSH Configuration

Install the public key that Vagrant uses when SSHing into the virtual machine:

sudo zypper --non-interactive install curl
mkdir -p ~/.ssh
chmod 0700 ~/.ssh
curl -o ~/.ssh/authorized_keys \
  https://github.com/mitchellh/vagrant/raw/master/keys/vagrant.pub
chmod 0600 ~/.ssh/authorized_keys 

Edit the sshd configuration to prevent DNS resolution (speedup logins):

sudo bash -c "echo 'UseDNS no' >> /etc/ssh/sshd_config"

Install Ruby, Chef, And Puppet

Thankfully, openSUSE comes with a decently up to date ruby (1.8.7) and a non-crippled rubygems (currently 1.3.7), so this is straight forward:

sudo zypper --non-interactive install ruby ruby-devel rubygems

Install the chef and puppet gems so they are ready for the provisioners:

sudo gem install chef --no-ri --no-rdoc
sudo gem install puppet --no-ri --no-rdoc

Update Message Of The Day

Modify the message of the day (to match the default Vagrant box):

sudo bash -c "echo 'Welcome to your Vagrant-built virtual machine.' > /etc/motd"

Final Cleanup

Run one last update and cleanup:

sudo zypper --non-interactive refresh
sudo zypper --non-interactive up

Finally, shutdown the virtual machine:

sudo /sbin/shutdown -hP now && exit

Now is a good time to kill off any temporary snapshots taken on the virtual machine.

Package and Distribute

Follow the instructions on the Vagrant website to package up the box. From your workstation:

mkdir -p ~/vagrant_box_opensuse11.3x32
(cd ~/vagrant_box_opensuse11.3x32 && vagrant package --base opensuse11.3x32)
mv ~/vagrant_box_opensuse11.3x32/package.box ~/vagrant_box_opensuse11.3x32/opensuse11.3x32.box

Now take ~/vagrant_box_opensuse11.3x32/opensuse11.3x32.box and store on a network drive or share on a web server (whatever your distribution requirements dictate).

Resources