Monday, 2 October 2017

Using sysidcfg file to perform initial zone configuration

In this article I'll demonstrate how we can use a sysidcfg file to perform initial configuration of a solaris 10 zone after it has just been installed. Note that we need to do this before the zones' first boot.

To avoid creating the entire zone configuration from scratch I'll export a running zones' configuration, modify it and use it.

root@sandbox:/# zonecfg -z test-zone export -f auto-zone.cfg

This exported the zone test-zone's configuration to a file named auto-zone.cfg.
Now let's configure our new zone auto-cfg using this file.

root@sandbox:/# zonecfg -z auto-zone -f auto-zone.cfg


I modified the file with vi to update the IP address information, zonepath and zonename properties.

root@sandbox:/# zonecfg -z auto-zone info net
net:
        address: 192.168.87.144/24
        physical: e1000g0
        defrouter: 192.168.87.2
root@sandbox:/# zonecfg -z auto-zone info zonepath
zonepath: /zones/auto-zone
root@sandbox:/# zonecfg -z auto-zone info zonename
zonename: auto-zone

I also removed a loopback file system by invoking the remove sub-command with the fs property.

zonecfg:auto-zone> remove fs


I then installed the zone. This is a sparse root zone so the installation was quick.

root@sandbox:/# zoneadm list -icv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   3 test-zone        running    /zones/test-zone               native   shared
   - auto-zone        configured /zones/auto-zone               native   shared
root@sandbox:/# zoneadm -z auto-zone install
A ZFS file system has been created for this zone.
Preparing to install zone <auto-zone>.
Creating list of files to copy from the global zone.
Copying <7503> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <1098> packages on the zone.
Initialized <1098> packages on zone.
Zone <auto-zone> is initialized.
The file </zones/auto-zone/root/var/sadm/system/logs/install_log> contains a log of the zone installation.
root@sandbox:/#  zoneadm list -icv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   3 test-zone        running    /zones/test-zone               native   shared
   - auto-zone        installed  /zones/auto-zone               native   shared

Now with that done go the /zones/auto-zone/root/etc/ directory.

root@sandbox:/# cd /zones/auto-zone/root/etc/

This will serve as the /etc directory for the zone and here we create our sysidcfg file and populate it.

root@sandbox:/zones/auto-zone/root/etc# vi sysidcfg

root@sandbox:/zones/auto-zone/root/etc# cat sysidcfg
system_locale=C
keyboard=US-English
terminal=xterms
network_interface=primary {
                hostname=auto-zone
}
security_policy=NONE
name_service=NONE
nfs4_domain=dynamic
timezone=Asia/Calcutta
root_password=Spectre_007
root@sandbox:/zones/auto-zone/root/etc# cd

Once done, change to a global zone directory and boot the zone.

root@sandbox:/# zoneadm -z auto-zone boot

The zone will now be in running state.

root@sandbox:/#  zoneadm list -icv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   3 test-zone        running    /zones/test-zone               native   shared
   4 auto-zone        running    /zones/auto-zone               native   shared
root@sandbox:/#

We need to give a minute or two to the system to apply the settings mentioned in the sysidcfg file. I waited for 2 minutes and then logged in to do a couple of snaity checks.

root@sandbox:/# zlogin auto-zone
[Connected to zone 'auto-zone' pts/4]
Last login: Mon Oct  2 22:32:10 on pts/4
Sun Microsystems Inc.   SunOS 5.10      Generic January 2005
# echo $TERM
xterm
# svcs -xv
svc:/application/print/server:default (LP print server)
 State: disabled since Mon Oct 02 22:23:08 2017
Reason: Disabled by an administrator.
   See: http://sun.com/msg/SMF-8000-05
   See: man -M /usr/share/man -s 1M lpsched
Impact: 2 dependent services are not running:
        svc:/application/print/rfc1179:default
        svc:/application/print/ipp-listener:default
# who -r
   .       run-level 3  Oct  2 22:23     3      0  S
# ifconfig -a
lo0:2: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
e1000g0:3: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet 192.168.87.144 netmask ffffff00 broadcast 192.168.87.255
#
# date
Mon Oct  2 22:35:15 IST 2017
#


As expected the system was functional and accessible from the network.

Here are two more useful sample sysidcfg files for consideration:

Sysidcfg file for SPARC systems:

keyboard=US-English
system_locale=en_US
timezone=US/Central
terminal=sun-cmd
timeserver=localhost
name_service=NIS {domain_name=marquee.central.example.com
                  name_server=nmsvr2(172.31.112.3)}
nfs4_domain=dynamic
root_password=m4QPOWNY
network_interface=hme0 {hostname=host1 
                       default_route=172.31.88.1 
                       ip_address=172.31.88.210 
                       netmask=255.255.0.0 
                       protocol_ipv6=no}
security_policy=kerberos {default_realm=example.com 
                          admin_server=krbadmin.example.com 
                          kdc=kdc1.example.com, 
                          kdc2.example.com}
  
  

Sysidcfg file for zones with multiple interfaces:
  
timezone=US/Pacific
system_locale=C
terminal=xterms
timeserver=localhost
network_interface=eri0 {primary
                        hostname=host1
                        ip_address=192.168.2.7
                        netmask=255.255.255.0
                        protocol_ipv6=no
                        default_route=192.168.2.1}

network_interface=eri1 {hostname=host1-b
                        ip_address=192.168.3.8
                        netmask=255.255.255.0
                        protocol_ipv6=no
                        default_route=NONE}
root_password=JE2C35JGZi4B2
security_policy=none
name_service=NIS {domain_name=domain.example.com
                  name_server=nis-server(192.168.2.200)}
nfs4_domain=dynamic

No comments:

Post a Comment

Using capture groups in grep in Linux

Introduction Let me start by saying that this article isn't about capture groups in grep per se. What we are going to do here with gr...