Vagrant

From Glee
Jump to: navigation, search

Installation

Install VirtualBox first.

https://www.vagrantup.com/downloads.html

yum install ./vagrant_1.6.5_x86_64.rpm

Creating a new Box

Define the VirtualBox VM

Use nictype of 82545EM for the installation because virtio makes the PXE boot take minutes instead of seconds.

# Set Variable for VirtualMachine Name
VM="RHEL-6.4"
# Create VM
VBoxManage createvm --name "${VM}" --ostype "RedHat_64" --register
# Create Disk (256G)
VBoxManage createhd --filename "${VM}.vdi" --size 262144
VBoxManage storagectl "${VM}" --name "SATA Controller" --add sata --controller IntelAHCI
VBoxManage storageattach "${VM}" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "${VM}.vdi"
# Set RAM to 1G
VBoxManage modifyvm "${VM}" --memory 1024 --cpus 2 --boot4 net --nictype1 82545EM
# Enable ssh access from the host
VBoxManage modifyvm "${VM}" --natpf1 "ssh,tcp,,2222,,22"
# Show all details
VBoxManage showvminfo "${VM}"

To see the full configuration of all VMs : VBoxManage list -l vms

Prepare PXE boot

Install syslinux if needed.

# Set Variable for VirtualMachine Name
VM="RHEL-6.4"
mkdir ~/.config/VirtualBox/TFTP/
cd ~/.config/VirtualBox/TFTP/
cp /usr/share/syslinux/pxelinux.0 .
ln -s pxelinux.0 "${VM}.pxe"
mkdir pxelinux.cfg
wget xxx/images/pxeboot/vmlinuz xxx/images/pxeboot/initrd.img
cat > pxelinux.cfg/default << 'EOF'
DEFAULT linux
LABEL linux
IPAPPEND 2
KERNEL vmlinuz
APPEND initrd=initrd.img ksdevice=bootif ks=http://xxx/RHEL-6.4.ks
EOF

Kickstart Specific Content

Usual caveats for creating a generic installation apply. Example kicsktart specific entries (use 'poweroff' or you'll also need to clean the host ssh keys) :

install
text
poweroff
# [...]

%packages
# [...]
# VirtualBox
gcc
kernel-devel
make
%end

%post --logfile /root/ks-post.log
curl -o VBoxLinuxAdditions.run http://xxx/VBoxLinuxAdditions.run
chmod +x VBoxLinuxAdditions.run
./VBoxLinuxAdditions.run
rm -f VBoxLinuxAdditions.run
# Make sure vbox kernel modules will be included during kernel update
mv /lib/modules/`uname -r`/misc/vbox* /lib/modules/`uname -r`/extra/
depmod
# Create special unprivileged user with full sudo access
useradd -g vagrant -c "Vagrant user" vagrant
cat > /etc/sudoers.d/vagrant << 'EOF'
Defaults:vagrant !requiretty
vagrant ALL = (ALL) NOPASSWD: ALL
EOF
chmod 440 /etc/sudoers.d/vagrant
mkdir -p /home/vagrant/.ssh && chmod 700 /home/vagrant/.ssh
echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key" > /home/vagrant/.ssh/authorized_keys
chmod 600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant
restorecon -Rv /home/vagrant/.ssh
# Clean up
rm -f /etc/udev/rules.d/70-persistent-net.rules
sed -i -e '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth*
%end

Install VM

Use the VirtualBox GUI to start the VM and look at the PXE installation progress.

Package Vagrant Box

# Set Variable for VirtualMachine Name
VM="RHEL-6.4"
VBoxManage modifyvm "${VM}" --nictype1 virtio
vagrant package --base "${VM}" --output "${VM}.box"
vagrant box add "${VM}" "${VM}.box"