Wednesday, December 09, 2009

Extract files from an ISO in Linux (or Windows) without root

I have a need to extract an iso from a script as a non-root user.

My google searching revealed a couple of ways to access the files within an ISO without root access. Obviously, the loop method requires root. If you have gnome around, you can use file-roller as this post shows, but this didn't work for me from the command line. Apparently you can use midnight commander, but I didn't see any easy way to script mc.

The solution I found is to use good ole 7zip. From previous experience I knew it could open up iso files on Windows. They have a Linux version.

Here is the 7zip download page. I recommend downloading the binary verison for linux if you don't want to compile from source.

Here is some sample syntax to extract an iso:

7z x -oOutputDir LargeLinuxIso.iso

I mentioned Windows in the title because 7zip is cross platform and these instructions apply there as well.

Friday, November 20, 2009

Custom RHEL / OEL 5.4 CD (iso) with kickstart

The end result of this tutorial is a bootable iso which will install a pre-configured RHEL 5.4 without any user input.

Step1: Copy

Copy the entire contents of the RHEL 5.4 dvd to $rhroot, where $rhroot is any directory on your system.

Step 2: Create Kickstart

A kickstart file tells the installer how you want the system installed and allows your install to take place with no user input. In it, you configure options like the timezone, the partition layout, and which packages you want installed. The easiest way to create a kickstart config file is to use the one created when you installed your current system which is located at /root/anaconda-ks.cfg. See the documentation for more information on tweaking your kickstart file.

Step 3: Remove Unnecessary Packages, Add Extra Packages

Remove the rpms that you don't need from $rhroot/Server/. Most likely the Cluster, ClusterStorage, and VT directories of $rhroot can also be removed. The rpms you don't need are determined by what packages your installing as defined in the kickstart file. For any additional custom RPMs, be sure you add them to kickstart file or include them in a package group (see $rhroot/Server/comps-rhel5-server-core.xml).

Despite the fact that you may remove many RPMs, I haven't found any benefit to removing references to them from the package group file.

Step 4: Rebuild the Repository

Run the following command from $rhroot/Server to rebuild the Server repository to reflect any packages that were added or removed:
$ createrepo -u "media://`head -1 ../.discinfo`" -g repodata/comps-rhel5-server-core.xml .
Step 5: Build the ISO

From $rhroot run the following:
mkisofs -r -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/ -x "lost+found" -o ../oel5Custom.iso .
Step 6: Test

I use VirtualBox to give my new ISO a spin.

Good References:

Friday, November 06, 2009

Ozone mobile web browser

For the longest time, I've been looking for a decent web browser for the Nokia e71.  After trying webkit s60 (the built in browser), skyfire, opera mini, bolt, and teashark, I finally found Ozone.  Ozone is amazing.  It is fast and loads pages with javascript better than any other mobile browser.

Interestingly enough, Ozone's author(s) is mysteriously elusive.  It is a really good browser, so I would conclude that it took a lot of money to develop.  Why is there no mention of a company or author?  With nobody to give credit to, there's nobody to take blame -- for better or worse.  It's hard for me to trust my identity (gmail username/password, for example) to Ozone.  For all I know, there's a good chance Ozone is the fruit of an organized crime effort.  I'm pretty sure someone could earn a buck or two if they full access to the kinds of information people, usually trustingly, put into their web browser.

So while I'll be using Ozone for everything I can, I won't be giving it any information I wouldn't openly post on the internet.  

Tuesday, October 06, 2009

How to (easily) mount a CDROM in Solaris

for device in `ls /dev/dsk`; do mount -F hsfs -o ro /dev/dsk/$device /mnt/cdrom; done

Thursday, September 24, 2009

Convert p4 cygwin commands to p4 win commands

Here’s a simple little script which allows me to use p4.exe from cygwin.  Perforce actually releases a p4.exe for cygwin, but I wanted my p4win and p4.exe to be able to use the same client spec.  This isn’t possible when one requires a root starting with “C:\” and the other requires “/cygdrive/c/”.  


This script works by expanding and window-izing all arguments after the p4 command.


Here is a series which shows the transformation.

  • p4 edit README
  • p4 edit /home/gwarner/foo/README (where foo is a symbolic link)
  • p4 edit /cygdrive/c/perforceRoot/blah/blah/blah/README
  • p4 edit C:\perforceRoot\blah\blah\blah\README


Ta da!


1.     #!/usr/bin/python

2.     import sys

3.     from subprocess import *


5.     def win32Path(path):                                                                                       path = path.replace('/cygdrive/c/','C:\\')

6.         path = path.replace('/','\\')

7.         return '"%s"' % path.strip()                                                                       

8.     if __name__ == '__main__':

9.         p4command = sys.argv[1]

10.      fullFiles = []


12.      for file in sys.argv[2:]:

13.          fullPath = Popen(['readlink.exe -f ' + file], stdout=PIPE, shell=True).communicate()[0]

14.          fullFiles.append(win32Path(fullPath))


16.      newCommand = 'p4 %s %s' % (p4command, ' '.join(fullFiles))


18.      print newCommand

19.      check_call(newCommand, shell=True)

20.      print 'done.'



Wednesday, September 02, 2009

The Trickyness that is called xhost, xauth, and X in general

Goal: Export a display from a linux client to a RHEL x-server with xauth security

I don't cover all of the details below, but just cover some gotchas.  For some good details on xhost and xauth, see here:

Here are some things that might get in your way:

1) iptables

RHEL blocks most ports out of the box.  The iptables configuration is found here: /etc/sysconfig/iptables.  After making changes, it can be reloaded by issuing this command: "service iptables restart".  

I noticed that ssh was connecting just fine, so I copied the line allowing port 22 connections and changed it to allow port 6000 (x11) connections.  

2) xhost

To disable host checking, issue the following: "xhost +".  Warning: This opens up your system completely as well as disables xauth.

To reenable: "xhost -"

To grant a host permission: "xhost +hostname"

3) xauth

Note: for xauth to work, xhost cannot be disabled.  Also, if xhost is granting permission to your client, it won't bother to check with xauth.  Moral of the story: Enable xhost, but don't add anything to it.

To make sure xauth is being used on the x-server, issue the following: "ps aux | grep auth" and look at the output.  You should see an .Xauthority (or similar file) being referenced.

Both the client and the server must have the cookie for xauth to work.  Run "xauth" and issue the command "list" at the prompt.  On the server, things should be in terms of the server's hostname.  On the client they should also be in terms of the server's hostname.

Some errors related to the above gotchas:
No protocol specified
Xt error: Can't open display ip:0.0

Tuesday, August 25, 2009


Source: 1776 p 271
"Will it not be possible": Joseph Reed to George Washington, December 22, 1776 in PGW, VII, 415

It was time something was done. Something aggressive and surprising.  Even failure would be preferable to doing nothing.

Monday, August 24, 2009

Move /var to its own (logical) partition in LVM

(all this using Oracle EL 5, aka RHEL 5...)

From memory, so there may be errors:

  1. Boot off of the installation cd using "linux rescue"
  2. Unmount all of the drives in /mnt/syslinux
    • Note: Before unmounting /mnt/syslinux itself, you must unmount all of the mountpoints within it.
  3. $ resize2fs /dev/VolGroup00/ 5G
  4. ... boot back into regular linux ...
  5. $ lvreduce -L 6GB /dev/VolGroup00 (answer yes)
  6. $ lvcreate -L 10G -n var VolGroup00
  7. ... boot back into rescue mode ...
  8. mkdir /mnt/var
  9. mkfs -t ext3 /dev/VolGroup00/var
  10. mount -t ext3 /dev/VolGroup00/var/ /mnt/var
  11. mv /mnt/syslinux/var* /mnt/var
  12. (edit fstab so that it mounts the new logical volume to /var)
  13. resize2fs /dev/VolGroup00/LogVol00 (remember how I made this 5Gb when the LV was 6GB?)
  14. reboot!

On rebooting, syslogd had a problem starting. (Running in debug mode, it would complain of "permission denied" to /var/log/secure and all other log files).  It was an SELinux problem and was remedied by relabeling the filesystem.

Wednesday, August 12, 2009

Basic .hgignore for web2py

This should do the trick!

syntax: glob

syntax: regexp

Wednesday, July 22, 2009

Restoring a USB disk

The other day, I imaged a USB disk to do a linux install.  The image was only a few hundred megabytes.  When I was done, I couldn't get the USB drive to reformat to anything other than the size of the image. (thus wasting a large portion of the disk).

Killdisk ( was a tool I found that pretty much writes the usb drive with zeros.  I believe you only need to do so for a few minutes to overwrite the table which holds the partitions and then cancel it and upon reformatting it in windows, you'll discover that you've got all your space back!

Wednesday, June 24, 2009

Byte ordering endianness mayhem! Aahh!

Working with (binary) data structures written to files can be difficult due to the fact that a hexdump of a binary file may appear to be out of order.

The following example may illustrate the source of confusion. This simple python script will create three binary files. To each file we will write 01 02 03 04 split up in different ways.
from struct import *
open('1long.bin','wb').write(pack('L', 0x01020304))
open('2short.bin','wb').write(pack('HH', 0x0102, 0x0304))
open('4char.bin','wb').write(pack('BBBB', 0x01, 0x02, 0x03, 0x04))
We can hexdump them to see their contents:
$ hexdump 1long.bin
0000000 0304 0102 (this is the long: 0x01020304)

$ hexdump 2short.bin
0000000 0102 0304 (these are the 2 shorts: 0x0102, 0x0304)

$ hexdump 4char.bin
0000000 0201 0403 (these are the 4 chars: 0x01, 0x02, 0x03, 0x04)
Before hexdumping, one might suspect that the outputs would be the same, but they're not. Each gave a diffent ordering.

These examples were run on a regular run-of-the-mill 32-bit Intel machine. These machines have a 16-bit word size (weird, yeah, I know) and use little-endian byte ordering. Little endian byte ordering means that the lest sigificant byte of any given data type, will go in the lowest-addressed memory space (or slot in a file on disk).

The least significant byte of the long 0x01020304 is the "04". Why doesn't it appear on the far left in the hexdump such as this: 04 03 02 01?

.... Need to finish writing in here ....

Diagram that I drew showing how reordering address so they increase from right to left can help understand little-endian byte ordering:

After googling around a bit, I found a thread which talks about how to reformat your hexdump so it is in big endian format (I believe). It's quite useful:

$ od -tx1 -w16 -Ax 1long.bin
000000 04 03 02 01
$ od -tx1 -w16 -Ax 2short.bin
000000 02 01 04 03
$ od -tx1 -w16 -Ax 4char.bin
000000 01 02 03 04

Friday, March 13, 2009

c++ runtime "symbol lookup error"

I was working on a c++ project. Everything linked and compiled fine. Upon running the executable, I got the following error:
./TestCppProgram: symbol lookup error: ./TestCppProgram: undefined symbol: _ZN12CppProgramC1Ev
I searched the internet. Two of the interesting links I found were the following:
For me it ended up being a bad LD_LIBRARY_PATH. The path I intended the executable to find it's needed shared library was in the LD_LIBRARY_PATH, it just wasn't before a different path which had an older version of the needed shared library. (This happened to me when I updated by bashrc with a library path and just re-sourced it).

Some cool commands in the debugging process:
  • ldd TestCppProgram (Shows you where your program is getting it's libraries from. An early-on careful inspection of this would've quickly let me to my problem!)
  • ldd -d -r TestCppProgram (Shows you any undefined symbols. There shouldn't be any undefined symbols for an executable, but there will be for a shared lib if it depends on another shared lib. Somebody please correct me if I'm wrong)
  • nm TestCppProgram | c++filt (displays unmangled symbol information)
  • nm TestCppProgram (Displays mangled symbol information. Ie: You should be able to find stuff like ZN12CppProgramC1Ev in here. In my problem above, I found which line number the undefined symbol in question was on, and then looked it up in the unmangled version to see what function it was trying to resolve. It let me know, but it didn't really help me find out what my problem was.)
  • readelf -d TestCppProgram (Shows library dependencies. similar to ldd.)

Tuesday, March 10, 2009

Wednesday, January 07, 2009

Vim search and replace, with increment

:let i=1 | g/foo/s//\=i."morestuff"/ | let i=i+1