Changing the zone path of a pre-existing zone

So, the hostname of one of our zones changed, and we create ZFS file systems for the zones using <path>/<zonename>

Easy enough of a fix…

root@db@blah-global:~#zoneadm list -cv
ID NAME             STATUS     PATH                           BRAND    IP
0 global           running    /                              native   shared
1 blah         running    /local2/data/zones/blah    native   shared
5 blah1          running    /local/data/zones/blah1      native   shared

root@db@blah-global:~#zonecfg -z blah1
zonecfg:blah1> set zonename=blah2
blah1: Zone state is invalid for the requested operation
So lets shut down the zone and change the zone name.

root@db@blah-global:~#zoneadm -z blah1 halt
root@db@blah-global:~#zonecfg -z blah1 info
zonename: blah1
zonepath: /local/data/zones/blah1

root@db@blah-global:~#zonecfg -z blah1
zonecfg:blah1> set zonename=blah2
zonecfg:blah2> verify
zonecfg:blah2> commit
zonecfg:blah2> exit

So now that we’ve changed the zone name, I also wanted to update the ZFS file system to reflect the new hostname…

root@db@blah-global:~#zfs rename pool0/local/data/zones/blah1 pool0/local/data/zones/blah2

Easy enough.  Lets boot the zone.

root@db@blah-global:~#zoneadm list -cv
ID NAME             STATUS     PATH                           BRAND    IP
0 global           running    /                              native   shared
1 blah         running    /local2/data/zones/blah    native   shared
- blah2    installed  /local/data/zones/blah1      native   shared

root@db@blah-global:~#zoneadm -z blah2 boot
zoneadm: /local/data/zones/blah1: No such file or directory
could not verify zonepath /local/data/zones/blah1 because of the above errors.
zoneadm: zone blah1 failed to verify

DOH.  Forgot to change the zone path.. So lets go fix this…

root@db@blah-global:~#zonecfg -z blah2
zonecfg:blah2> set zonepath=/local/data/zones/blah2
Zone blah2 already installed; set zonepath not allowed.

WHAT?!?!  Come on now zonecfg, this shouln’t be brain surgery….

So, lets go poke at the source of truth — /etc/zones.

root@db@blah-global:/etc/zones#grep blah1
index:blah2:installed:/local/data/zones/blah1:6b9891a3-7029-ef67-9581-aa01475c9b6e
blah2.xml:<zone name=”blah2″ zonepath=”/local/data/zones/blah1″ autoboot=”true”>

So, go and edit blah2.xml to change the zone path, as well as index.  (Make backup copies of these before doing so please)

Once the modifications were done, I was able to boot up the zone with the newly changed zonepath.

root@db@blah-global:/etc/zones#zoneadm list -cv
ID NAME             STATUS     PATH                           BRAND    IP
0 global           running    /                              native   shared
1 blah         running    /local2/data/zones/blah    native   shared
- blah2    installed  /local/data/zones/blah2 native   shared

root@db@blah-global:/etc/zones#zoneadm -z blah2 boot
root@db@blah-global:/etc/zones#zoneadm list -cv
ID NAME             STATUS     PATH                           BRAND    IP
0 global           running    /                              native   shared
1 blah         running    /local2/data/zones/blah    native   shared
6 blah2    running    /local/data/zones/blah2 native   shared
root@db@blah-global:/etc/zones#zlogin blah2
[Connected to zone 'blah2' pts/1]
Last login: Fri Mar 27 17:14:03 from blah-global
Sun Microsystems Inc.    SunOS 5.10    Generic    January 2005
#

Sun, could we please extend zonecfg to do this for us?  The header of /etc/zones/index is scary.

root@db@blah-global:~#cat /etc/zones/index
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident “@(#)zones-index        1.2     04/04/01 SMI”
#
# DO NOT EDIT: this file is automatically generated by zoneadm(1M)
# and zonecfg(1M).  Any manual changes will be lost.
#

3 Comments

Craig S. Bell  on May 28th, 2009

Would the newer “zoneadm move” command work for you? The NGZ must still be halted first, but it’s a public interface.

apatoki  on October 22nd, 2009

You should be able to move the zonepath with “zoneadm detach”.

# zoneadm -z detach
# zfs rename …
# zonecfg -z set zonepath=
# zoneadm -z attach

I still think there should be an easier option though.

gene0921  on October 30th, 2009

Great help provided in the artcle:
Changing the zone path of a pre-existing zone

I very much doubt sunsolve would have had this.

Leave a Comment