Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.