Creating a chroot environment in Fedora with bash and other utils.

Table of contents for chroot

  1. Creating a chroot environment in Fedora with bash and other utils.
  2. Creating a chroot environment – the script.


I am testing some of my scripts to work on a very old system and there the versions of the most popular applications are very old, real old :(. So, some of things that I am very used to since last couple of years, do not seem to work as expected and I need to keep verifying a lot of things on the server, very inconvinient to keep testing the script on the server (need to connect on VPN) just to test some very simple things.

But if I want to test it on my local desktop or laptop then I need to donwgrade all the applications on my system. Other option is changing the scripts or the paths to get the lower version to work. I found the third option which I liked best and gives me a very controlled environment – chroot.

So, what do we need to achieve this. Here are the steps

  • Create a empty directory
  • Create the minimum required directories under this directory
   mkdir -p {root,home,dev,etc,lib,usr,bin}
   mkdir -p usr/bin
   mkdir -p libexec/openssh
  • Copy the minimim files required for the chroot
   mknod -m 666 dev/null c 1 3
   cd etc
   cp /etc/ .
   cp -avr /etc/ .
   cp -avr /etc/ .
   cp /etc/ .
   cp /etc/nsswitch.conf .
   cp /etc/passwd .
   cp /etc/group .
   cp /etc/hosts .
   cp /etc/resolv.conf .
  • Copy the required libs for the commands that you would like to have in the chroot

This will have a output like this: => (0x00e77000) => /lib/ (0x46bf1000) => /lib/ (0x46bba000) => /lib/ (0x46020000) => /lib/ (0x47fb3000) => /lib/ (0x46a09000) => /lib/ (0x46bb3000)
/lib/ (0x469e8000) => /lib/ (0x46b97000) => /lib/ (0x46960000)
Here you would need to copy all the files mentioned after the => sign in the output to your lib directory for the chrooted environment. Also make sure that if the above are links then you copy the actual files also to ensure that you have the actual libs for the commands to work.

  • Copy the actual command to the chroot environment.

Copy the command with cp command to the bin directory of your chroot environment.

Once all this is done, you can simply chroot to this directory with the command


Voila, you are done.

Check that you have all the utils/commands that you have copied and nothing less/nothing more.

Enhanced by Zemanta

10 Useful Sar (Sysstat) Examples for UNIX / Linux Performance Monitoring

10 Useful Sar (Sysstat) Examples for UNIX / Linux Performance Monitoring

by Ramesh Natarajan on March 29, 2011

Using sar you can monitor performance of various Linux subsystems (CPU, Memory, I/O..) in real time.

Using sar, you can also collect all performance data on an on-going basis, store them, and do historical analysis to identify bottlenecks.

Sar is part of the sysstat package.

This article explains how to install and configure sysstat package (which contains sar utility) and explains how to monitor the following Linux performance statistics using sar.

  1. Collective CPU usage
  2. Individual CPU statistics
  3. Memory used and available
  4. Swap space used and available
  5. Overall I/O activities of the system
  6. Individual device I/O activities
  7. Context switch statistics
  8. Run queue and load average data
  9. Network statistics
  10. Report sar data from a specific time

This is the only guide you’ll need for sar utility. So, bookmark this for your future reference.

I. Install and Configure Sysstat

Install Sysstat Package

First, make sure the latest version of sar is available on your system. Install it using any one of the following methods depending on your distribution.

 sudo apt-get install sysstat (or) yum install sysstat (or) rpm -ivh sysstat-10.0.0-1.i586.rpm

Install Sysstat from Source

Download the latest version from sysstat download page.

You can also use wget to download the


tar xvfj sysstat-10.0.0.tar.bz2

cd sysstat-10.0.0

./configure --enable-install-cron

Note: Make sure to pass the option –enable-install-cron. This does the following automatically for you. If you don’t configure sysstat with this option, you have to do this ugly job yourself manually.

  • Creates /etc/rc.d/init.d/sysstat
  • Creates appropriate links from /etc/rc.d/rc*.d/ directories to /etc/rc.d/init.d/sysstat to start the sysstat automatically during Linux boot process.
  • For example, /etc/rc.d/rc3.d/S01sysstat is linked automatically to /etc/rc.d/init.d/sysstat

After the ./configure, install it as shown below.


make install

Note: This will install sar and other systat utilities under /usr/local/bin

Once installed, verify the sar version using “sar -V”. Version 10 is the current stable version of sysstat.

 $ sar -V sysstat version 10.0.0 (C) Sebastien Godard (sysstat

Finally, make sure sar works. For example, the following gives the system CPU statistics 3 times (with 1 second interval).

 $ sar 1 3 Linux 2.6.18-194.el5PAE (dev-db)        03/26/2011      _i686_  (8 CPU)

01:27:32 PM       CPU     %user     %nice   %system   %iowait    %steal     %idle 01:27:33 PM       all      0.00      0.00      0.00      0.00      0.00    100.00 01:27:34 PM       all      0.25      0.00      0.25      0.00      0.00     99.50 01:27:35 PM       all      0.75      0.00      0.25      0.00      0.00     99.00 Average:          all      0.33      0.00      0.17      0.00      0.00     99.50

Utilities part of Sysstat

Following are the other sysstat utilities.

  • sar collects and displays ALL system activities statistics.
  • sadc stands for “system activity data collector”. This is the sar backend tool that does the data collection.
  • sa1 stores system activities in binary data file. sa1 depends on sadc for this purpose. sa1 runs from cron.
  • sa2 creates daily summary of the collected statistics. sa2 runs from cron.
  • sadf can generate sar report in CSV, XML, and various other formats. Use this to integrate sar data with other tools.
  • iostat generates CPU, I/O statistics
  • mpstat displays CPU statistics.
  • pidstat reports statistics based on the process id (PID)
  • nfsiostat displays NFS I/O statistics.
  • cifsiostat generates CIFS statistics.

This article focuses on sysstat fundamentals and sar utility.

Rest here:
Enhanced by Zemanta

List all installed rpm packages and it’s size

If you are looking for a command to see the disk usage by each of the rpm‘s then you can use this command:

 rpm -q --queryformat "%10{SIZE}\t%{NAME}\n"

And if you use this command very regularly then you can create an alias like

 alias rpm_size='rpm -q --queryformat "%10{SIZE}\t%{NAME}\n" '

and use it like

rpm_size <package name>

and if you wish to see all the packages then you can use the following:

rpm -qa -–queryformat=”%10{SIZE}\t%{NAME}\n” | sort -k1,1n

Enhanced by Zemanta