<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Toolchain on Amit Agarwal Linux Blog</title>
    <link>/tags/toolchain/</link>
    <description>Recent content in Toolchain on Amit Agarwal Linux Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 23 Sep 2011 09:47:48 +0000</lastBuildDate>
    
	<atom:link href="/tags/toolchain/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Creating a chroot environment – the script.</title>
      <link>/2011/09/23/creating-chroot-environment-script/</link>
      <pubDate>Fri, 23 Sep 2011 09:47:48 +0000</pubDate>
      
      <guid>/2011/09/23/creating-chroot-environment-script/</guid>
      <description>&lt;p&gt;Here is the script, very simple and effective 🙂&lt;/p&gt;
&lt;pre class=&#34;brush: bash; gutter: true; first-line: 1&#34;&gt;#!/bin/bash -
#===============================================================================
#
#          FILE:  mkchroot.sh
#
#         USAGE:  ./mkchroot.sh
#
#   DESCRIPTION:  Make a  chroot environ and cd to it
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), 
#       CREATED: 09/03/2011 02:53:37 PM IST
# Last modified: Sat Sep 03, 2011  03:11PM
#      REVISION:  ---
#===============================================================================

 binaries=( bash2 ls cat vi vim sudo)
#===  FUNCTION  ================================================================
#          NAME:  copy_binary
#   DESCRIPTION:  copy binary to chroot
#    PARAMETERS:
#       RETURNS:
#===============================================================================

copy_binary ()
{
   cmd=`which $1`
   echo $cmd
   cp $cmd bin/
   ldd $cmd
   while read line
   do
      while read ld
      do
         if [[ -f $ld ]]
         then
            echo copy $ld
            cp $ld lib/
            if [[ -L $ld ]]
            then
               ld1=$( ls -l $ld |sed &#39;s/.*&amp;gt; //&#39;)
               echo &#34;  copy $ld1&#34;
               cp  /lib/$ld1 lib/
            fi
         fi
      done &amp;lt; &amp;lt;(echo $line|sed &#39;s/.*&amp;gt; //&#39;|sed &#39;s/ .*//&#39;)
   done &amp;lt; &amp;lt;(ldd $cmd)
}	# ----------  end of function copy_binary  ----------

#===  FUNCTION  ================================================================
#          NAME:  init
#   DESCRIPTION:  Do the required initialization
#    PARAMETERS:
#       RETURNS:
#===============================================================================
init()
{
   mkdir -p {root,home,dev,etc,lib,usr,bin}
   mkdir -p usr/bin
   mkdir -p libexec/openssh



   mknod -m 666 dev/null c 1 3

   cd etc
   cp /etc/ld.so.cache .
   cp -avr /etc/ld.so.cache.d/ .
   cp -avr /etc/ld.so.conf.d/ .
   cp /etc/ld.so.conf .
   cp /etc/nsswitch.conf .
   cp /etc/passwd .
   cp /etc/group .
   cp /etc/hosts .
   cp /etc/resolv.conf .
   cd -
}
cd $1
if [[ -f .status ]]
then
   cat .status
   echo &#34;Not running now&#34;
else
   init
   for i in ${binaries[*]}
   do
       copy_binary $i
       cp -avr /etc/${i}* etc/
   done
   ln bin/bash2 bin/bash
   echo &#34;complete&#34; &amp;gt; .status
fi
cp -avr ~/bin/automation root/automation
sudo chroot .

&lt;/pre&gt;
&lt;p&gt;.&lt;/p&gt;</description>
    </item>
    
  </channel>
</rss>
