Warning Livedoc is no longer being updated and will be deprecated shortly. Please refer to https://documentation.tjhsst.edu.

VM Creation

From Livedoc - The Documentation Repository
Revision as of 16:49, 28 December 2016 by 2019okulkarn (talk | contribs) (update with ubuntu stuff)
Jump to: navigation, search

Storage Setup

We use iSCSI LUNs to back the partitions for our VM cluster. Each VM has at least two LUNs for a root and a swap partition. Some VMs may have additional partitions for specific purposes.

Once you know how many and what size partitions you will need, see the SAN/iSCSI Administration guide for detailed instructions on configuring a LUN for each required partition. When you are done, you should have device nodes in /dev/mapper for each new volume


Soon we won't be pinning kernel and we will use an MBR formated disk to do native boot via grub/similar

The old way involved this


We currently use ext4 as the main filesystem for all of our VM partitions except for swap partitions (obviously). Create filesystems on each of the new VMs partitions now; then mount them on the host VM server.

# In theory this should work (maybe I will script it)
mkfs.ext4 /dev/mapper/apocalypse-<hostname>-root
mkfs.ext4 /dev/mapper/apocalypse-<hostname>-boot
cfdisk /dev/mapper/apocalypse-<hostname>-boot
#  Create 1 bootable Linux type partition that takes up the whole disk
mkswap /dev/mapper/apocalypse-<hostname>-swap
mkdir /mnt/<hostname>
mount /dev/mapper/apocalypse-<hostname>-root /mnt/<hostname>
debootstrap --arch amd64 xenial /mnt/<hostname> http://mirror.rit.edu/ubuntu/
mount /dev/mapper/apocalypse-<hostname>-boot /mnt/<hostname>/boot 
chroot /mnt/<hostname>
(chroot) apt update
(chroot) systemctl enable getty@ttyS0
(chroot) passwd
(chroot) exit
# now we will be booting into a pinned kernel version and installing grub
# and I will finish the rest later

VM Installation

We maintain a prebuilt base VM along with an excludes file that can be used to very quickly install a new VM without having to go through the normal Gentoo install process. Use the following commands to copy the stage64 image to the new VM.

 scp stage64:newvm-excludes ~/
 rsync -avSz --numeric-ids --exclude-from=~/newvm-excludes stage64:/ /mnt/<hostname>

If you need the kernel sources (only if you need to compile 3rd party modules such as AFS)

 cd /mnt/<hostname>/usr/src/
 git clone git://haimageserver/linux-stable.git linux-stable.git

VM Postinstall

There are a few postinstall steps that need to be completed on the copied image before it is ready to run. First, chroot into the new VM and set the root password.

 chroot /mnt/<hostname> /bin/bash
 source /etc/profile
 export PS1="{<hostname>}$PS1"


If you have any additional partitions beyond root and swap, add them to /etc/fstab.

Configure the system's new identity in various files and make sure that no part of stage64's identity was copied over.

 vim /etc/conf.d/hostname
 vim /etc/conf.d/net
 rm /etc/ssh/ssh_host_* #These should already be gone
 rm /etc/krb5.keytab

 ktutil -k /etc/krb5.keytab get -p ahamilto/admin host/<FQDN>
 vim /etc/issue #Remove the warning and change the hostname
 vim /etc/nagios/nrpe.cfg #Edit the bind IP and update check values if appropriate
 vim /etc/security/access.groups #remove stage64 and add in appropriate hostname group
 crontab -l #Configure appropriate backup time

More about backups can be found at on the Guardian Backup System page, this setup can be done before or after the VM is created.

Finally, exit the chroot and unmount all of the VM's partitions.

 #umount additional partitions if needed, then.
 umount /mnt/<hostname>

Libvirt VM Definition

Copy the stage64 XML configuration file to create the new VM's configuration; then edit it as detailed below.

 cd /etc/libvirt/qemu
 cp stage64.xml <hostname>.xml

 vim <hostname>.xml

Set name, partitions, kernel, memory, and networking as appropriate Mac address is derrived from the IPv4 Address of the system

Load the new VM's configuration into libvirt and then start the new VM.

 virsh define /etc/libvirt/qemu/<hostname>.xml
 virsh start <hostname>