How to create Virtual Machines from scratch
We've created a script that will help you create Virtual Disks images and docker images. This script is named create_imagevm. You can obtain it by cloning the following git repository: https://github.com/CosyVerif/images. In order to use it, you have to download genvm, which is located on the CosyVerif's repository. Here's how to do it. You also have to install the package docker.io.
If you want to use that script you have to be root ! (or a least be able to use the sudo command).
The scripts works that way: first, it download an up-to-date debian system (you can specify which version), make a docker image out of it, and applies dockerfiles on it (you can choose which ones). You can modify the way the script behaves by using a lot of options. Here's the list of all of them:
-
-a <arch>, --arch=ARCH, --architecture=ARCH
Architecture of the thing you're going to create. It can either be amd64 or i386. Default value: amd64. -
-b <branch>, --branch=BRANCH
Branch of the thing you're going to create. This is the option that allows you to specify which dockerfiles you want to apply on the base docker image that will be used to create the virtual disk image at the end (or the docker image, if that's what you want). THIS OPTION IS MANDATORY UNLESS YOU USE --custom. Keep in mind that Debian is always downloaded, unless you use --from to specify a base image on which the script will apply all dockerfiles. This option must take one of the 9 following values:-
debian
This branch allows you to create a basic debian system, without any kernel (unless you want to create a virtual disk image. In that case, there will be one). There are no dockerfiles applied. -
cosy
This branch will allow you to create a virtual disk image (or a docker image) with a kernel, and a user named cosy. The dockerfiles applied are: without-recommends, with-kernel and with-cosy. -
buildeb
Creates a minimal virtual disk image (or docker image) with all the dependencies of buildeb installed. Dockerfiles applied: without-recommends, with-minimal and with-buildeb. -
kernel
Creates a virtual disk image (or a docker image) with a kernel. Dockerfiles applied: with-kernel. -
minimal
Creates a minimal virtual disk image (or docker image). It means that there are no manpages and documentations. It also means that when you're going to install a package, the packages marked as 'recommended' by apt-get won't be installed (they normally are). Dockerfiles applied: without-recommends and with-minimal. -
repo
Creates a minimal virtual disk image (or docker image) with a kernel and all the programs you need to setup a repository. If you want to configure them correctly you have to fill the following files (they're all in the git repository): data/home/repo/.ssh/authorized_keys, data/etc/apache2/sites-available/repository, data/home/repo/.dput.cf, data/home/repo/.mini-dinstall.conf and data/home/repo/gpg-keygen.conf . Here's how to fill them.
Dockerfiles applied: without-recommends, with-minimal, with-kernel and with-repo. -
jenkins-slave
Creates a minimal virtual disk image (or docker image), which contains a kernel and all the software you need to setup a jenkins slave. You might want to read that if you want to configure it right. Dockerfiles applied: without-recommends, with-minimal, with-kernel and with-jenkins-slave. -
without-recommends
Create a virtual disk image (or a docker image) on which recommended packages won't be installed when you're using apt-get. Dockerfiles applied: without-recommends. -
custom:DOCKERFILES
Create a custom virtual disk image (or docker image). With that value, you can choose the dockerfiles that will be applied on the base docker image, as long as they're all in the same directory (which is dockerfiles/, if you don't use -d). The dockerfiles must be written like that:-b custom:dockerfile1,dockerfile2,...For more informations about the dockerfiles in the directory dockerfiles/, see --custom below (which is the same as using -b custom:DOCKERFILES).
-
debian
-
--custom=DOCKERFILES, --dockerfiles=DOCKERFILES
List of dockerfiles you want to apply on the base docker image. The dockerfile list must be written like that:--custom=dockerfile1,dockerfile2,...The dockerfiles will be applied in the same order they appear on your list.
The following dockerfiles are already in the default dockerfiles' directory (i.e. dockerfiles/):-
clean
This dockerfile will remove unnecessary packages, all temporary files and all *.deb files downloaded by apt-get. This dockerfile is always executed before creating the final docker image (or virtual disk image), so you don't really have to put it on your list. -
install-extrapackages
This dockerfile will install extra packages. If you want to use it you have to use -p (or --packages, --install ...) to define what packages you want to add. However, if you use -p (or --package, ...) the script will automatically execute this dockerfile right before creating the final docker image/virtual disk. If you want to execute it at another time, then you should put it in your list. In that case, the script won't execute it at the end. -
remove-packages
This dockerfile will remove packages. To indicate what packages you want to remove, you have to use --remove-packages. If you don't use it, no packages will be removed. Like install-extrapackage, this dockerfile is normally executed at the end of the script. If you want to execute it at another time, you should put it on your list. -
with-buildeb
This dockerfile will install all the dependencies of buildeb. It'll not install buildeb. -
with-cosy
Dockerfile that creates an user named cosy. -
with-jenkins-slave
Dockerfile that install and configure all the software you need to create a jenkins slave. It installs buildeb, slave-cosy (which contains all the scripts needed to build and create packages via jenkins), docker.io and creates an user named 'jenkins'. It also adds an authorized_keys file in the directory /usr/home/jenkins/.ssh of the docker image/virtual disk. You can find this file in the directory data/home/jenkins/.ssh/. -
with-kernel
Dockerfile that compiles a linux kernel and install a bootloader. It also adds a password for root (which is toor). This dockerfile is mandatory if you want to create a vm. If you don't put it on your list, this script will execute it anyway. Consider yourself warned. -
with-minimal
Dockerfile that forces apt-get to exclude some directories when installing packages. Thus, apt-get won't be able to create files in those directories. The list of excluded directories can be found in the file data/etc/dpkg/dpkg.cfg.d/01_nodoc. This allows us to reduce the size of installed packages. This dockerfile also reinstalls every packages installed (in order to apply those modifications to the packages that have already been installed). We recommend you to execute this dockerfile before any other dockerfile that may install packages, because this one takes quite some time. -
without-recommends
This Dockerfile will force apt-get to never download and install suggested or recommended packages (which aren't mandatory at all). -
with-repo
This Dockerfile installs and configures all the software you need to setup a debian repository. This includes: apache, mini-dinstall, and dput. The configuration files used to configure those softwares are located in data/etc/apache2/sites-available/ (for apache2), data/home/repo/.ssh (for ssh), and data/home/repo/ (for dput and mini-dinstall). We highly recommend you to look at those files and fill them correctly. This dockerfile also creates an user named 'repo' and generates a key for the repo, which will be used to sign packages.
-
clean
-
-c <configuration_file>, --configuration-file=FILE
Path leading to a configuration file. It's not mandatory. If you use one, every options after this one will be ignored. You can find one in the git repository. Its name is create_imagevm.conf.yml -
-d <directory>, --directory=DIR, --dockerfiles-dir=DIR
Path leading to the directory that contains all dockerfiles. Default value: ./dockerfiles. -
-D, --debug, --debug-mode
Debug mode. -
-f <format>, --format=FORMAT, --vm-format=FORMAT,
--format-vm=FORMAT
Type of virtual disk image to create. Can be one of these: vmdk, qcow2, qcow, raw. Default: vmdk. If you want to build a docker image, you must not use this option. -
-F <image>, --from=IMAGE
Docker image on which all dockerfiles will be executed. Debian won't be downloaded in this case. -
-h, --help
Print an help. -
-n <name>, --name=NAME
Name you want to give to your virtual disk image (or docker image).
Default value for a docker image: <branch>:<Debianversion>-<arch>
Default value for a virtual disk image: <branch>.<Debianversion>.<arch>.<vmformat> -
-p <packages>, --install=PACKAGES, --extra-packages=PACKAGES,
--packages=PACKAGES
List of packages you want to install in the resulting virtual disk/docker image. The list of packages must be written like this:-p package1,package2,package3,... -
-r <yes/no>, --remove=yes/no
(Do or Don't) Remove temporary docker images and files. Default value: yes. It means that temporary files and docker images will be removed -
-R <repo>, --repository=REPO, --repo=REPO, --cosy-repo=REPO
Address of the debian repository where are located all the cosyverif related packages. It must follow this pattern: <repo_address>,<section>. Default: http://cosyverif-debian.lip6.fr jessie-testing/
<section> MUST be coherent with the debian version you want to use. -
--remove-packages=PACKAGES
List of packages to remove in the virtual disk/docker image. The list must be in the written like this :--remove-packages=package1,package2,package3,... -
-s <size>, --size=SIZE, --vmsize=SIZE, --sizevm=SIZE
Size of the virtual disk image. Default: 5G. -
-t <type>, --type=TYPE
What you want to create. <type> can be one of these:
image: A docker image will be created
vm: A virtual disk image will be created.
This option is mandatory. -
-v <version>, --version=VER, --debian-version=VER,
--release=VER
Debian version you want to use to create your docker image or your virtual disk image. It must either be a release code name (squeeze, wheezy, ...) or a symbolic name (stable, testing, unstable, ...). Default value: jessie. -
-V, --verbose, --verbose-mode
Verbose Mode
Here are some examples of how you can use this script: