Changing zonepath of an installed Zone

If a Solaris Zone is installed, we cannot change the zonepath with zonecfg command.
Theoretically isn’t recommended changing the zoneptah after zone installation, but in some situation we need to do this.
How can we do?

We need edit the config files manually, use for example vi. (Under Solaris by default, you cannot find nano 🙂  )
The zone configs are in the /etc/zones directory:

[root@MAB-0030:/]# ls -l /etc/zones
 -rw-r--r--   1 root     sys          701 Dez 13 15:26 index
 -rw-r--r--   1 root     root         487 Nov 16 14:39 korte1.xml
 -rw-r--r--   1 root     root         486 Nov 15 14:49 korte2.xml
 -rw-r--r--   1 root     root         486 Nov 15 15:16 korte3.xml
 -r--r--r--   1 root     bin          392 Aug  9  2007 SUNWblank.xml
 -r--r--r--   1 root     bin          562 Aug  9  2007 SUNWdefault.xml
 -r--r--r--   1 root     bin          402 Jun 20  2007 SUNWlx.xml
 -r--r--r--   1 root     bin          777 Mrz 12  2008 SUNWtsoldef.xml
 -rw-r--r--   1 root     root         509 Dez 13 15:26 test-zone5.xml
 -rw-r--r--   1 root     root         274 Mai 29  2012 zone-1.xml
 -rw-r--r--   1 root     root         502 Dez 13 14:32 zone-5.xml

We need edit 2 config files:
– index
– and the your_zonename.xml

In my example I will change the zonepath for a test-zone5.

1. Create a backup from the config files

cp /etc/zones/index /etc/zones/index_backup
cp /etc/zones/test-zone5.xml /etc/zones/test-zone5.xml_backup

2. Stopping the zone

[root@MAB-0030:/]# zoneadm list -iv
 ID NAME             STATUS     PATH                           BRAND    IP
 0 global           running    /                              native   shared
 6 test-zone5       running    /rpool/test-zone5              native   shared
 - zone-1           installed  /zones/zone-1                  native   shared
 - zone-5           installed  /zones/zone-5                  native   shared
 - korte1           running     /zones/korte1                  native   shared
 - korte2           running     /rpool/korte2                  native   shared
 - korte3           running     /rpool/korte3                  native   shared
[root@MAB-0030:/]# zoneadm -z test-zone5 halt

3. Moving the Zone on the files ystem

[root@MAB-0030:/]# zfs list
 NAME                                 USED  AVAIL  REFER  MOUNTPOINT
 rpool                               12,0G  7,58G  50,5K  /rpool
 ..
 rpool/swap                          1,50G  8,99G  94,1M  -
 rpool/test-zone5                     605M  7,58G   605M  /rpool/test-zone5
 ..

I have a separated ZFS file system to the test-zone5, therefore I not need move the zone files or directories, I just rename the ZFS file system.
We love you ZFS ! 😀

[root@MAB-0030:/]# zfs rename rpool/test-zone5 rpool/zones/test-zone5
 cannot create 'rpool/zones/test-zone5': parent does not exist

Oops, first I need to create the parent: rpool/zones

[root@MAB-0030:/]# zfs create rpool/zones
[root@MAB-0030:/]# zfs rename rpool/test-zone5 rpool/zones/test-zone5
[root@MAB-0030:/]# zfs list
 NAME                                 USED  AVAIL  REFER  MOUNTPOINT
 rpool                               12,0G  7,58G  50,5K  /rpool
 ..
 rpool/swap                          1,50G  8,99G  94,1M  -
 rpool/zones                          605M  7,58G    32K  /rpool/zones
 rpool/zones/test-zone5               605M  7,58G   605M  /rpool/zones/test-zone5
 ..

Ok, we can see, that the ZFS file system name and the mount point was successful renamed.
If you have a zone installed in a normal directory, you need move the files from the old zonepath directory to the new.

4. Edit the index file

vi /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.
 #
 global:installed:/
 zone-1:installed:/zones/zone-1:55b96ba2-1d2e-e98a-9313-f56e5d726e57
 zone-5:installed:/zones/zone-5:0995febb-2543-c12d-e4d6-bd3bca890605
 korte1:installed:/zones/korte1:b13c490f-6797-c2c6-f415-dba1cc0d0f2d
 korte2:installed:/rpool/korte2:249a1129-6895-c481-9c02-d5fb950ea056
 korte3:installed:/rpool/korte3:99f935a1-ca5e-659a-a299-fc0f5002777a
 test-zone5:installed:/rpool/test-zone5:abedc25e-7eb8-ccdf-c4d9-c2bc54258417

We need modify the zonepath in the line for the test-zone5.
The actually zonepath is /rpool/test-zone5, and the new zonepath is: /rpool/zones/test-zone5
And the new line will be:

 test-zone5:installed:/rpool/zones/test-zone5:abedc25e-7eb8-ccdf-c4d9-c2bc54258417

5. Edit the zone configuration file

vi /etc/zones/test-zone5.xml
[root@MAB-0030:/]# cat /etc/zones/test-zone5.xml
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE zone PUBLIC "-//Sun Microsystems Inc//DTD Zones//EN" "file:///usr/share/lib/xml/dtd/zonecfg.dtd.1">
 3 <!--
 4     DO NOT EDIT THIS FILE.  Use zonecfg(1M) instead.
 5 -->
 6  <zone name="test-zone5" zonepath="/rpool/test-zone5" autoboot="true">
 7    <inherited-pkg-dir directory="/lib"/>
 8    <inherited-pkg-dir directory="/platform"/>
 9    <inherited-pkg-dir directory="/sbin"/>
 10   <inherited-pkg-dir directory="/usr"/>
 11 </zone>

In line 6 I change the zonepath to /rpool/zones/test-zone5 The new line looks like this:

 <zone name="test-zone5" zonepath="/rpool/zones/test-zone5" autoboot="true">

6. If booth file was edited, we are ready to start the zone

[root@MAB-0030:/]# zoneadm -z test-zone5 boot

And we need to check the zone status and the zonepath:

[root@TCB-Y0030:/]# zoneadm list -iv
 ID NAME             STATUS     PATH                           BRAND    IP
 0 global           running    /                              native   shared
 7 korte1           running    /zones/korte1                  native   shared
 8 korte2           running    /rpool/korte2                  native   shared
 9 korte3           running    /rpool/korte3                  native   shared
 10 test-zone5       running    /rpool/zones/test-zone5        native   shared
 - zone-1           installed  /zones/zone-1                  native   shared
 - zone-5           installed  /zones/zone-5                  native   shared

If the zone status is running and we can see the new zonepath, then the action was successful.
The whole procedure is not so complicated. If you cannot start the zone, check the logs, config files and the new zonepath, maybe you miswrite something 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s