Next Previous Contents

5. Pre-Setup: Template Filesystem

5.1 Template Filesystem

Prior to setting up virtual servers, you must create a template filesystem, which will be used to decide what files each virtual server will contain. In other words, you must create a small Linux Filesystem. The files within the template filesystem will be hard linked to each virtual server you create. The template directory will be the directory and file structure for your virtual servers - whatever is in the template directory will be what each virtual server you create will contain. This may seem a hassle but there are many reasons this must be done. In order for the files to be linked over, they must all be within the same partition (most servers have multiple partitions). Virtfs uses links to create virtual servers to save hard drive space. For example, if you are running about six virtual servers and copied all the files over for each server, this would amount to about 700Mb in itself. By linking, however, this problem is eliminated. Each server will take up about 5-10Mb. However not all of the filesystem is linked over. For example, /etc/hosts, /etc/HOSTNAME, etc - system specific files are not linked and therefore are not included in the template filesystem.

Another advantage to the template filesystem is that you can configure what files should be copied over to the virtual servers. Would you want the "virtual users" to have access to developmental tools? SSH? You can specify which files should be included with each virtual server by copying them to the template filesystem.

To recap, the process in creating virtual servers is simple. Firstly, a template directory is created and whatever files you specify will be copied over to the template filesystem. Then, when you want to create virtual servers, the files from the template filesystem are hard linked to the virtual server - Virtfs handles this for you upon creation of a virtual server. You will have to make sure that the template directory is within the same partition as the virtual servers, ie within the /virtual directory (if you stick to the suggested configuration). If you don't please make changes to the Leading Virtual Directory variable within /etc/virt.conf.

The basic structure of this is:

                           --------------------
                           |  MAIN SERVER: /  |
                           ____________________
                                   |         
                                   |
                                   V direct copy
                                   |
                  -----------------------------------------
                  | Template Filesystem /virtual/template |
                  -----------------------------------------
                     |                          |     |        
   hard links        ^                          ^     ---------<-------------- 
                     |                          |                            |
                     |                          |                            |
                 -----------------        ------------------           ------------------
                 |   a.com        |       |     b.com      |           |    c.com       |
                 | /virtual/a.com |       | /virtual/b.com |           | /virtual/c.com |
                 -----------------        ------------------           ------------------

5.2 Setting up a template filesystem

This section describes how to configure the template filesystem from the /etc/virt_template.conf file.

<Template>

To specify what files should be copied over to the template filesystem, edit the /etc/virt_template.conf file. Within the <Template> section, you will notice, for example:

bin_files = ls echo bash ...

In the above example the bin_files variable holds the names of the files which are to be copied from the main server's /bin directory to the template filesystem, ie /virtual/template/bin. Seperate each filename with a space.

Therefore, from the value of bin_files above, each virtual server will contain ls, echo, bash and whatever else was specified. Here is an outline of which directories are dealt with:

If you would like to copy a whole directory to the template directory, for example /usr/sbin/some_dir, you may list some_dir/* within the usr_sbin_files list. Another alternative is to edit the <Custom Template> section (below).

You must be asking yourself about the /etc/ directory. Since this directory is very specific to each server, and not general such as the executables mentioned above, we must choose the files carefully. When creating a template, the sendmail configuration files are copied over (sendmail.cf) and some are created on the fly (sendmail.cw).

By default the template directory will be /virtual/template but you can always change this value within /etc/virt_template.conf.

<Custom Template>

Within the same configuration file, virt_template.conf there is the <Custom Template> section. In this section, you can specify what shell commands should be executed after virt_template.pl does all the copying of the files from the <Template> section. An example may be:

cp -a /lib !!template
The !!template will be replaced by virt_template.pl and it indicates the template directory. Therefore, the above is stating: cp -a /lib /virtual/template (if we choose to stick to the directory defaults). This section is for you to customise the template directory even further than the <Template> section.

<Passwd File>, <Shadow File> and <Group File>

In these sections, you must specify the password, shadow and group files that will be copied over. I suggest copying these file to a secure location on your main server first, and then editing them to delete the accounts you do not want on your virtual server. For example, you probably like to remove your normal users accounts. But please keep the root password, shadow and group entried unedited (you may change the password at a later time). So, for example, you may copy your main server's /etc/passwd, /etc/shadow and /etc/group files to a secure location, ie /root. Then edit the files to your preference. If your main server has the joe account, but your virtual servers should not contain this, remove the entries for the account from the passwd, shadow and group files. After the template directory is created, remove the temporary files!

If you copy over the main server's password, shadow and group files, all those accounts (except for home directories) will be copied over, so I have left this option up to you for which accounts should stay and which should be removed.

The Perl script virt_template.pl creates the template directory. The script is interactive and will create the template filesystem for you. Once it has been created you can make changes to the directory. Remember it is this directory structure that each virtual server will link to, and only server specific files will be copied over.

5.3 Executing virt_template.pl

If you are happy with the configuration of /etc/virt_template.conf, you are now ready to create the filesystem. The Perl script, virt_template.pl will help you with this. The script will be informative and you will know what is going on.


Next Previous Contents