Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With OpenVZ you assign a VE's hostname (among other things) from the host node (HN) using vzctl set CTID --hostname myhost --save. It then sets this in /etc/vz/conf/CTID.conf. During startup of the VE, a distribution-specific file in /etc/vz/dists is consulted containing pointers to files in /etc/vz/dists/scripts. Those are distribution-specific scripts for editing the VE's config files, for instance if the VE uses Debian or Ubuntu, the hostname is written to /etc/hostname. The same happens with the IP address, for example.

My question now is: How does OpenVZ know which file in /etc/vz/dists to use? Does it somehow derive the distribution name from the template's name?

share|improve this question
up vote 2 down vote accepted

Looking at the source of vzctl, I figured out how it works. It actually does derive the name from the name of the template. When starting up the VE, at some point a method in lib/dist.c is called:

static int get_dist_conf_name(char *dist_name, char *dir, char *file, int len)
      char buf[256];
      char *ep;

      if (dist_name != NULL) {
            snprintf(buf, sizeof(buf), "%s", dist_name);
            ep = buf + strlen(buf);
            do {
                  snprintf(file, len, "%s/%s.conf", dir, buf);
                  if (stat_file(file))
                        return 0;
                  while (ep > buf && *ep !=  '-') --ep;
                  *ep = 0;
            } while (ep > buf);

There it removes dash delimited parts from the end of the name, each time looking for a match. The template I was looking at is arch-2010.05-x86_64-minimal, so here it first tries arch-2010.05-x86_64-minimal.conf, then arch-2010.05-x86_64.conf, then arch-2010.05.conf, until it finally finds a file named arch.conf holding the pointers to the scripts for updating Arch's configuration files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.