04
Mon, Nov
1 New Articles

TechTip: IFS Containers Part 2, Automation with IBM i Chroot

General
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Automation wins in the end. IFS Containers have automation as a first class citizen.

In the first article of this series, I discussed what IFS Containers are and how they use the chroot command to implement the container concept. To create the IFS Container, we had to manually create directories and copy files. That wasn't a big deal for the small example we created, but imagine if you needed to create an IFS Container for an entire PASE application that had requirements for hundreds of directories, commands, and libraries. This is where automation becomes a necessity, and more specifically, the IBM i Chroot open-source project.

The IBM i Chroot project (ibmichroot) is a collection of shell scripts, configuration files, and binaries stored as a Git repo on Bitbucket.org and exists to serve two purposes. First, it is used to automate the creation of IFS Containers. Second, it houses multiple methods for easily retrieving open-source software from the web and installing it on your IBM i. In this article, we'll be focusing on the automation of creating IFS Containers.

The first thing you'll want to do is install ibmichroot on your machine. You could install licensed program 5733OPS option 3, but I wouldn't recommend it because it will always be behind in features. Some of the things talked about in this article have been created in the past month and haven't yet been placed into a 5733OPS option 3 update. I'd instead recommend you obtain the project directly from Bitbucket using one of the following methods.

If you already have Git installed on your machine, you can run the following two commands.

$ cd /QOpenSys

$ git clone This email address is being protected from spambots. You need JavaScript enabled to view it.:litmis/ibmichroot.git

The second approach works well if you don't have Git installed. Go to the IBM i Chroot project's download page, select the "Download Repository" link, save it to your PC, and unzip it. You should end up with a directory with a name similar to litmis-ibmichroot-1a82e1ebbc70. Rename it to ibmichroot and upload it via FTP to directory /QOpenSys on your IBM i.

At this point, you have ibmichroot installed on your IBM i in /QOpenSys/ibmichroot, and there are no further steps for installing the tool.

Now we can now start creating our own IFS Containers, but first we should create a directory to store them. I usually put them in /QOpenSys/ibmichroot_containers, so we'll also do that in this tutorial.

$ mkdir /QOpenSys/ibmichroot_containers

Now it's time to create our first IFS Container using the chroot_setup.sh script. First, go into the chroot directory using the following command.

$ cd /QOpenSys/ibmichroot/chroot

Use the ls command to learn what is contained in this directory.

$ ls

README.md                       chroot_ZendServer5.lst         chroot_gen_OPS_Python2.7.lst   chroot_nls.lst

chroot_OPS_GCC.lst             chroot_ZendServer6.lst         chroot_gen_OPS_Python3.4.lst   chroot_setup.sh

chroot_OPS_NODE.lst             chroot_bins.lst                 chroot_gen_OPS_cloudinit.lst   chroot_system.lst

chroot_OPS_PYTHON.lst           chroot_chown.sh                chroot_gen_OPS_tools.lst       chroot_template.lst

chroot_OPS_PYTHON2.lst         chroot_gen_OPS_GCC.lst         chroot_includes.lst             chroot_xlc.lst

chroot_OPS_SC1.lst             chroot_gen_OPS_Node4.lst       chroot_libs.lst                 gen_chroot_OPS_lst

chroot_PowerRuby.lst           chroot_gen_OPS_Orion.lst       chroot_minimal.lst             ibmichroot_containers

chroot_ZendDBi-5.1.59.lst       chroot_gen_OPS_Python-pkgs.lst

In this directory listing, we see a couple of important things. First, the chroot_setup.sh script, which will be used to create a new IFS Container, and also files ending in .lst. These are IFS Container configuration files that describe all of the things that should be done to either create or update an IFS Container. In this case, we want to create a very simple IFS container, so we'll focus on the chroot_minimal.lst configuration and run the following command.

$ chroot_setup.sh chroot_minimal.lst /QOpenSys/ibmichroot_containers/c1

The chroot_setup.sh script accepts a number of parameters. The first parameter is the configuration file we want to use, and the second is the location of the IFS Container directory. In this case, we're calling the new IFS Container "c1". You can call it whatever you want and create as many as you want. Another convention I've used with customers is to name them according to who owns them and what they're used for. For example, /QOpenSys/ibmichroot_containers/aaron-appname-development would be a container for me, for a specific application, and specifically for development purposes, as compared to it being an IFS Container for production deployment.

After you hit Enter on the chroot_setup.sh script above, you'll see many log messages being sent out to the screen. Below is an abbreviated sampling of the logs.

**********************

Live IBM i session (changes made).

**********************

PATH=/QOpenSys/usr/bin:/QOpenSys/usr/sbin:/opt/freeware/bin

LIBPATH=/QOpenSys/usr/lib:/opt/freeware/lib

mkdir -p /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/sbin

mkdir -p /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

mkdir -p /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/lib

. . .

mknod /QOpenSys/ibmichroot_containers/c1/dev/tty c 32945 0

mknod /QOpenSys/ibmichroot_containers/c1/dev/null c 32769 1

mknod /QOpenSys/ibmichroot_containers/c1/dev/zero c 32769 2

mknod /QOpenSys/ibmichroot_containers/c1/dev/urandom c 32954 0

. . .

cp /QOpenSys/usr/sbin/chroot /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/sbin/chroot

cp /QOpenSys/usr/sbin/dbx_server /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/sbin/dbx_server

cp /QOpenSys/usr/sbin/dump /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/sbin/dump

. . .

chroot /QOpenSys/ibmichroot_containers/c1 ln -sf /QOpenSys/usr/sbin /sbin

chroot /QOpenSys/ibmichroot_containers/c1 ln -sf /QOpenSys/usr/bin /bin

chroot /QOpenSys/ibmichroot_containers/c1 ln -sf /QOpenSys/usr/lib /lib

. . .

============

chroot command:

> chroot /QOpenSys/ibmichroot_containers/c1 /bin/bsh

chroot ssh profile (optional):

> mkdir -p /QOpenSys/ibmichroot_containers/c1/home/MYPROF

> CHGUSRPRF USRPRF(MYPROF) LOCALE(*NONE) HOMEDIR(/QOpenSys/ibmichroot_containers/c1/./home/MYPROF)

   '/./home/MYPROF' is required auto ssh login chroot (IBM i hack)

other useful settings chroot (optional):

> $PS1='dev$ '

> LANG=C

> LANG=819

At this point, the new IFS Container has been created successfully. It's important to note the amount of automation that occurred and how much time it saved by my not having to type those things in by hand. Specifically, compare this to the first article in this series that had us manually creating directories and copying files.

Now it's time to enter the IFS Container by using the PASE chroot command. This is the same way we entered the IFS Container in the first article.

$ chroot /QOpenSys/ibmichroot_containers/c1 /usr/bin/sh

$ pwd

/

$ ls

QOpenSys bin       dev       home     lib       sbin     tmp       usr       var

$ exit

In the above series of commands, the first thing I did was enter the IFS Container by issuing the chroot command with two parameters: the directory location of my IFS Container and the command to run when I am placed inside the IFS Container. By specifying /usr/bin/sh, I am declaring I want to enter into an interactive shell. I could have instead declared I only wanted to run a command inside the IFS Container and then immediately exit. This type of "run a command and leave" was used extensively during the creation of the IFS Container to create things like symbolic links, which are highly relative to the environment they're created in.

After the chroot command completes, I am at that time inside my IFS Container. Running the pwd (print working directory) command conveys where I am in the file system within my IFS Container. Note that I had previously changed the directory to /QOpenSys/ibmichroot/chroot when I was outside the IFS Container. When I enter an IFS Container, I am initially placed at the root of the file system unless the IFS Container is configured otherwise. Running the ls command displays the contents of the IFS Container's root directory. Only the directories that were specified to be created in chroot_minimal.lst exist inside the IFS Container. Notice that QSYS.LIB doesn't exist in here. You can't have a QSYS.LIB file system inside an IFS Container, though you are still able to access the QSYS.LIB file system using a variety of tools, including database adapters, iToolKits, and other utilities. The last thing I do is issue the exit command to return back to my previous shell session and exit the IFS Container.

At this point, the IFS Container is fully functional, but it might still be lacking features required to meet your business need. For example, more than likely you'll need things like OpenSSL and OpenSSH inside your IFS Container so you can do encrypted communication to sites like GitHub or Bitbucket for source change management. Another cool feature of the chroot_setup.sh script is it can apply multiple configuration files to the same IFS Container. For example, below we're applying the chroot_OPS_SC1.lst configuration file, which contains IBM's SC1 licensed program. This means configuration files can be created in modular fashion, and that's exactly why you see so many in the /QOpenSys/ibmichroot/chroot directory.

$ chroot_setup.sh chroot_OPS_SC1.lst /QOpenSys/ibmichroot_containers/c1

**********************

Live IBM i session (changes made).

**********************

PATH=/QOpenSys/usr/bin:/QOpenSys/usr/sbin:/opt/freeware/bin

LIBPATH=/QOpenSys/usr/lib:/opt/freeware/lib

mkdir -p /QOpenSys/ibmichroot_containers/c1/QOpenSys/QIBM/ProdData/SC1

cp -R /QOpenSys/QIBM/ProdData/SC1/* /QOpenSys/ibmichroot_containers/c1/QOpenSys/QIBM/ProdData/SC1/.

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSL/bin/c_rehash c_rehash

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSL/bin/openssl openssl

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/scp scp

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/sftp sftp

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/ssh ssh

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/ssh-add ssh-add

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/ssh-agent ssh-agent

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/ssh-keygen ssh-keygen

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/bin

ln -sf ../../QIBM/ProdData/SC1/OpenSSH/bin/ssh-keyscan ssh-keyscan

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/lib

ln -sf ../../QIBM/ProdData/SC1/OpenSSL/lib/libcrypto.a libcrypto.a

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/lib

ln -sf ../../QIBM/ProdData/SC1/OpenSSL/lib/libssl.a libssl.a

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/lib

ln -sf ../../QIBM/ProdData/SC1/zlib/lib/libz.a libz.a

cd /QOpenSys/ibmichroot_containers/c1/QOpenSys/usr/lib

ln -sf ../../QIBM/ProdData/SC1/zlib/lib/libz.so libz.so

============

chroot command:

> chroot /QOpenSys/ibmichroot_containers/c1 /bin/bsh

chroot ssh profile (optional):

> mkdir -p /QOpenSys/ibmichroot_containers/c1/home/MYPROF

> CHGUSRPRF USRPRF(MYPROF) LOCALE(*NONE) HOMEDIR(/QOpenSys/ibmichroot_containers/c1/./home/MYPROF)

   '/./home/MYPROF' is required auto ssh login chroot (IBM i hack)

other useful settings chroot (optional):

> $PS1='dev$ '

> LANG=C

> LANG=819

At this point, the "c1" IFS Container has both the chroot_minimal.lst and chroot_OPS_SC1.lst configurations applied to it. The simplicity and automation make the IBM i Chroot project hugely valuable for those running applications in PASE. We use this technology extensively at Krengeltech both for in-house purposes and when we engage with clients. We found there are so many fewer problems once we can "contain" applications and development environments.

In this article, we covered only one side of the IBM i Chroot project: IFS Container creation. In the next article, we'll dive into how open-source software can be easily downloaded from the Internet and installed in an IFS Container.

If you have any questions or comments, please comment below or email me at This email address is being protected from spambots. You need JavaScript enabled to view it..

Aaron Bartell

Aaron Bartell is Director of IBM i Innovation for Krengel Technology, Inc. Aaron facilitates adoption of open-source technologies on IBM i through professional services, staff training, speaking engagements, and the authoring of best practices within industry publications andwww.litmis.comWith a strong background in RPG application development, Aaron covers topics that enable IBM i shops to embrace today's leading technologies, including Ruby on Rails, Node.js, Git for RPG source change management, and RSpec for unit testing RPG. Aaron is a passionate advocate of vibrant technology communities and the corresponding benefits available for today's modern application developers. Connect with Aaron via email atThis email address is being protected from spambots. You need JavaScript enabled to view it..

Aaron lives with his wife and five children in southern Minnesota. He enjoys the vast amounts of laughter that having a young family brings, along with camping and music. He believes there's no greater purpose than to give of our life and time to help others.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: