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
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
LATEST COMMENTS
MC Press Online