<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Tim - the *other* archlinux user</title>
    <link rel="alternate" type="text/html" href="http://blogs.gurulabs.com/tim/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.gurulabs.com/tim/atom.xml" />
    <id>tag:blogs.gurulabs.com,2009-02-24:/tim/19</id>
    <updated>2009-06-15T21:06:28Z</updated>
    <subtitle>linux. bash. KISS.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.25</generator>

<entry>
    <title>My Way of Keeping Arch Linux Updated</title>
    <link rel="alternate" type="text/html" href="http://blogs.gurulabs.com/tim/2009/06/my-way-of-keeping-arch-linux-u.html" />
    <id>tag:blogs.gurulabs.com,2009:/tim//19.267</id>

    <published>2009-06-15T20:33:42Z</published>
    <updated>2009-06-15T21:06:28Z</updated>

    <summary>One of the things that Arch Linux does _not_ try to do is administer your system for you. One area where this bothers me is in a system upgrade procedure which goes roughly like this:$ pacman -SyuThe above command will...</summary>
    <author>
        <name>Tim Gelter</name>
        <uri>http://blogs.gurulabs.com/tim</uri>
    </author>
    
    <category term="archlinuxsysadmin" label="archlinux sysadmin" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://blogs.gurulabs.com/tim/">
        <![CDATA[One of the things that Arch Linux does _not_ try to do is administer your system for you. One area where this bothers me is in a system upgrade procedure which goes roughly like this:<br /><br />$ pacman -Syu<br />The above command will refresh the local cache of packages made available by any configured archlinux repositories, then proceed to upgrade any installed packages to the newest available version.<br />The (pac)kage (man)agement tool "pacman" does not provide the capability of merging new and exisiting configuration files. This is an intentional decision meant to assure that system settings won't be clobbered. As a result, you must manually scan through your filesystem after an update, looking for files with the *.pacsave or *.pacnew extensions, merge in any changes you would like, then (optionally) delete the *.pac{save,new} files. A tool called pacdiffviewer is provided by the yaourt package which can automate the previous procedure.<br /><br />Another thing that pacman is not capable of is updating packages installed via the (A)rch (U)ser (R)epository, AUR (http://aur.archlinux.org/). One tool which is capable of (un)installing/updating/querying/etc. packages located in AUR is yaourt.<br /><br />$ yaourt -Syu --aur --devel<br />The above command will update all packages on the entire system whether installed from pacman repositories or from the AUR.<br /><br />A tool that I recently started using to manage my /etc/ directory is called etckeeper. Etckeeper can be configured to use one of several revision control systems (git, bzr, cvs, etc.) and creates and manages all of the revisions that /etc/* files go through. I've really enjoyed not having to manually make backups of config files when I experiment with new settings and it's good to know that I can easily roll-back or merge changes of files in the future if I decide that I liked things better the way they were before.<br /><br />To put all of the previous things together and save my fingers some typing each day, I created the following alias in ~/.bashrc :<br />alias update='yaourt -Syu --aur --devel &amp;&amp; sudo pacdiffviewer &amp;&amp; cd /etc/ &amp;&amp; sudo etckeeper commit; cd -'<br /><br />My system upgrading is now done by simply typing "sysupgrade" as a normal user and interactively managing the rest of the process.&nbsp; <br /><br /> ]]>
        
    </content>
</entry>

<entry>
    <title>&quot;Get to the Chopper!&quot;</title>
    <link rel="alternate" type="text/html" href="http://blogs.gurulabs.com/tim/2009/03/get-to-the-chopper.html" />
    <id>tag:blogs.gurulabs.com,2009:/tim//19.248</id>

    <published>2009-03-06T18:54:34Z</published>
    <updated>2009-03-06T19:10:32Z</updated>

    <summary>One of the traditions amongst students who attend Guru Labs classes is come up with a putty creations using the &quot;enlightenment putty&quot; they receive during class.Sometime around the beginning of my career here, I taught a Linux Fundamentals class which...</summary>
    <author>
        <name>Tim Gelter</name>
        <uri>http://blogs.gurulabs.com/tim</uri>
    </author>
    
        <category term="swag" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="swag" label="swag" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://blogs.gurulabs.com/tim/">
        <![CDATA[One of the traditions amongst students who attend Guru Labs classes is come up with a putty creations using the "enlightenment putty" they receive during class.<br />Sometime around the beginning of my career here, I taught a Linux Fundamentals class which had a particularly fun group of guys in it. I wish I had more pictures of their creations, but I did have one student forward me this picture he took with his phone. It depicts Arnold Schwarzenegger in a scene from the "The Predator" yelling "Get to the Chopper!"<br /><br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://blogs.gurulabs.com/tim/assets_c/2009/03/Image002-19.html" onclick="window.open('http://blogs.gurulabs.com/tim/assets_c/2009/03/Image002-19.html','popup','width=1600,height=1200,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://blogs.gurulabs.com/tim/assets_c/2009/03/Image002-thumb-350x262-19.jpg" alt="get_to_the_chopper.jpg" class="mt-image-none" style="" width="350" height="262" /></a></span><em></em> <div><br /></div>]]>
        
    </content>
</entry>

<entry>
    <title>Swap file versus swap partition</title>
    <link rel="alternate" type="text/html" href="http://blogs.gurulabs.com/tim/2008/12/swap-file-versus-swap-partitio.html" />
    <id>tag:blogs.gurulabs.com,2008:/tim//18.261</id>

    <published>2008-12-17T20:29:37Z</published>
    <updated>2009-03-06T19:11:34Z</updated>

    <summary>Which is faster, a swap file or a swap partition?This is a question that comes up on a fairly regular basis on IRC chatrooms, mailing lists, etc. which has widely varying answers depending on the source.While updating our courseware a...</summary>
    <author>
        <name>Tim Gelter</name>
        <uri>http://blogs.gurulabs.com/tim</uri>
    </author>
    
    <category term="performancetuning" label="performance tuning" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://blogs.gurulabs.com/tim/">
        <![CDATA[Which is faster, a swap file or a swap partition?<br /><br />This is a question that comes up on a fairly regular basis on IRC chatrooms, mailing lists, etc. which has widely varying answers depending on the source.<br /><br />While updating our courseware a few days back, I decided to start digging into the issue and found a couple of very interesting reads.<br /><br />The most common claim is that a swap partition is faster than a swap<br />file because in older versions of the Linux kernel experienced some filesystem overhead when accessing the swap file.<br /><br />Ever since the release of 2.5.23 of the Linux kernel, however, this is no longer the case. <br />http://www.kernel.org/pub/linux/kernel/v2.5/ChangeLog-2.5.23<br />
(search for the line: "[PATCH] direct-to-BIO I/O for swapcache pages")<br />
<br />In case the highly-technical explanation of how swap files are now handled is less-than-enlightening, perhaps a description from number two Linux kernel developer himself (Andrew Morton) can help clear the muddy waters:<br />http://lkml.org/lkml/2005/7/7/326<br /><br />I still haven't had time to come up with and perform any decent performance comparison, so for now I'll take Andrew Morton's word for it...<br /> ]]>
        
    </content>
</entry>

<entry>
    <title>Thinkfinger stops working with hal 0.5.11</title>
    <link rel="alternate" type="text/html" href="http://blogs.gurulabs.com/tim/2008/12/thinkfinger-stops-working-with.html" />
    <id>tag:blogs.gurulabs.com,2008:/tim//18.265</id>

    <published>2008-12-16T04:59:00Z</published>
    <updated>2009-03-06T19:14:31Z</updated>

    <summary>In case anyone is wondering why their fingerprint reader isn&apos;t working under Linux after a recent upgrade, I may have an answer for a portion of you._If_ you happen to use the thinkfinger PAM module to authenticate and you&apos;ve upgraded...</summary>
    <author>
        <name>Tim Gelter</name>
        <uri>http://blogs.gurulabs.com/tim</uri>
    </author>
    
    <category term="bugs" label="bugs" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://blogs.gurulabs.com/tim/">
        <![CDATA[In case anyone is wondering why their fingerprint reader isn't working under Linux after a recent upgrade, I may have an answer for a portion of you.<br />_If_ you happen to use the thinkfinger PAM module to authenticate and you've upgraded hal to version 0.5.11, a carriage return is now necessary *after* scanning your finger. The reason, as described in the bug report is that: 'When creating a uinput device with only one key, hal incorrectly assigns it as a "button" rather than a "keyboard".'<br />They're still working on a solution, but a temporary workaround (and perhaps the final solution) is to apply this patch and rebuild/reinstall hal:<br /><br /><pre>diff -ur hal-0.5.11.old/hald/linux/device.c hal-0.5.11.new/hald/linux/device.c<br />--- hal-0.5.11.old/hald/linux/device.c	2008-05-07 19:23:42.000000000 -0400<br />+++ hal-0.5.11.new/hald/linux/device.c	2008-11-05 18:26:33.000000000 -0500<br />@@ -175,7 +175,7 @@<br /> {<br /> 	char *s;<br /> 	long bitmask[NBITS(KEY_MAX)];<br />-	int num_bits;<br />+	int num_bits, bus_type;<br /> <br /> 	s = hal_util_get_string_from_file (sysfs_path, "capabilities/key");<br /> 	if (s == NULL)<br />@@ -183,11 +183,11 @@<br /> <br /> 	num_bits = input_str_to_bitmask (s, bitmask, sizeof (bitmask));<br /> <br />-	if (num_bits == 1) {<br />-		/* this is for input devices originating from the ACPI layer et. al. */<br />-<br />-		/* TODO: potentially test for BUS_HOST */<br />+	if (!hal_util_get_int_from_file (sysfs_path, "id/bustype", &amp;bus_type, 16))<br />+		goto out;<br /> <br />+	if (num_bits == 1 &amp;&amp; bus_type == BUS_HOST) {<br />+		/* this is for input devices originating from the ACPI layer et. al. */<br /> 		hal_device_add_capability (d, "button");<br /> 		hal_device_property_set_bool (d, "button.has_state", FALSE);<br /> 		if (test_bit (KEY_POWER, bitmask)) {<br /></pre><br />  ]]>
        
    </content>
</entry>

<entry>
    <title>Hello and chroot</title>
    <link rel="alternate" type="text/html" href="http://blogs.gurulabs.com/tim/2008/11/hello-and-chroot.html" />
    <id>tag:blogs.gurulabs.com,2008:/tim//18.256</id>

    <published>2008-11-06T21:48:00Z</published>
    <updated>2009-03-06T19:14:40Z</updated>

    <summary>Up till now, I&apos;ve only used blogging as a way to keep in touch with friends and family members. One thing that I have noticed while doing so is that contrary to what I&apos;ve felt in the past, not all...</summary>
    <author>
        <name>Tim Gelter</name>
        <uri>http://blogs.gurulabs.com/tim</uri>
    </author>
    
    <category term="tutorial" label="tutorial" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-US" xml:base="http://blogs.gurulabs.com/tim/">
        <![CDATA[Up till now, I've only used blogging as a way to keep in touch with friends and family members. One thing that I have noticed while doing so is that contrary to what I've felt in the past, not all of my acquaintances are interested in Linux or even in technology. Any tech-based blog entries I've created in my family's blog have gone largely ignored and I've even been asked (nicely) _not_ to pollute the blog with my Linux fanaticism. :) Consequently, I've decided to jump on the Guru Labs bandwagon and move all technospeak to this blog.<br /><br />Without further stalling, let the blogging commence...<br /><br />CHROOT<br />


	<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">
	<title></title>
	<meta name="GENERATOR" content="OpenOffice.org 3.0  (Unix)">
	<style type="text/css">
	<!--
		@page { margin: 0.79in }
		PRE { font-family: "Times New Roman" }
		P { margin-bottom: 0.08in }
	--></style>


	<meta http-equiv="CONTENT-TYPE" content="text/html; charset=utf-8">
	<title></title>
	<meta name="GENERATOR" content="OpenOffice.org 3.0  (Unix)">
	<style type="text/css">
	<!--
		@page { margin: 0.79in }
		PRE { font-family: "Times New Roman" }
		P { margin-bottom: 0.08in }
	-->
	</style>

<pre>During my adventures with Linux, I've often seen some pretty powerful uses
for the "chroot" command. Being new to Linux/Unix, I had no idea what it
accomplished, but like many users, ran it blindly trusting that it would help
me accomplish whatever a particular tutorial was outlining.
Since coming to work at Guru Labs, I've had several chances to explore
chroot a bit more and have made some (hopefully) useful observations:

1. chroot can be used as a security mechanism
2. chroot can be used to troubleshoot a broken Linux installation
3. chroot can be used to make major modifications to a Linux installation that
   couldn't otherwise be made
4. chroot can be used for testing in an isolated environment
5. chroot can be used to run 32-bit apps inside of a 64-bit Linux environment
6. chroot can be used in many other ways that I haven't currently seen

Before exploring any of the aforementioned areas where chroot is useful, a short
explanation of chroot is necessary.

As chroot(2) (the Linux man page viewed by running "man 2 chroot") points out,
      "chroot()  changes  the  root  directory of the calling process to that specified in
       path.  This directory will be used for pathnames beginning with /.  The root direc‐
       tory is inherited by all children of the calling process."

Now, the following example could prove useful if the above description wasn't obvious.
Personally, what chroot accomplished or why I should care wasn't apparent to me until I had
experimented with chroot a few times. 

Let's assume that I've got a filesystem that looks like this:
tgelter ~  $  tree -L 1 /
/
|-- bin
|-- boot
|-- dev
|-- etc
|-- home
|-- lib
|-- lib64
|-- media
|-- mnt
|-- oldroot &lt;--specifically notice this one
|-- opt
|-- proc
|-- root
|-- sbin
|-- srv
|-- sys
|-- tmp
|-- usr
`-- var

Now, excluding a lengthy conversation about Linux having a singly-rooted inverted-tree
filesystem structure, let it suffice to say that several individual filesystems are
currently "mounted" and grafted together as we can see from running the "mount" command:
tgelter ~  $  mount
/dev/sda2 on / type jfs (rw)
none on /dev type ramfs (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw)
none on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext3 (rw)
/dev/mapper/storage on /storage type xfs (rw,noatime)
/dev/mapper/oldroot on /oldroot type ext3 (rw,noatime)

Specifically, I have a filesystem on device "/dev/mapper/oldroot" mounted to the directory
called "/oldroot". This filesystem happens to be an older installation of Linux which I'm 
no longer using but keeping around in case I happen to need to copy over an old config file
or, in the worst case scenario, I can boot to it if my current installation were badly broken.

Looking at the directory listing of "/oldroot", we see that it has many of the same
directories of my currently running system:
tgelter ~  $  ls /oldroot/
backup  boot  etc   lib    lost+found  mnt  proc  sbin  storage  tmp  var
bin     dev   home  lib64  media       opt  root  srv   sys      usr

Now let us consider the scenario where I'm attempting to fix "/oldroot". After some research,
I've determined that I just need to issue a system upgrade in order to fix networking. If I
were to boot into "/oldroot" to fix the issue, networking would be broken and there would be
no way to perform the system upgrade in order to fix networking. (Yeah, I _could_ download the
needed packages and install them offline, but let's pretend that's not possible :) )

In order to perform the upgrade, the following steps could be taken:

1. Bind mount virtual filesystems that will be needed by the new chroot environment (a "bind mount" takes a directory that is already mounted and mounts it somewhere else at the same time):
root ~ #  mount --bind /proc /oldroot/proc
root ~ #  mount --bind /dev /oldroot/dev
root ~ #  mount --bind /sys /oldroot/sys
	(more may be needed depending on your configuration)
	*note - these need to be mounted prior to entering the chroot so that your
	 new working environment will be able to obtain information about hardware,
	 running processes, etc.

2. Chroot into the new environment:
root ~ #  chroot /oldroot/
	When I issue this command, the shell (in this case, bash) as well as any
	processes created by it, see the "/dev/mapper/oldroot" filesystem which we saw
	mounted to "/oldroot" as the new "/"

	root / #  tree -L 1 /
	/
	|-- backup
	|-- bin
	|-- boot
	|-- dev
	|-- etc
	|-- home
	|-- lib
	|-- lib64
	|-- lost+found
	|-- media
	|-- mnt
	|-- opt
	|-- proc
	|-- root
	|-- sbin
	|-- srv
	|-- storage
	|-- sys
	|-- tmp
	|-- usr
	`-- var

	You may notice that "/oldroot" no longer appears as it is now referred to as "/".
	Before chrooting, each of these directories was located under "/oldroot/". To help
	visualize,
		/oldroot/etc --&gt; /etc
		/oldroot/home --&gt; /home
		/oldroot/backup --&gt; /backup
		etc.

3. Fix networking as necessary:
	(in my case, I just need to overwrite my /etc/resolv.conf to properly
   	resolv hostnames. _DON'T RUN THIS UNLESS YOU KNOW WHAT YOU'RE DOING_)
root / #  cp /etc/resolv.conf /etc/resolv.conf.bak &amp;&amp; echo "nameserver 4.2.2.2" &gt; /etc/resolv.conf

4. Perform the upgrade (I'm using ArchLinux):
root / #  pacman -Syu
:: Synchronizing package databases...
 testing is up to date
 core is up to date
 extra is up to date
 community is up to date
:: Starting full system upgrade...
resolving dependencies...
looking for inter-conflicts...

Targets (9): e2fsprogs-1.41.3-2  expat-2.0.1-2  git-1.6.0.3-1  gvfs-1.0.2-1  kismet-2008_05_R1-1
             libdrm-2.4.0-1  openoffice-base-3.0.0-2  kernel26-2.6.27.1-1

Total Download Size:    154.91 MB
Total Installed Size:   367.04 MB

Proceed with installation? [Y/n] y

	I happen to use Arch Linux on my laptop, so the system upgrade procedure on your own
	machine will almost certainly differ from what I did above (perhaps "yum upgrade" for
	Fedora/RHEL, "aptitude dist-upgrade" for debian/ubuntu, etc.).

5. Exit the chroot:
root / #  exit

6. Unmount the virtual filesystems:
root ~ #  umount /oldroot/{dev,proc,sys}


Assuming that I had a bad kernel which has now been updated, I could now reboot into the
old installation using the new kernel to test if my fix worked.

Now, I mentioned several reasons to use chroot: 1. A security mechanism, 2. To troubleshoot 
a broken Linux installation, 3. To make major modifications to a Linux installation that
couldn't otherwise be made, 4. For testing an isolated  environment, 5. Used to run 32-bit apps 
inside of a 64-bit Linux environment, 6. Used in many other ways that I haven't currently seen

The example I went over is a fairly common example of reason #2 mentioned above. Most Linux
rescue media uses a similar procedure for rescuing a broken system. I won't go into detailing
any of the other reasons, but see the included URL for reading related to each reason as 
numbered above:

1. http://fedoraproject.org/wiki/Docs/Drafts/AdministrationGuide/Servers/DNSBIND/BINDChroot
3. http://www.howtoforge.com/install-ubuntu-with-software-raid-10
4. https://help.ubuntu.com/6.10/ubuntu/installation-guide/amd64/linux-upgrade.html
5. http://wiki.archlinux.org/index.php/Arch64_Install_bundled_32bit_system

One last note about item #1, placing a process inside of a chroot "jail" as a security
mechanism is often criticized as we see here: http://kerneltrap.org/Linux/Abusing_chroot
from man chroot(2):
	"In  particular,  the  superuser can escape from a "chroot jail" by doing:
	mkdir foo; chroot foo; cd .."

The thing to keep in mind is that chroot is _not_ as powerful as freebsd's jail(). This doesn't
mean that there is no value in placing a process, especially a network service, into a chroot.
Like all security, multiple layers means more protection.
If you've read this far and still have interest in researching security through chroot, I'd
recommend you look into a couple of better solutions which are available:
  -linux vserver (attempt at improving the chroot jail idea)
  -virtual machines (kvm/xen/etc.)</pre>
<br /> ]]>
        
    </content>
</entry>

</feed>

