KNOW-HOWHercules Mainframe EmulatorHercules mainframe emulatorBIG BOXESKirsty Pargeter, FotoliaMany enterprises still rely heavily on mainframes, which makes it all the more difficult to get your hands onone and install Linux on it. The Hercules emulator gives you a full-fledged alternative.BY BERNHARD BABLOKMainframes commonly are regarded as being reliable, butalso big, complicated, pricey,and outmoded in today’s IT landscapes.Here, the Hercules mainframe editor,which emulates the CPU architecture,can help. Even if Linux is running in aproduction environment on a mainframe, Hercules still can provide a usefulservice for testing and development.In this article, I will describe how toset up and configure Hercules and itsvirtual hardware, and then I will focuson installing zLinux on Hercules. Finally,I’ll take a quick look at z/OS – the nativemainframe operating system – and itsfreely available predecessor MVS.Hercules 3.04 does not support currentzLinux variants, which is why youshould download the current sourcecode for version 3.05 [1]. The RPM, alsoavailable from the homepage, will installbut does not support network connec-tions, making it unsuitable for the purposes of this article.In a directory of your choice (e.g.,/usr/local/src), unpack the sources,change to the /usr/local/src/hercules-3.05directory, and enter configure as shownin Listing 1. After doing so, don’t forgetto check config.log, paying particular attention to whether Zlib support is available. If the zlib-devel package is not installed on SUSE, you will still be able tobuild and use Hercules, but you will notbe able to use the typical Zlib compressed virtual hard disks.After completing the configurationphase, follow the normal make and su -c"make install" procedure. Now Herculesis installed, but some manual finishingwork is necessary. The HTML-formatteddocumentation is available in /usr/local/share/hercules, with links to additionalresources on the Internet; if you run intodifficulty, try the mailing list.If you will be using TCP/IP networking with a Hercules guest system, it is54MAY 2008Download and InstallationISSUE 90important to configure the host systemcorrectly. First, you need to modify theprivileges for the /usr/local/bin/hercifcscript, which configures the Tun/Tapnetwork device when Hercules starts up.Just as for any direct device access, youneed root privileges for this. The --enable-setuid-hercifc configure option (seeListing 1, line 9) sets the SUID bit, butthe installation script sets group ownership for the file to root, making it impossible to execute the script as a non-privileged user. The following lines will setthe permissions correctly:# chgrp users U/usr/local/bin/hercifc# chmod 4750 U/usr/local/bin/hercifcThe following sections only apply toopenSUSE systems; some details willvary for other operating systems. For thenetwork connection, Hercules uses theTun/Tap device; on a normal system, the

Hercules Mainframe EmulatorAt system launch time, /etc/init.d/boot.udev copies a number of devices from /lib/udev/devices to /dev, so you willneed to delete the Tun devicein this directory or modify itspermissions:chgrp users U/lib/udev/devices/net/tunchmod 660 U/lib/udev/devices/net/tunNetwork PreparationThe Tun/Tap device supports apoint-to-point connection between the host and the guest,which other virtualization soFigure 1: A throwback to the good old days: an IBMlutions call host-only network1403 line If you want to grant theguest system access to thedevice is owned by root:root and has perlocal network – or even the Internet –missions of 0600. Again, this rules outyou also will need to set up NAT. To doaccess by normal users. However, changso, first enable IP forwarding, either pering the permissions manually will not domanently in /etc/sysconfig/sysctl (IPyou much good because the original staFORWARD yes) or manually:tus is restored when you reboot.echo "1" UUdev is used for device management/proc/sys/net/ipv4/ip forwardon today’s systems, which is why youwill need to modify the correspondingThen use iptables to define two rules:Udev rule. On an openSUSE system,the /etc/udev/rules.d/50-udev-default.iptables -t nat -A POSTROUTING Urules file controls this, and you must-o eth0 -j MASQUERADEadd:KERNEL "tun", GROUP "users", UNAME "net/%k",MODE "0660"To give /dev/net/tun the right permissions, type rm /dev/net/tun and modprobe tun. If the device still has incorrectpermissions after a reboot, don’t worry.Listing 1: Building Hercules:Configure Arguments01 #!/bin/bash0203 PREFIX /usr/local0405 ./configure --prefix PREFIX \06--enable-cckd-bzip2\07--enable-optimization yes \08--disable-external-gui \09--enable-setuid-hercifciptables -A FORWARD -i Utun0 -j ACCEPTKNOW-HOWHercules supports emulated printers,there are no Linux drivers for the old,line-oriented 1403 printer (Figure 1).However, this is not a major drawback;you can print over the network to thehost’s CUPS server or to any other printserver available on the network.The virtual hardware is defined in aconfiguration file (Listing 2), which ispassed in to the emulator with the -f option when it’s launched. Hercules doesnot impose any restrictions with respectto the name and directory structure. Depending on your personal preferences,you can store all your files in a singledirectory or organize them in subdirectories by file type.Virtual hard disks are normal files, aswith any other emulator. In IBM speak,hard disks are referred to as DASDs (fordirect-access storage devices). To createhard disks for your zLinux installation,enter:dasdinit -z -lfs Udasd/sys1.dasd 3390-3 SYS1dasdinit -z -lfs Udasd/sys2.dasd 3390-3 SYS2The -z option configures Zlib compression. Alternatively, you could select -bz2for Bzip2 compression; note that themethod is slower, and thus means performance hits without giving you majordisk space savings. The -lfs option refersThis completespreparation of thehost system. Nextcomes creating andconfiguring thevirtual hardware.VirtualHardwareHercules supports awhole bunch of virtual hardware components, but youjust need some harddisks and a networkconnection forzLinux. Becausethis is a high-endserver system,video, audio, andUSB support are irrelevant. AlthoughFigure 2: The Hercules console showing the supported features onstartup.MAY 2008ISSUE 9055

KNOW-HOWHercules Mainframe EmulatorListing 2: Hercules Configuration for CentOS 4.501 #17 TZOFFSET 000002 # Configuration file for Hercules & CentOS 4.5s39018 OSTAILORLINUX# OS tailoring19 PANRATESLOW# Panel refresh rate03 #20 ARCHMODE ESAMEESA/390 or ESAME0405 MODPATH {MODPATH HERCULES: /usr/local/lib/hercules}21 PGMPRDOS0623RESTRICTED2207 CPUSERIAL 00262324 # Device list08 CPUMODEL209625 # ---09 MAINSIZE780# Expanded storage size in11 CNSLPORT 3270consoles connect# TCP port number to which12 HTTPROOT {HTTPROOT HERCULES: /usr/local/share/hercules/}13 HTTPPORT9091# HTTP server14 NUMCPU1# Number of CPUs16 SYSEPOCH020304050607--------------------27 # DASD2829 0A01 3390dasd/sys1.dasd30 0A02 3390dasd/sys2.dasd3132 # Channel to channel: CTCIip-linux-hostip-linux-guest33# Vector facilities34 0cc0.2 3088 CTCI large file support; that is, dasdinitwill not split up the hard disk into 2GBchunks. Depending on your DASD size,you might want to omit this option soyou can store files on DVD media.The file names (dasd/sys?.dasd) arearbitrary. The hard disk type (3390-3)defines the size, which is about 2.7GB inmy example. The Hercules documenta-01----2610 XPNDSIZE 0megabytes15 NUMVEC1emulated# Architecture mode S/370,tion gives you a list of available typesand their respective sizes [2].The last parameter for dasdinit, theVOLSER name (the disk label), really isnot necessary for Linux, but the installation writes the label anyway. As a finalstep, the administrator needs to add thedisks to the Hercules configuration file(Listing 2, lines 29-30), thereby assign-ing the device addresses for Linux toreference the disks.Network InterfaceHercules emulates various types of network connections. The easiest type toconfigure is the channel-to-channel(CTC) connection. To configure twotype-3088 CTC devices at the addresses0cc0 and 0cc1, you just need toadd one line to the configurationListing 3: Verifying the Network Configurationfile (Listing 2, line 34), and assign[[email protected]: ] # route -nan address of to theKernel IP routing tableguest and to the host.DestinationGatewayGenmaskFlags Metric RefUse IfaceThe HTML documentation explains192. UH000 tun0the syntax for the device particular.To launch Hercules, type the127. locommand:[[email protected]: ] # ifconfig08 eth0.hercules -f conf/ Ucentos45.conf U hercules.log0910 lo.1112 tun0Link encap:UNSPEC -0013inet addr: POINTOPOINT RUNNING15RX packets:0 errors:0 dropped:0 overruns:0 frame:016TX packets:0 errors:0 dropped:0 overruns:0 carrier:017collisions:0 txqueuelen:50018RX bytes:0 (0.0 b)56ISSUE 90P-t-P: bytes:0 (0.0 b)MAY 2008Mask: 2 shows the initial outputat the Hercules console. Here, thecritical message is HHCCT073I,which tells me that the tun0 network device is open. Unfortunately, the message isn’t completely reliable because it dependson the permissions for hercifc; tobe certain, you have to check

Hercules Mainframe Emulatorthe output from route -n and ifconfig(Listing 3).Both the routing table (line 4ff.) andthe network configuration (lines 29-35)must have entries for the tun0 device.Using HerculesThe Hercules console is used to controlthe system. Hercules supports a largenumber of commands, the most important of which is ipl (initial programload), which initiates the boot process.The maxrates command is useful, too; itoutputs the performance in MIPS (million instructions per second).Hercules supports alternate consoles.Pressing the Esc key toggles between theline-oriented console shown in Figure 1and the semi-graphic console shown inFigure 3. This view gives you the currentperformance data, and you can see theregister values flash past.To run Hercules remotely, you also canuse an http console (Figure 4), whichthe administrator must set up in the configuration file (Listing 2, lines 12-13).Also, you can set up username- andpassword-based authentication, but thisdoes not change the fact that the httpconnection is insecure.KNOW-HOWListing 4: Installation of zLinux: First Phase001 Which kind of network device do you intend to use:002 .ctc003 Enter the bus ID and the device number of your CCW devices.004 CTC/ESCON and LCS need two subchannels:005 (e.g. "0.0.0600,0.0.0601" will configure the CTC or ESCON interface006 with the subchannels 0x600 and 0x601)007 QETH needs three subchannels p.e. 0.0.0300,0.0.0301,0.0.0302008.0.0.0cc0,0.0.0cc1009 Enter the FQDN of your new Linux guest (e.g. Enter the IP address of your new Linux guest: Enter the network address of the new Linux guest: Enter the IP of your CTC / ESCON / IUCV point-to-point partner: Select which protocol should be used for the CTC interface018 0 for compatibility with p.e. VM TCP service machine (default)019 1 for enhanced package checking for Linux peers020 3 for compatibility with OS/390 or z/OS peers021.0022 Enter your DNS server(s), separated by colons (:): Enter your DNS search domain(s) (if any), separated by colons (:):025.Installing zLinux026 Enter DASD range (e.g. 200-203Mainframes support two system architectures: zLinux with 31 bits (s390) andzLinux with 64 bits (s390x). Only theaddressing is 31 bits for the 31-bit variant; the data itself uses the full 32 bits.If you are looking for a free 64-bitzLinux, you can go for either the ThinkBlue/64 Linux [3] or the newer CentOS4.5 [4], which is the distribution I usedfor this article.Debian offers a good alternative;the 31-bit architecture is maintainedthroughout the Debian releases. I will027 Press Enter for autoprobing (not recommended):028or200,201,202,203).0a01-0a02029030 Starting telnetd and sshd to allow login over the network.031032 Connect now to to start the installation.not cover the differences between theDebian and CentOS installations.Installation StepsInstallation of CentOS on the mainframecan be done across thewire. Because mainframes and Hercules donot support CD drives,it is necessary to exportthe mounted DVD viaNFS or copy the contentof the DVD to an exported directory. Typingipl /cdrom/generic.insboots the system at theHercules console.Going forward, youshould see normalFigure 3: The semi-graphic Hercules with its colorful console.MAY 2008Linux boot messages flash across yourscreen. Launching the network configuration program, which prompts you forthe information required to set up a connection, comes next. Listing 4 shows themessages and responses. Note that theHercules console passes commands thatstart with a dot through to the runningsystem.After completing this phase, the message shown in line 32 will appear. Nowyou can establish an SSH connection tothe guest address, which takes you tothe CentOS standard installation tool,Anaconda. After changing a few settingsand mounting the installation source viaNFS, everything should fall into place.Because the virtual network connectionis not very fast, you can expect the sys-ISSUE 9057

KNOW-HOWHercules Mainframe Emulatortem to be busy configuring itself for thenext hour or so.With a real mainframe, on which youcan opt between HMC (hardware management console) and bootable tapes orprepare a volume for zLinux z/OS-side,this process looks very different.After the InstallationThe ipl command will boot an installedsystem on Hercules. As a parameter,Hercules expects the boot volume address (ipl 0a01, in my example). AfterIPL, a grub-style boot menu appears, although the system automatically willboot after waiting 15 seconds. The console shows typical startup messages fora (Red Hat) Linux system up until thelogin prompt. Working directly at theconsole is impractical because it meanstyping a dot in front of every commandand because some programs will not runat the console. The use of an SSH connection from a different machine makesmore sense.Dynamically Adding DisksIn principle, zLinux is no different fromLinux on any other platform, except forthe way it handles hardware. The following example mounts another disk in/home on the system, but first you mustgenerate the new disk (file dasd/home.dasd). Hercules emulates a high-availability system; the administrator doesnot shut down zLinux but does use theHercules console tointroduce the newdevice:attach 0a03 U3390 dasd/Uhome.dasdOn the zLinuxpage, typing lsdasd-s -a shows a list ofavailable DASD devices; you can seethat a new deviceFigure 4: The clear-cut Hercules web available, but offline. Whereas a mainframe operatorIf you are setting up multiple partitions,would now type vary online, root wouldyou need to call fdasd without the -ado this:parameter, which takes you to an fdiskstyle partitioning menu.echo 1 /sys/bus/ccw/UIn the example, you will be using thedrivers/dasd-eckd/Uwhole volume as a large partition; how0.0.0a03/onlineever, the new device is lost on rebooting.To prevent this, you need to add a lineA quick check with lsdasd and a peekfor the device to the Hercules configuraat the /dev directory show that a dasdction file and add a mount entry in /etc/now exists.fstab.Now you need to low-level format andThe dasd mod kernel module expectspartition the device: dasdfmt handles thethe available devices as a start option; afirst of these tasks, and fdasd handleschange to /etc/modprobe.conf takes carethe second:of this:dasdfmt -p -v -l HOME01 -b U4096 -d cdl -f /dev/dasdcfdasd -a /dev/dasdcmke2fs -j /dev/dasdcmount /dev/dasdc /homeoptions dasd mod Udasd 0a01-0a03To start the system, you need a new Initrd. If you want to be on the safe side,The Mainframe PrincipleAlthough Linux still relies on variousschedulers to ensure fair and optimumresource usage, the mainframe worldhas gone its own way. On a mainframe,users specify the resources they need,which enables the system to decidewhether the program should run now,later, or not at all. Listing 5, a classiccopying program, looks fairly complicated compared with the cp command,but complexity has both disadvantagesand advantages.Jobs on a mainframe are not much morethan a stack of punch cards shifted to afile. The job printed here starts with a jobcard that specifies the memory, run time,and job class, which makes it fairly easyto prioritize. Next comes the copyingprogram, IEBGENER, and its parameters.Host programs use logical filenames toaccess files; for IEBGENER, these names– defined by DD (data definition) cards –58ISSUE 90SYSUT1 (line 5), the input file, is designated as “OLD” – which means that youneed the file exclusively. If another job isprocessing this file, your job will have towait. An alternative to this is DISP SHR,which allows shared (read) access (andmight be a more realistic alternative fora copying program).Optimization entails additional effort. Inthe past, when mainframes were muchsmaller, this kind of safeguard was moreimportant, whereas today’s mainframesinclude options that simplify the process.The goal of maximizing use has notchanged. Utilization values of 90 percentfor 24x7 operations are possible, andthey make financial sense.Note the specification of the target file inlines 6-9. (NEW,CATLG) stipulates thatthe file must not exist and that it shouldbe cataloged after successful processing.If the file exists, the job will not run. Theother details specify the space requirements (primary 5 cylinder, additionallyup to 15 times 2 cylinders) and the physical file format. On Linux, a rogue program can completely fill up the filesystem; on a mainframe, the program isstopped if it oversteps its space assignment.The protocol that mainframe terminalsuse to communicate with the host provides another example of maximumresource utilization. Physical terminalsno longer exist; programs such as x3270emulate the protocol. In contrast to Unixkeyboard drivers, which process everysingle key press, the user of a 3270 terminal fills out all the fields on the screenand then transmits everything at once.This reduces the number of processingsteps, at the cost of making programssuch as Vi or Emacs impossible to run.are SYSUT1 and SYSUT2.MAY 2008

KNOW-HOWHercules Mainframe Emulatoryou might want to copy the existing Initrd and add an entry to the boot menuin /etc/zipl.conf, to be able to launch theprevious version in case of an error:cd /bootmv initrd-2.6.9-55.EL.img Uinitrd-2.6.9-55.UEL.img.origmkinitrd -v initrd-2.6.9-55.EL.Uimg 2.6.9-55.ELvi /etc/zipl.conf# - Modify to load the Uoriginal initrdzipl -VThis procedure is something like the legacy Linux bootloader, lilo, in which youneeded to launch the lilo program aftermodifying the configuration file.Shadow Files Instead ofSnapshotsHercules does not use snapshots likeother virtualization programs, but itdoes implement shadow files, which canbe put to similar use. To use a shadowfile, you need to change the lines withthe hard disk configuration slightly (Listing 2, line 29ff.):0A01 3390 dasd/sys1.dasd ro Usf shadow/sys1 *.dasd0A02 3390 dasd/sys2.dasd ro Usf shadow/sys2 *.dasdAfter starting, Hercules automaticallywrites the shadow/sys? 1.dasd files. Thesf * command at the Hercules consolecreates a new set of shadow files, up toa maximum of eight files. sf- * merge orsf- * nomerge accepts or discards thechanges to the current shadow step.Accepting means that sf- merge writesthe changes from, for example, sys12.dasd to sys1 1.dasd. To write changesto the original files, you must specify sf* force (or omit the read-only option ro).The Hercules suspend and resumecommands save and restore the complete system state; however, this mechanism does not work reliably – zLinuxwill not work after you use it.z/OS and MVSFrom a Linux perspective, the mainframeis just one architecture out of many, so itmakes sense to look at the operating systems that normally run on mainframes.On the current crop of systems, the operating system is z/OS 1.x. (Version 1.9was released in September 2007.)Unfortunately, z/OS is not free. Although there is an “ADCD” package fordevelopers and a z/OS demo package,you at least need to lease an IBM machine to use it legally. This just leavesthe granddaddy of today’s z/OS, MVS(version 3.8), as an alternative for experimenting at home.MVS (Multiple Virtual Storage) wasdeveloped from earlier IBM operatingsystems; its direct predecessor is the OS/360 MVT (Multitasking with a Variablenumber of Tasks) variant. MVS then became the operating system for the nextgeneration of hardware, the System/370computer, which supported virtualmemory as of 1972.Interestingly, the older S/360-67 models did support virtual memory, but atthe time, batch processing was regardedas far more important and hardware support for memory virtualization was thusomitted from the S/370 series.MVS was released in 1974 and led directly via MVS/XA, MVS/ESA, and OS/390 to z/OS. Now MVS is freely avail-Listing 5: Copying a File with IEBGENER01 //MYJOB02 //03 //COPYJOB (COPY),'COPY',CLASS A,MSGCLASS A,REGION 256K,TIME 5,MSGLEVEL (1,1),NOTIFY HERC0404 //SYSPRINT DD SYSOUT *DD DISP OLD,DSN HERC04.DATEI206 //SYSUT2DD DSN HERC04.FILE2.BAK,DISP (NEW,CATLG),07 //UNIT SYSDA,VOL SER PUB002,08 //SPACE (CYL,(5,2,0)),09 //DCB (RECFM FB,LRECL 80,BLKSIZE 4096,DSORG PS)10 //SYSINConclusionsHercules offers a stable emulator formainframe architecture. Running on apowerful midrange system, the performance should be sufficient to replace azLinux test LPAR. If you are thinkingof porting your software to zLinux, youcan use Hercules or the CommunityDevelopment System for Linux (LCDS),a service provided by IBM [9]. INFO[1] Hercules:[2] Conversion table for DASD sizes: capacity.html[3] ThinkBlue/64 Linux for zSeries:[4] CentOS:[5] MacIsaac, Michael, Ronald Annuss,Wolfgang Engel, et al. Linux for IBMeServer zSeries and S/390: Distributions. Redbooks, 46264.pdf[6] Linux Redbook rtals/LinuxEXEC PGM IEBGENER05 //SYSUT1able because operating systems at thetime were distributed openly.A “turnkey” MVS system is availablefor Hercules: the MVS Turnkey System[7][8]. The only additional software youneed is a 3270 terminal emulator; Linuxusers can install the x3270 package thatcomes with their distributions.If you think you can set up a mainframe system quickly and start using it,you will be disappointed. Although youcan boot and down the system using the“Cookbook” [8], it will not help youmuch if you do not have any previousmainframe experience. If you are seriously interested in immersing yourselfin this material and working your waythrough the available documentation –including the current z/OS documentation, which is freely available from IBM– you will enjoy the experience of yourown mainframe.[7] The MVS 3.8j Turnkey[8] Information about the MVS TurnkeySystem:[9] Community Development System forLinux (LCDS): DUMMYMAY 2008ISSUE 9059

Hercules mainframe emulatorBIG BOXES KNOW-HOW Hercules Mainframe Emulator 54 ISSUE 90 MAY 2008 Kirsty Pargeter, Fotolia 054-059_hercules.indd 54 12.03.2008 11:22:10 Uhr. device is owned by root:root and has per-missions of 0600 . Again, this rules out access by normal users. H owever, chang-