Dynamic Zone changes
By menno on Mar 10, 2005
This subject has come up several times in the last two weeks, so it might be a good opportunity to finally start using my blog.
When talking to a colleague about Zones he said: 'I have been looking at Zones and while they are cool, they are also "static". To add an extra file system to a running zone I have to restart the zone.'. Well, as it happens, this is not required. You can dynamically add a file system to a running zone. Here's how:
The current configuration of the running zone looks like this:
# zonecfg -z zone1 info zonepath: /export/zones/zone1 autoboot: true pool: large inherit-pkg-dir: dir: /lib inherit-pkg-dir: dir: /platform inherit-pkg-dir: dir: /sbin inherit-pkg-dir: dir: /usr net: address: 220.127.116.11/26 physical: hme0 rctl: name: zone.cpu-shares value: (priv=privileged,limit=10,action=none)
Adding a new UFS file system to this zone would entail the following: create a new file system in the global zone, add an fs resource to the zone configuration and restart the zone to re-read the configuration.
global # newfs /dev/md/rdsk/d100 newfs: construct a new file system /dev/md/rdsk/d100: (y/n)? y Warning: 1280 sector(s) in last cylinder unallocated /dev/md/rdsk/d100: 1024000 sectors in 712 cylinders of 15 tracks, 96 sectors 500.0MB in 45 cyl groups (16 c/g, 11.25MB/g, 5440 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 23168, 46304, 69440, 92576, 115712, 138848, 161984, 185120, 208256, 806720, 829856, 852992, 876128, 899264, 922400, 945536, 968672, 991808, 1014944, global # zonecfg -z zone1 zonecfg:zone1> add fs zonecfg:zone1:fs> set dir=/u01 zonecfg:zone1:fs> set special=/dev/md/dsk/d100 zonecfg:zone1:fs> set raw=/dev/md/rdsk/d100 zonecfg:zone1:fs> set type=ufs zonecfg:zone1:fs> end zonecfg:zone1> exit
At this point we could reboot the zone and have the new file system mounted during zone boot. However, there is no need to restart the zone because the file system can be mounted into the running zone from the global zone. The only thing we have to do now is add the mountpoint in the zone ourselves:
global # mkdir /export/zones/zone1/root/u01 global # mount /dev/md/dsk/d100 /export/zones/zone1/root/u01
Note that there is an extra /root/ component in the path to the file system. Inside the zone we see that the new file system has appeared:
zone1 # df -h Filesystem size used avail capacity Mounted on / 15G 3.3G 11G 23% / /dev 15G 3.3G 11G 23% /dev /lib 15G 3.3G 11G 23% /lib /platform 15G 3.3G 11G 23% /platform /sbin 15G 3.3G 11G 23% /sbin /usr 15G 3.3G 11G 23% /usr proc 0K 0K 0K 0% /proc ctfs 0K 0K 0K 0% /system/contract swap 8.3G 264K 8.3G 1% /etc/svc/volatile mnttab 0K 0K 0K 0% /etc/mnttab fd 0K 0K 0K 0% /dev/fd swap 8.3G 0K 8.3G 0% /tmp swap 8.3G 32K 8.3G 1% /var/run /u01 469M 1.0M 421M 1% /u01
But wait, there's more. The same 'magic' can be applied to add an extra network interface to a running zone. Instead of adding a net resource to the zone configuration and then rebooting the zone, we add the net resource to the zone configuration (to make the change persistent) and then use ifconfig(1M) from the global zone to add the network interface dynamically.
global # zonecfg -z zone1 zonecfg:zone1> add net zonecfg:zone1:net> set physical=hme0 zonecfg:zone1:net> set address=192.168.1.13/24 zonecfg:zone1:net> end zonecfg:zone1> exit global # ifconfig hme0 addif 192.168.1.13 netmask + broadcast + zone zone1 up Created new logical interface hme0:3 Setting netmask of hme0:3 to 255.255.255.0
The key point here is the 'zone' option of ifconfig. Running ifconfig -a inside the zone shows that we now have the extra network interface. And without having to reboot the zone!
zone1 # ifconfig -a lo0:5: flags=2001000849
mtu 8232 index 1 inet 127.0.0.1 netmask ff000000 hme0:2: flags=1000843 mtu 1500 index 2 inet 18.104.22.168 netmask ffffffc0 broadcast 22.214.171.124 hme0:3: flags=1000843 mtu 1500 index 2 inet 192.168.1.13 netmask ffffff00 broadcast 192.168.1.255
There are more things that can be changed dynamically such as resource controls and pool binding. I'll leave that for another blog entry.
So: Zones are cool and dynamic!