# Jail cannot start / restart



## satriani (Nov 5, 2017)

Hello
Often I get the following problem when starting / restarting my jails


```
# service jail start sys1
Starting jails: cannot start jail  "sys1":
jail: sys1: cannot redefine variable "name".
jail: sys2: cannot redefine variable "name".
jail: sys3: cannot redefine variable "name".
jail: sys1: jail 1 already exists
```

After a few minutes, it works normally again.

/etc/jail.conf

```
exec.clean;
exec.start += "/bin/sh /etc/rc";
exec.stop = "/bin/sh /etc/rc.shutdown";
exec.system_user = "root";
exec.jail_user = "root";
exec.consolelog = "/var/log/jail_${name}_console.log";
mount.devfs;
mount.fstab = "/etc/fstab.${name}";
allow.mount;
allow.set_hostname = 0;
allow.sysvipc = 0;
allow.raw_sockets = 0;
devfs_ruleset = 4;

sys1 {
        jid = 1;
        name = sys1;
        path = /usr/jail/sys1;
        ip4.addr = 127.0.0.2;
        host.hostname = sys1.local;
        persist;
        interface = lo0;
        allow.sysvipc = 1;
}

sys2 {
        jid = 2;
        name = sys2;
        path = /usr/jail/sys2;
        ip4.addr = 127.0.0.3;
        host.hostname = sys2.local;
        persist;
        interface = lo0;
        allow.sysvipc = 1;
}

sys3 {
        jid = 3;
        name = sys3;
        path = /usr/jail/sys3;
        ip4.addr = xxx.xxx.xxx.xxx, 127.0.0.4;
        ip6.addr = xxx:xxx:xxx;
        host.hostname = website.tld;
        persist;
        interface = em0, lo0;
        allow.sysvipc = 1;
}
```

Each jail is in its own dataset eg. /usr/jail/sys1, /usr/jail/sys2, /usr/jail/sys3
with base and template method /usr/jail/base /usr/jail/tmpl

/etc/fstab.sys1

```
/usr/jail/base /usr/jail/sys1/base nullfs noatime,ro 0 0
```

/etc/fstab.sys2

```
/usr/jail/base /usr/jail/sys2/base nullfs noatime,ro 0 0
```

/etc/fstab.sys3

```
/usr/jail/base /usr/jail/sys3/base nullfs noatime,ro 0 0
```


```
# freebsd-version
11.1-RELEASE-p3
```

What can cause this problem?

Thanks in advance.


----------



## ShelLuser (Nov 6, 2017)

Well, I think the error says it all; you can't (re)define name. See also jail(8), although I do agree that it's not very explicitly mentioned:


```
name    The jail name.  This is an arbitrary string that identifies a
             jail (except it may not contain a `.').  Like the jid, it can be
             passed to later jail commands, or to jls(8) or jexec(8).  If no
             name is supplied, a default is assumed that is the same as the
             jid.  The name parameter is implied by the jail.conf(5) file
             format, and need not be explicitly set when using the
             configuration file.
```
So my suggestion is to get rid of the name parameter in your jail definitions.


----------



## satriani (Nov 6, 2017)

OK, I understand, but why does that happen sporadically?


----------



## SirDice (Nov 6, 2017)

Remove the name and jid from jail.conf. The name is already defined:

```
[b]sys1[/b] {
...
}
```
The actual jid will be the first _free_ JID.


----------



## satriani (Nov 6, 2017)

Unfortunately without success

```
# service jail restart
Stopping jails:.
Starting jails:jail: sys1: jail 1 already exists
ifconfig: : bad value
jail: sys2: /sbin/ifconfig lo0 inet  netmask 255.255.255.255  alias: failed
jail: sys3: jail 3 already exists
```

next try

```
# service jail restart
Stopping jails:.
Starting jails:sys1: created
jail: sys1: /bin/sh /etc/rc: failed
sys1: removed
ifconfig: : bad value
jail: sys2: /sbin/ifconfig lo0 inet  netmask 255.255.255.255  alias: failed
sys3: created
jail: sys3: /bin/sh /etc/rc: failed
sys3: removed
```

Is there a way to reset the ID assignment?
Because I would like to assign an ID to each cell myself.


----------



## satriani (Nov 8, 2017)

There must be some way to reset the JID-counter.
Does anyone know how to do that?


----------



## SirDice (Nov 8, 2017)

satriani said:


> There must be some way to reset the JID-counter.
> Does anyone know how to do that?


By rebooting. There is no way to "reset" the counter. Which is why you shouldn't depend on specific JIDs.


----------



## tobik@ (Nov 8, 2017)

A JID is like a PID and you have no control over either of them.



satriani said:


> Starting jails:sys1: created jail: sys1: /bin/sh /etc/rc: failed sys1: removed ifconfig: : bad value


So what do you see in /var/log/jail_sys1_console.log?


----------



## satriani (Nov 8, 2017)

SirDice said:


> By rebooting. There is no way to "reset" the counter. Which is why you shouldn't depend on specific JIDs.


That is, there is the nice practical option to set a static JID, but unfortunately it seems to be baggy. The option to assign JID is very useful for managing the jails.

```
jid     The jail identifier.  This will be assigned automatically to a
             new jail (or can be explicitly set), and can be used to identify
             the jail for later modification, or for such commands as jls(8)
             or jexec(8).
```



tobik@ said:


> A JID is like a PID and you have no control over either of them.
> 
> 
> So what do you see in /var/log/jail_sys1_console.log?


actually, nothing unusual except maybe
`jail: sys1: exec /bin/sh: No such file or directory`


----------



## SirDice (Nov 8, 2017)

satriani said:


> The option to assign JID is very useful for managing the jails.


Refer to the jail by its name, not its JID. The JID is dynamic, the name is static.


----------



## tobik@ (Nov 8, 2017)

satriani said:


> That is, there is the nice practical option to set JID, but unfortunately it seems to be baggy. The option to assign JID is very useful for managing the jails.


TIL...  Though I still don't understand the rationale for that feature.



satriani said:


> actually, nothing unusual except maybe
> `jail: sys1: exec /bin/sh: No such file or directory`


But /usr/jail/sys1/bin/sh exists?


----------



## satriani (Nov 11, 2017)

tobik@ said:


> But /usr/jail/sys1/bin/sh exists?



/usr/jail/base is exist but there is nothing in it 
Looks like there are problems with the nullfs mounting


----------

