Renaming Solaris zones

Tested on solaris 11.1 SRU 8, 4JUL2013

Goal: rename solaris zone name the ZFS dataset oldzonename to renamedzone, from the global zone perspective, and rename the ZFS dataset to match the new name. We'll also rename the non-global zone inside the zone.

Here is the Oracle Documentation on renaming zones, and on renaming a solaris instance.

root@globalzone:~# zoneadm list -vi
  ID NAME             STATUS     PATH                           BRAND    IP
   4 oldzonename      running    /zones/oldzonename             solaris  excl
`</pre> 

Halt the zone:
 <pre>`zoneadm -z oldzonename halt
`</pre> 

Set the new zone name:
 <pre>`root@globalzone:~# zonecfg -z oldzonename
zonecfg:oldzonename&gt; set zonename=renamedzone
zonecfg:renamedzone&gt; set zonepath=/zones/renamedzone
zonecfg:renamedzone&gt; commit
zonecfg:renamedzone&gt; exit
`</pre> 

Try Rename the ZFS datasets:
 <pre>`root@globalzone:~# zfs rename rpool/zones/oldzonename rpool/zones/renamedzone
cannot rename 'rpool/zones/oldzonename': child dataset with inherited mountpoint is used in a non-global zone
`</pre> 

This is because the zone **rpool/zones/oldzonename/rpool** has **zoned=true**

We need to remove that setting before trying again:
 <pre>`root@globalzone:~# zfs set zoned=off rpool/zones/oldzonename/rpool
root@globalzone:~# zfs rename rpool/zones/oldzonename rpool/zones/renamedzone
cannot mount 'rpool/zones/renamedzone/rpool/ROOT/solaris-2' on '/': directory is not empty
cannot mount 'rpool/zones/renamedzone/rpool/ROOT/solaris-2/var' on '/var': directory is not empty
root@globalzone:~# zfs set zoned=on rpool/zones/renamedzone/rpool
`</pre> 

Boot the zone, check everything works:
 <pre>`root@globalzone:~# zoneadm -z renamedzone boot
root@globalzone:~# zlogin renamedzone
root@globalzone:~# zlogin renamedzone
[Connected to zone 'renamedzone' pts/6]
Oracle Corporation      SunOS 5.11      11.1    May 2013
root@oldzonename:~#
root@oldzonename:~#
`</pre> 

Now rename the zone (from inside the zone):
 <pre>`root@oldzonename:~# svccfg -s identity:node setprop config/nodename=renamedzone
root@oldzonename:~# svccfg -s identity:node setprop config/loopback=renamedzone
root@oldzonename:~# svccfg -s identity:node refresh
root@oldzonename:~#
root@oldzonename:~# hostname
renamedzone