GenVM - Customization scripts

All elements is customizable with GenVM by a simple mechanism of scripts, located on a chosen directory, and executed from virtual machine, from master or from master after the installation (for operations on disk image like chown, copy, etc).

The “-t” option, set the directory containing the personalizations scripts (here scripts are located on directory “3rd”):

fhh@aaricia ~ $ su -c "genvm -t 3rd vm.vmdk"

The order and context of execution are define by the scripts names, that’s why it must respect accurate name syntax:

XX.{chroot|host|post}.script_name
XX
this is a number, in two digits (so between 00 and 99), defining the order of execution of script
{chroot|host|post}
define where the script is executed
chroot mean script executed on this virtual machine
host mean script executed from host
post mean script executed after the installation
script_name
this is a name of script

Files that don’t respect this name syntax are ignored.

Executions rights aren’t need (scripts are sourced).

Note:
Your virtual machine contain very few packages, so if you use on chrooted environment a command, be sure it’s available. Example, to use wget, install it first.

Example of personalizations scripts tree:

3rd/
├── 01.chroot.norecommends
├── 01.host.issue
├── 01.host.network
├── 01.post.chown
└── 99.post.run

Variables and functions

In scripts executed in host environment or “post generation”, you can use some variables initialized by GenVM and functions defined in it.

Variables

ARCH
Architecture of virtual machine.
HD_IMG
This is the name of image disk generated.
MOUNT_POINT
This is the location where the future virtual machine is mounted (so where your future VM is accessible).
NAME
Name of virtual machine.
THIRD
file or directory containing third party part.

Functions

set_passwd_to <username> <password>
This function set the password <password> to user <username>. User must exist.

Example of scripts

Category “scripts” offer some useful scripts to personalize your machine.

Network configuration of VM

This script executed from host set the network configuration of virtual machine.

aaricia ~ # cat > 01.host.network
cat > "${MOUNT_POINT}/etc/network/interfaces <<_eof_
auto lo eth0                    
 
iface lo inet loopback
 
iface eth0 inet dhcp
_eof_
^d

Obviously, you should install ifupdown, isc-dhcp-client or udhcpc on your VM (have look on GenVM - Add packages to install additional packages).

Activate NoRecommends

This script executed from the created VM, disable installation of recommended packages on Debian.

aaricia ~ # cat > ~/scripts.genvm/01.chroot.norecommends
cat > /etc/apt/apt.conf.d/02norecommends <<_eof_
APT::Install-Recommends False;
_eof_
^d

Keyboard layout

In this example, script (executed on virtual machine) set the keyboard layout to french one:

aaricia ~ # cat > ~/scripts.genvm/03.chroot.keymap
cat > /etc/default/keyboard <<_eof_
XKBMODEL="pc105"
XKBLAYOUT="fr"
XKBVARIANT="oss_latin9"
XKBOPTIONS="terminate:ctrl_alt_bksp"
BACKSPACE="guess"
_eof_

Remember to add “console-setup” on list of packages (have look on GenVM - Add packages to install additional packages).

Only run personalizations scripts

The “-T” option placed on the line used to create the virtual machine permit the execution of third party scripts only.

fhh@aaricia ~ $ su -c "genvm -Tt 3rd vm.vmdk"

Combined with “-v” or stronger with “-D” this options is ideal in development stage.