Wednesday, April 27, 2005

initial ramdisk howto i found

http://inferno.slug.org/lfs-hints/initrd.txt
TITLE: initrd for LFS
LFS VERSION: any
AUTHOR: Jim Gifford

SYNOPSIS:
How to setup initrd for LFS.

HINT:
$Revision: 1.8 $

Introduction to Initial RAMDisk

This hint will help you configure an LFS system for Initial RAMDisk.
Which will allow you to add modules at start-up instead of compiling them
into the kernel.

The script that is enclosed works with SCSI and USB modules only. IDE
devices are recommened to be built-in the kernel. The script will
auto-detect all SCSI and USB modules and add them to the initial ramdisk.
It will also detect the root from the fstab file

---
Assumptions Made in this document

I have made the following assumptions in this document.
Files have been downloaded.

---
Kernel Configuration

You will need to make sure the following items are configured
in your kernel. With out these, the initrd will not work.

Block Devices

Select Loopback Device Support this can be a module
or built-in.

Select RAM Disk Support this needs to be compiled as
built-in or the initrd will not show up.

Set Default RAM Disk size is 4096 which is the default

Select Initial RAM Disk (initrd) support needs be selected.

---
Needed File System Changes

You will need to create a directory for initrd to use.

The default one that is looked for is /initrd.

To Create this directory use mkdir /initrd

Another change that needs to be made is due to a bug
in busybox itself.

You will need to create a symlink to init and call it
linuxrc

cd /sbin
ln -sf init linuxrc

---
Needed Static Modules

In order for the initrd to work properly during boot up
you will need to create to static programs.

The first one being bash.

busybox
----

Busybox has a Config.h file that needs the following options
enabled to enable them remove the //

#define BB_INSMOD
#define BB_FEATURE_SH_STANDALONE_SHELL

You can configure the rest as you need, but remember have at
least the following enabled to make initrd to work properly.

#define BB_ASH
#define BB_CHROOT
#define BB_ECHO
#define BB_INSMOD
#define BB_MKDIR
#define BB_MODPROBE
#define BB_MOUNT
#define BB_PIVOT_ROOT
#define BB_UMOUNT

To create a static version of bash needed for initrd use
the following commands.

cd /usr/src
tar zxvf /usr/src/busybox-*.tar.gz
cd busy*
make LDFLAGS=-static
cp busybox /bin/busybox

Busybox must be in the /bin directory or the links created
during the initrid will fail.

---
mkinitrd

For those who do not want to type out the script. It is
available on my CVS server at
http://www.jg555.com/cvs/cvsweb.cgi/scripts/mkinitrd-lfs

This script will create the initial RAM Disk image file.
By default this script creates /boot/initrd.img

The default location for this file is /sbin

#!/bin/bash

# mkinitrd for LFS by Jim Gifford
# $Revision: 1.8 $

# Variables
TEMP="$1"

KERNEL_VERSION=""
CONFIG_FILE="/etc/modules.conf"

FSTAB="/etc/fstab"
ROOT_DEVICE=$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $FSTAB)

SCSI_MODULES="`grep scsi_hostadapter $CONFIG_FILE | grep -v '^[ ]*#' | awk '{ print $3 }'`"
NEEDED_SCSI="scsi_mod sd_mod"

USB_MODULES="`grep usb-controller $CONFIG_FILE | grep -v '^[ ]*#' | awk '{ print $3 }'`"
NEEDED_USB="usbcore"

MODULES="$NEEDED_SCSI $SCSI_MODULES $NEEDED_USB $USB_MODULES"

IMAGE_SIZE=3000
MOUNT_IMAGE="/tmp/initrd.$$"
IMAGE="/tmp/initrd.img-$$"
MOUNT_POINT="/tmp/initrd.mnt-$$"
LINUXRC="$MOUNT_IMAGE/linuxrc"

# Check for initrd Directory

if ! [ -e /initrd ]
then
mkdir /initrd
fi

# Check for RAM Disk Device

if [ -e /dev/.devfsd ]
then
RAM_DEVICE="rd"
else
RAM_DEVICE="ram0"
fi

# Check for input

if [ "$TEMP" == "" ]
then
KERNEL_VERSION="`uname -r`"
else
KERNEL_VERSION="$TEMP"
fi

INITRD="/boot/initrd-$KERNEL_VERSION.img"

if [ "$TEMP" == "-h" ] || [ "$TEMP" == "--h" ] || [ "$TEMP" == "-help" ] || [ "$TEMP" == "--help" ]
then
echo "usage: mkinitrd kernel_version"
echo " : mkinitrd will automatically determin kernel version"
exit 1
fi

# Creating LoopBack Device

dd if=/dev/zero of=$IMAGE bs=1k count=$IMAGE_SIZE 2> /dev/null

for device_number in 0 1 2 3 4 5 6 7 8
do
if losetup /dev/loop$device_number $IMAGE 2>/dev/null
then
break
fi
done

if [ "$device_number" = "8" ]
then
rm -rf $MOUNT_POINT $IMAGE
echo "All of your loopback devices are in use!" >&2
exit 1
fi

LOOP_DEVICE=/dev/loop$device_number

echo y | mke2fs $LOOP_DEVICE $IMAGE_SIZE > /dev/null 2> /dev/null

echo "Using loopback device $LOOP_DEVICE"

mkdir -p $MOUNT_POINT
mount -t ext2 $LOOP_DEVICE $MOUNT_POINT || {
echo "Can't get a loopback device"
exit 1
}
# Creating Directories

mkdir -p $MOUNT_IMAGE
mkdir -p $MOUNT_IMAGE/lib
mkdir -p $MOUNT_IMAGE/bin
mkdir -p $MOUNT_IMAGE/etc
mkdir -p $MOUNT_IMAGE/dev
mkdir -p $MOUNT_IMAGE/proc
ln -s /bin $MOUNT_IMAGE/sbin

rm -rf $MOUNT_POINT/lost+found

# Copying Static Programs

cp -a /bin/busybox $MOUNT_IMAGE/bin/busybox
ln -s /bin/busybox $MOUNT_IMAGE/bin/echo
ln -s /bin/busybox $MOUNT_IMAGE/bin/mount
ln -s /bin/busybox $MOUNT_IMAGE/bin/modprobe
ln -s /bin/busybox $MOUNT_IMAGE/bin/mkdir
ln -s /bin/busybox $MOUNT_IMAGE/bin/sh
ln -s /bin/busybox $MOUNT_IMAGE/bin/umount
ln -s /bin/busybox $MOUNT_IMAGE/bin/insmod
ln -s /bin/busybox $MOUNT_IMAGE/bin/pivot_root
cp -a /etc/fstab $MOUNT_IMAGE/etc/fstab
cp -a /etc/modules.conf $MOUNT_IMAGE/etc/modules.conf

# Copying Modules

for MODULE in $MODULES
do
echo "$MODULE" | {
IFS=':' read module options
module=$module
options=$options
DIR_SEARCH1="`ls -1 /lib/modules/$KERNEL_VERSION/kernel/drivers`"
for DIR_1SEARCH in $DIR_SEARCH1
do
cp /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH/$module.o $MOUNT_IMAGE/lib > /dev/null 2>&1
DIR_SEARCH2="`ls -1 /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH`"
for DIR_2SEARCH in $DIR_SEARCH2
do
cp /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH/$DIR_2SEARCH/$module.o $MOUNT_IMAGE/lib > /dev/null 2>&1
done
done
}
done

for i in console null $RAM_DEVICE tty[1234]
do
cp -a /dev/$i $MOUNT_IMAGE/dev
done

# Creating linuxrc File

echo "#!/bin/sh" > $LINUXRC
echo "" >> $LINUXRC

echo "echo \"Initial RAMDISK Loading Starting...\"" >> $LINUXRC

for MODULE in $MODULES
do
echo "$MODULE" | {
IFS=':' read module
module=$module

echo "Loading module $module"
echo "insmod /lib/$module.o" >> $LINUXRC
}
done

echo "echo \"Initial RAMDISK Loading Completed...\"" >> $LINUXRC
echo "mkdir /new_root" >> $LINUXRC
echo "echo \"Mounting proc...\"" >> $LINUXRC
echo "mount -n -t proc none /proc" >> $LINUXRC
echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $LINUXRC
echo "echo \"Mounting real root dev...\"" >> $LINUXRC
echo "mount -n -o ro $ROOT_DEVICE /new_root" >> $LINUXRC
echo "umount /proc" >> $LINUXRC
echo "cd /new_root" >> $LINUXRC
echo "echo \"Running pivot_root...\"" >> $LINUXRC
echo "pivot_root . initrd" >> $LINUXRC
echo "if [ -c initrd/dev/.devfsd ]" >> $LINUXRC
echo " then" >> $LINUXRC
echo " echo \"Mounting devfs...\"" >> $LINUXRC
echo " mount -n -t devfs none dev" >> $LINUXRC
echo "fi" >> $LINUXRC
echo "if [ \$\$ = 1 ]" >> $LINUXRC
echo " then" >> $LINUXRC
echo " echo \"Running init...\"" >> $LINUXRC
echo " exec chroot . sbin/init dev/console 2>&1" >> $LINUXRC
echo " else" >> $LINUXRC
echo " echo \"Using bug circumvention for busybox...\"" >> $LINUXRC
echo " exec chroot . linuxrc dev/console 2>&1" >> $LINUXRC
echo "fi" >> $LINUXRC

chmod +x $LINUXRC

(cd $MOUNT_IMAGE; tar cf - .) | (cd $MOUNT_POINT; tar xf -)

umount $MOUNT_POINT
losetup -d $LOOP_DEVICE

gzip -9 < $IMAGE > $INITRD
rm -rf $MOUNT_IMAGE $MOUNT_POINT $IMAGE

lilo -v

---
initrd script

The following script needs to placed in /etc/rc.d/init.d.

You will then need to link it to rcsysinit.d.

It is recommended that this script be run right after
mountfs.

To link the script change to the /etc/rc.d/rcsysinit.d
directory and issue the following command.

ln -sf ../init.d/initrd S41initrd

#!/bin/bash
# Begin $rc_base/init.d/initrd

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

echo "Clearing Initial RAM Disk..."
if [ -e /initrd/dev/.devfsd ]
then
umount /initrd/dev
fi
umount /initrd
/sbin/blockdev --flushbufs /dev/ram0

# End $rc_base/init.d/initrd

---
For Lilo

In order to use the initrd.img file is to add the
following entry to you lilo.conf file.

initrd=/boot/initrd.img

So your lilo.conf should look something like this.

image=/boot/vmlinuz-2.4.18
label=test
initrd=/boot/initrd-2.4.18.img
read-only
append="root=/dev/ram0 init=/linuxrc rw"

If you are just testing. You should make a separate
entry in lilo.conf. This will still allow you to boot.

---
For Grub

In order to use the initrd.img file is to add the
following entry to you menu.lst file.

initrd /boot/initrd-2.4.18.img

So your menu.lst should look something like this.

title test
root (hd0,1)
kernel /boot/vmlinuz-2.4.18
initrd /boot/initrd-2.4.18.img

---
For Syslinux

In order to use the initrd.img file is to add the
following to syslinux.cfg file.

append root=/dev/ram0 initrd=initrd-2.4.18.img

So your syslinux.cfg should look something like this.

label test
kernel vmlinuz
append root=/dev/ram0 initrd=initrd.img

---
Mail suggestions to giffordj@linkline.com

New Version of this document can be viewed from
http://www.jg555.com/cvs

this looked interesting, i am going to come back and read
a bit more closesly.

initial ramdisk howto i found

http://inferno.slug.org/lfs-hints/initrd.txt
TITLE: initrd for LFS
LFS VERSION: any
AUTHOR: Jim Gifford

SYNOPSIS:
How to setup initrd for LFS.

HINT:
$Revision: 1.8 $

Introduction to Initial RAMDisk

This hint will help you configure an LFS system for Initial RAMDisk.
Which will allow you to add modules at start-up instead of compiling them
into the kernel.

The script that is enclosed works with SCSI and USB modules only. IDE
devices are recommened to be built-in the kernel. The script will
auto-detect all SCSI and USB modules and add them to the initial ramdisk.
It will also detect the root from the fstab file

---
Assumptions Made in this document

I have made the following assumptions in this document.
Files have been downloaded.

---
Kernel Configuration

You will need to make sure the following items are configured
in your kernel. With out these, the initrd will not work.

Block Devices

Select Loopback Device Support this can be a module
or built-in.

Select RAM Disk Support this needs to be compiled as
built-in or the initrd will not show up.

Set Default RAM Disk size is 4096 which is the default

Select Initial RAM Disk (initrd) support needs be selected.

---
Needed File System Changes

You will need to create a directory for initrd to use.

The default one that is looked for is /initrd.

To Create this directory use mkdir /initrd

Another change that needs to be made is due to a bug
in busybox itself.

You will need to create a symlink to init and call it
linuxrc

cd /sbin
ln -sf init linuxrc

---
Needed Static Modules

In order for the initrd to work properly during boot up
you will need to create to static programs.

The first one being bash.

busybox
----

Busybox has a Config.h file that needs the following options
enabled to enable them remove the //

#define BB_INSMOD
#define BB_FEATURE_SH_STANDALONE_SHELL

You can configure the rest as you need, but remember have at
least the following enabled to make initrd to work properly.

#define BB_ASH
#define BB_CHROOT
#define BB_ECHO
#define BB_INSMOD
#define BB_MKDIR
#define BB_MODPROBE
#define BB_MOUNT
#define BB_PIVOT_ROOT
#define BB_UMOUNT

To create a static version of bash needed for initrd use
the following commands.

cd /usr/src
tar zxvf /usr/src/busybox-*.tar.gz
cd busy*
make LDFLAGS=-static
cp busybox /bin/busybox

Busybox must be in the /bin directory or the links created
during the initrid will fail.

---
mkinitrd

For those who do not want to type out the script. It is
available on my CVS server at
http://www.jg555.com/cvs/cvsweb.cgi/scripts/mkinitrd-lfs

This script will create the initial RAM Disk image file.
By default this script creates /boot/initrd.img

The default location for this file is /sbin

#!/bin/bash

# mkinitrd for LFS by Jim Gifford
# $Revision: 1.8 $

# Variables
TEMP="$1"

KERNEL_VERSION=""
CONFIG_FILE="/etc/modules.conf"

FSTAB="/etc/fstab"
ROOT_DEVICE=$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $FSTAB)

SCSI_MODULES="`grep scsi_hostadapter $CONFIG_FILE | grep -v '^[ ]*#' | awk '{ print $3 }'`"
NEEDED_SCSI="scsi_mod sd_mod"

USB_MODULES="`grep usb-controller $CONFIG_FILE | grep -v '^[ ]*#' | awk '{ print $3 }'`"
NEEDED_USB="usbcore"

MODULES="$NEEDED_SCSI $SCSI_MODULES $NEEDED_USB $USB_MODULES"

IMAGE_SIZE=3000
MOUNT_IMAGE="/tmp/initrd.$$"
IMAGE="/tmp/initrd.img-$$"
MOUNT_POINT="/tmp/initrd.mnt-$$"
LINUXRC="$MOUNT_IMAGE/linuxrc"

# Check for initrd Directory

if ! [ -e /initrd ]
then
mkdir /initrd
fi

# Check for RAM Disk Device

if [ -e /dev/.devfsd ]
then
RAM_DEVICE="rd"
else
RAM_DEVICE="ram0"
fi

# Check for input

if [ "$TEMP" == "" ]
then
KERNEL_VERSION="`uname -r`"
else
KERNEL_VERSION="$TEMP"
fi

INITRD="/boot/initrd-$KERNEL_VERSION.img"

if [ "$TEMP" == "-h" ] || [ "$TEMP" == "--h" ] || [ "$TEMP" == "-help" ] || [ "$TEMP" == "--help" ]
then
echo "usage: mkinitrd kernel_version"
echo " : mkinitrd will automatically determin kernel version"
exit 1
fi

# Creating LoopBack Device

dd if=/dev/zero of=$IMAGE bs=1k count=$IMAGE_SIZE 2> /dev/null

for device_number in 0 1 2 3 4 5 6 7 8
do
if losetup /dev/loop$device_number $IMAGE 2>/dev/null
then
break
fi
done

if [ "$device_number" = "8" ]
then
rm -rf $MOUNT_POINT $IMAGE
echo "All of your loopback devices are in use!" >&2
exit 1
fi

LOOP_DEVICE=/dev/loop$device_number

echo y | mke2fs $LOOP_DEVICE $IMAGE_SIZE > /dev/null 2> /dev/null

echo "Using loopback device $LOOP_DEVICE"

mkdir -p $MOUNT_POINT
mount -t ext2 $LOOP_DEVICE $MOUNT_POINT || {
echo "Can't get a loopback device"
exit 1
}
# Creating Directories

mkdir -p $MOUNT_IMAGE
mkdir -p $MOUNT_IMAGE/lib
mkdir -p $MOUNT_IMAGE/bin
mkdir -p $MOUNT_IMAGE/etc
mkdir -p $MOUNT_IMAGE/dev
mkdir -p $MOUNT_IMAGE/proc
ln -s /bin $MOUNT_IMAGE/sbin

rm -rf $MOUNT_POINT/lost+found

# Copying Static Programs

cp -a /bin/busybox $MOUNT_IMAGE/bin/busybox
ln -s /bin/busybox $MOUNT_IMAGE/bin/echo
ln -s /bin/busybox $MOUNT_IMAGE/bin/mount
ln -s /bin/busybox $MOUNT_IMAGE/bin/modprobe
ln -s /bin/busybox $MOUNT_IMAGE/bin/mkdir
ln -s /bin/busybox $MOUNT_IMAGE/bin/sh
ln -s /bin/busybox $MOUNT_IMAGE/bin/umount
ln -s /bin/busybox $MOUNT_IMAGE/bin/insmod
ln -s /bin/busybox $MOUNT_IMAGE/bin/pivot_root
cp -a /etc/fstab $MOUNT_IMAGE/etc/fstab
cp -a /etc/modules.conf $MOUNT_IMAGE/etc/modules.conf

# Copying Modules

for MODULE in $MODULES
do
echo "$MODULE" | {
IFS=':' read module options
module=$module
options=$options
DIR_SEARCH1="`ls -1 /lib/modules/$KERNEL_VERSION/kernel/drivers`"
for DIR_1SEARCH in $DIR_SEARCH1
do
cp /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH/$module.o $MOUNT_IMAGE/lib > /dev/null 2>&1
DIR_SEARCH2="`ls -1 /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH`"
for DIR_2SEARCH in $DIR_SEARCH2
do
cp /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH/$DIR_2SEARCH/$module.o $MOUNT_IMAGE/lib > /dev/null 2>&1
done
done
}
done

for i in console null $RAM_DEVICE tty[1234]
do
cp -a /dev/$i $MOUNT_IMAGE/dev
done

# Creating linuxrc File

echo "#!/bin/sh" > $LINUXRC
echo "" >> $LINUXRC

echo "echo \"Initial RAMDISK Loading Starting...\"" >> $LINUXRC

for MODULE in $MODULES
do
echo "$MODULE" | {
IFS=':' read module
module=$module

echo "Loading module $module"
echo "insmod /lib/$module.o" >> $LINUXRC
}
done

echo "echo \"Initial RAMDISK Loading Completed...\"" >> $LINUXRC
echo "mkdir /new_root" >> $LINUXRC
echo "echo \"Mounting proc...\"" >> $LINUXRC
echo "mount -n -t proc none /proc" >> $LINUXRC
echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $LINUXRC
echo "echo \"Mounting real root dev...\"" >> $LINUXRC
echo "mount -n -o ro $ROOT_DEVICE /new_root" >> $LINUXRC
echo "umount /proc" >> $LINUXRC
echo "cd /new_root" >> $LINUXRC
echo "echo \"Running pivot_root...\"" >> $LINUXRC
echo "pivot_root . initrd" >> $LINUXRC
echo "if [ -c initrd/dev/.devfsd ]" >> $LINUXRC
echo " then" >> $LINUXRC
echo " echo \"Mounting devfs...\"" >> $LINUXRC
echo " mount -n -t devfs none dev" >> $LINUXRC
echo "fi" >> $LINUXRC
echo "if [ \$\$ = 1 ]" >> $LINUXRC
echo " then" >> $LINUXRC
echo " echo \"Running init...\"" >> $LINUXRC
echo " exec chroot . sbin/init dev/console 2>&1" >> $LINUXRC
echo " else" >> $LINUXRC
echo " echo \"Using bug circumvention for busybox...\"" >> $LINUXRC
echo " exec chroot . linuxrc dev/console 2>&1" >> $LINUXRC
echo "fi" >> $LINUXRC

chmod +x $LINUXRC

(cd $MOUNT_IMAGE; tar cf - .) | (cd $MOUNT_POINT; tar xf -)

umount $MOUNT_POINT
losetup -d $LOOP_DEVICE

gzip -9 < $IMAGE > $INITRD
rm -rf $MOUNT_IMAGE $MOUNT_POINT $IMAGE

lilo -v

---
initrd script

The following script needs to placed in /etc/rc.d/init.d.

You will then need to link it to rcsysinit.d.

It is recommended that this script be run right after
mountfs.

To link the script change to the /etc/rc.d/rcsysinit.d
directory and issue the following command.

ln -sf ../init.d/initrd S41initrd

#!/bin/bash
# Begin $rc_base/init.d/initrd

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

echo "Clearing Initial RAM Disk..."
if [ -e /initrd/dev/.devfsd ]
then
umount /initrd/dev
fi
umount /initrd
/sbin/blockdev --flushbufs /dev/ram0

# End $rc_base/init.d/initrd

---
For Lilo

In order to use the initrd.img file is to add the
following entry to you lilo.conf file.

initrd=/boot/initrd.img

So your lilo.conf should look something like this.

image=/boot/vmlinuz-2.4.18
label=test
initrd=/boot/initrd-2.4.18.img
read-only
append="root=/dev/ram0 init=/linuxrc rw"

If you are just testing. You should make a separate
entry in lilo.conf. This will still allow you to boot.

---
For Grub

In order to use the initrd.img file is to add the
following entry to you menu.lst file.

initrd /boot/initrd-2.4.18.img

So your menu.lst should look something like this.

title test
root (hd0,1)
kernel /boot/vmlinuz-2.4.18
initrd /boot/initrd-2.4.18.img

---
For Syslinux

In order to use the initrd.img file is to add the
following to syslinux.cfg file.

append root=/dev/ram0 initrd=initrd-2.4.18.img

So your syslinux.cfg should look something like this.

label test
kernel vmlinuz
append root=/dev/ram0 initrd=initrd.img

---
Mail suggestions to giffordj@linkline.com

New Version of this document can be viewed from
http://www.jg555.com/cvs

this looked interesting, i am going to come back and read
a bit more closesly.

Monday, April 18, 2005

Xauth problems

Xauth problems
the issue is the hostname is screwed up
$> hostname
returns
(none)
sound familiar
when i removed the section of script
and just said the hostname was "uccd"
no errors

two things of import
there is a file /etc/hostname that contains
the setting for the hostname
and there is a command "hostname"

Sunday, April 17, 2005

Xauth problems

I am starting x and even getting twm to work
but when i shutdown twm/x11/xvesa
there are two sets of error messages:

xauth: (argv):1: bad display name "(none):0" in "list" command
xauth: (argv):1: bad display name "(none):0" in "add" command

waiting for X server to shut down

xauth: (argv):1 bad display name "(none):0" in "remove" command


what up?

the startx script is as follows:

#!/bin/sh

userclientrc=$HOME/.xinitrc
userserverrc=$HOME/.xserverrc
sysclientrc=/etc/X11/xinit/xinitrc
sysserverrc=/etc/X11/xinit/xserverrc
defaultclient=/usr/X11R6/bin/xterm
defaultserver=/usr/X11R6/bin/X
defaultclientargs=""
defaultserverargs="-screen 800x600x24 -2button"
clientargs=""
serverargs=""

if [ -f $userclientrc ]; then
defaultclientargs=$userclientrc
elif [ -f $sysclientrc ]; then
defaultclientargs=$sysclientrc
fi

if [ -f $userserverrc ]; then
defaultserverargs=$userserverrc
elif [ -f $sysserverrc ]; then
defaultserverargs=$sysserverrc
fi

whoseargs="client"
while [ x"$1" != x ]; do
case "$1" in
# '' required to prevent cpp from treating "/*" as a C comment.
/''*|\./''*)
if [ "$whoseargs" = "client" ]; then
if [ x"$clientargs" = x ]; then
client="$1"
else
clientargs="$clientargs $1"
fi
else
if [ x"$serverargs" = x ]; then
server="$1"
else
serverargs="$serverargs $1"
fi
fi
;;
--)
whoseargs="server"
;;
*)
if [ "$whoseargs" = "client" ]; then
clientargs="$clientargs $1"
else
# display must be the FIRST server argument
if [ x"$serverargs" = x ] && expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then

display="$1"
else
serverargs="$serverargs $1"
fi
fi
;;
esac
shift
done

# process client arguments
if [ x"$client" = x ]; then
# if no client arguments either, use rc file instead
if [ x"$clientargs" = x ]; then
client="$defaultclientargs"
else
client=$defaultclient
fi
fi

# process server arguments
if [ x"$server" = x ]; then
# if no server arguments or display either, use rc file instead
if [ x"$serverargs" = x -a x"$display" = x ]; then
server="$defaultserverargs"
else
server=$defaultserver
fi
fi

if [ x"$XAUTHORITY" = x ]; then
XAUTHORITY=$HOME/.Xauthority
export XAUTHORITY
fi

removelist=

# set up default Xauth info for this machine
case `uname` in
Linux*)
if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then
hostname=`hostname -f`
else
hostname=`hostname`
fi
;;
*)
hostname=`hostname`
;;
esac

authdisplay=${display:-:0}
mcookie=`mcookie`
for displayname in $authdisplay $hostname$authdisplay; do
if ! xauth list "$displayname" | grep "$displayname " >/dev/null 2>&1; then
xauth add $displayname . $mcookie
removelist="$displayname $removelist"
fi
done

xinit $client $clientargs -- $server $display $serverargs

if [ x"$removelist" != x ]; then
xauth remove $removelist
fi


if command -v deallocvt > /dev/null 2>&1; then
deallocvt
fi

Wednesday, April 13, 2005

SAXParser (isn't)

The SAXParser class really isnt a parser classes.
Its Bridge class that gets the xml stream into
the Handler class or the class derived
from the Handler class. The Derived handler
is the parser and its recursive descent
parser.

interesting
http://www.s34.co.jp/cpptechdoc/article/xml/fsm/fsm_sax.cpp

Tuesday, April 12, 2005

Const wierdness found in xerces

static XMLCh* transcode (const char* const toTranscode);
ok wtf?
man i have forgotten const's and constantness

from the c++-faq section 18.5:

[18.5] What's the difference between "const Fred* p", "Fred* const p" and "const Fred* const p"?

You have to read pointer declarations right-to-left.

* const Fred* p means "p points to a Fred that is const" — that is, the Fred object can't be changed via p.
* Fred* const p means "p is a const pointer to a Fred" — that is, you can change the Fred object via p, but you can't change the pointer p itself.
* const Fred* const p means "p is a const pointer to a const Fred" — that is, you can't change the pointer p itself, nor can you change the Fred object via p.

or in my case const char* const p means "p is a const pointer to a const char" i cant change
the pointer location or what is pointed to?

Autotools update

checkout subversion and did a autogen
on the mandrake 9.2 book and got got
the following error:
configure: error: cannot find install-sh or install.sh in . ./.. ./../..
looked on google and found to things.
1) configure.in is now deprecated and the standard is now
configure.ac
2) update automake then autoconf
i updated automake to version 1.9
and autoconf to version 2.59

see this web site for a quicky example
http://freedomink.org/node/100

Sunday, April 10, 2005

Autoconf project that uses Xerces 2.6.0

I started this little project about 2 or 3 times
first looking at how to recognize if
a said library was properly installed on a system.
I found more than one answer on how that should
work. Then I pulled back from that and just
started from basics.

I followed the link "Developing software with GNU"
http://www.amath.washington.edu/~lf/tutorials/autoconf/toolsmanual_toc.html
another good reference is
http://developer.gnome.org/doc/books/WGA/creating-configuration.html

The project has these files.

reconf
Makefile.am
configure.in
src/hello.cc
src/Makefile.am

The Makefile.am has the following lines
-------------------- Makefile.am --------------------------
EXTRA_DIST = reconf configure
SUBDIRS = src
-----------------------------------------------------------

EXTRA_DIST says to "List any files that you want to include
into your source code distribution. "

A file Makfile.in will have a target called dist
The dist target can be used to generate a gzip'd tar file
some files are not covered in the automatic rules.
These files should be listed in the EXTRA_DIST variable.

since configure is normally generated it need not be part
of tar dist but you want to include it as a convience
so anyone how get the the tared dist need only
run configure.

SUBDIRS
SUBDIRS = dir1 dir2 ...
`make' will be recursively invoked in each subdirectory
stated before doing anything on the current directory.
On the same token you will need to supply a `Makefile.am'
for each of the `src' directories you have stated.

configure.in
----------------------- configure.in ---------------------
AC_INIT
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(test,0.1)
AC_PROG_CC
AC_PROG_CXX
AC_PROG_RANLIB
AC_PROG_INSTALL
AC_OUTPUT(Makefile src/Makefile)
----------------------------------------------------------

configure script must call AC_INIT

AC_INIT(package, version, [bug-report], [tar-name])

AC_INIT and AC_OUTPUT are the two only required macros by the
configure script.
AC_INIT generates the following m4 macros,
output variables and preprocessor symbols:

* [AC_]PACKAGE_NAME
* [AC_]PACKAGE_TARNAME
* [AC_]PACKAGE_VERSION
* [AC_]PACKAGE_STRING
* [AC_]PACKAGE_BUGREPORT

AM_CONFIG_HEADER:

AM_CONFIG_HEADER(config.h)
AM_CONFIG_HEADER(config.h:config.in)

Names the header file which will hold the preprocessor
macro definitions for compile time. Normally, this is
config.h. The source files will then #include "config.h".
Requires a accconfig.h file.

AC_PROG_CC first checks to see if the CC environment
variable is set on the end user's system and the other
AC_PROG_* macros work similarly.

AC_OUTPUT
Automake uses this to determine which files to create
Listed files named Makefile are treated as `Makefile's.

The next files are

src/hello.cc

------------------------------- hello.cc ---------------
#if HAVE_CONFIG_H
# include
#endif

#include
#include

using namespace XERCES_CPP_NAMESPACE
int main(int argc,char *argv[])
{
return 0;
}

the above compile and linked seemlessly.
why? because of the file:

src/Makefile.am

-------------------------- src/Makefile.am ---------------
INCLUDES = -I/usr/inlucde/xerces -I/usr/include/xercesc/sax
LDADD = -lxerces-c
bin_PROGRAMS = hello
hello_SOURCES = hello.cc
----------------------------------------------------------

INCLUDES = -I/dir1 -I/dir2 ...
Insert the -I flags that you want to pass to your compiler
when it builds object files.

LDFLAGS = -L/dir1 -L/dir2 ...
Insert the -L flags that you want to pass to your compiler.

bin_PROGRAMS = prog1 prog2 ....

Lists the executable files that will be compiled with `make'
and installed with `make install' under `/prefix/bin',

prog_SOURCES = foo1.c foo2.c ... header1.h header2.h ....
List all the files that compose the source code of the program,
including header files.

there is also specialization.
your can have the following
prog_SOURCES
prog_LDADD apply headers to a specific file
prog_LDFLAGS apply library includes to a specific file
prog_DEPENDENCIES

Friday, April 08, 2005

Subversion + SSH

found this link
http://www.mono-project.com/SVN
has a nice overview of everything.

Autotools

http://www.nevrax.org/tiki-pagehistory.php?page=NeLCompilingLinux&diff=4
the following has a sample automake project:
http://www.openismus.com/documents/linux/automake/automake.shtml
also here is a great online book:
http://sources.redhat.com/autobook

notes: form the above online book.

configure will generate the following
files:

`config.cache' results of the system tests
`config.log` each test run and the result
`config.status` used to recreate the current configuration.
`config.h' examines variability of the C and C++ programming
languages and implementations thereof.
`Makefile' One of the common functions of `configure' is
to generate `Makefile's and other files.

so basically generate config.h and Makefile
if things break look at config.log

NOTE:
The smallest project requires the user to provide only two files.

* `Makefile.am' is an input to automake.
* `configure.in' is an input to autoconf.


----------------------Makefile.am---------------------------------
bin_PROGRAMS = foonly
foonly_SOURCES = main.c foo.c foo.h nly.c scanner.l parser.y
foonly_LDADD = @LEXLIB@

This `Makefile.am' specifies that we want a program called `foonly'
to be built and installed in the `bin' directory when make
install is run. The source files that are used to build `foonly'
are the C source files `main.c', `foo.c', `nly.c' and `foo.h', the
lex program in `scanner.l' and a yacc grammar in `parser.y'.
------------------------------------------------------------------

Wednesday, April 06, 2005

SDL linking woes

I have tried to compile a small sdl demo and all i get is grief of this
flavor:
checking for SDL - version >= 1.2.0... no

after some research i found that what is happening
is that a small program is trying to compiled and failing.
the analogue is this.

---------------------- sdltest.c -----------------------------------------
#include <SDL.h>
int main(int argc,char **)
{
return 0;
}
----------------------------------------------------------------------------
the configure script uses a configure script sdl-config
to determine to kick out the need library and header
path information.
all of this fails and you get the error:
checking for SDL - version >= 1.2.0... no

if found via google that details what i did above and then
hacked the sdl-config macro. and i was able to compile
the the above test and the testdrivers in the sdl
source distro.

gcc -o sdltest sdltest.c -L/usr/X11R6/lib/ `sdl-config --cflags` `sdl-config --libs` -lX11 -lXext -lgcc

what now insterests me is why i need to add -L/usr/X11/lib?
no actuall i know that i need this but what does the configure
script know this?

Tuesday, April 05, 2005

More on SSH/Pam

1. clean and server exchange (public) host keys.
If the client machine has never encountered
a given public key before, both SSH .... ask
the user whether to accept the untrusted key, ...
next the use these public keys to negotiate a session
key .... As with typical SSL connections, this
initial round of key exchanging and session-key
negotiations is completely transparent to the
end user.

[linux server security oreilly page 118-119]

SSH can secure these [X POP3 LPD] and most other
TCP based services! Forwarding X applications
back to your remote console is simple. First,
on the the remote host, edit /etc/ssh/sshd_config
and set X11Forwarding to yes (in OpenSSH Version
2x, the default is no). Second, open an ssh session using
the authentication method of your choice from your
local console to the remote host.

book [inside network perimeter security, sams second edition]

chapter 16 page 397 The Dangers of SSH
... be sure to ue the latest software versions and to keep
current with all the patchs, Also configure your SSH
servers to only permit the use of the SSH2 protocol,
instead of SSH1.

page 398. SSH Tunnels.
port forwardinging.
SSH has a powerful capability called port forwarding.
In port forwarding, an abitrary local port is chosen and
linked by an SSH connection to a particular remote host
and remote port.
After the connection is established, the SSH client listens
for traffic on the specified local port. Any traffic that
is sent to the that port is then sent through the tunnel
to the the remote SSH server. This technique is know
as SSH tunneling.

[end quote]

plans
finish building 2.6 gento book+udev
emerge ssh ... login to ssh remotely
rc-update ssh.
what risks are associated with ssh?

[more from LINUX Server Security page 125-127]
... to control the behavior of the SSH client and server [ssh],
there are only two files to edit: ssh_config and sshd_config, respectively.

ssh_config is a global configuration file for ssh sessions
intitiated from the local host.
ssh_config consists of a list of parameters, one line per parameter,
in the format:

parameter-name parameter-value1(,parameter-value2,etc.)

Sunday, April 03, 2005

Created rootfs files: /etc

I want to create premade user accounts

From "Running Linux page 141"
ever account on the system has an entry in the file /etc/passwd.
this file contains entries, one line per user ...

username:password:uid:gid:gecos:homedir:shell

username (obvious)
password and encrypted representation of the users password.
uid
the user id is a unique integer the system uses to identify the account.
... the uid is more important to the system
gid the group id ... refering to the users default group
found in the file /etc/gorup
gecos miscellaneous inforation about the user
homedir: the users home directory
shell: the name of the progr run when the user logs in.

Tossed 2.4.2x and moved 2.6 + udev

In the next interation of the machine build I will start with
the kernel 2.6 and use udev.
I had all the parts working apache+mysql+bugzill and
ssh as a stand alone (no integration with apache)

see the following
http://www.gentoo.org/doc/en/udev-guide.xml
and it eliminated the errors i was getting about
about modprobe

Friday, April 01, 2005

MySql Bugzilla

ok mysql has a two part process of install
you need to have a root or sa user
then have a bugzilla user and
all the grant tables working.

$> /etc/init.d/mysql start
$> mysqladmin -u root flush-privileges password "password"
$> mysql -u root -p
Enter password: password
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.0.22

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> exit
Bye

the above worked see the page:
http://www.ladse.de/index.php/Installation:Gentoo:MySQL

now i have tried to run the bugzilla checksetup.pl script
and here is what i get.

Creating database bugs ...

The 'bugs' database could not be created. The error returned was:

Access denied for user: '@localhost' to database 'bugs'

but this makes sense because really all i have done is setup
the basic mysql exe and the system tables
but is there a complete bugzilla db with tables and a user?
i dont know is the answer to this. so what do i need to do?
i need to have command line tools to query the db status.

yes there are fine graphical tools but i need things
i can script. (i dont want to fart with web shots
on this blog)

ok
i ran mysql command

$> mysql -u root -p
and then ran the following query:

mysql> select Host,User from mysql.user;
+-----------+------+
| Host | User |
+-----------+------+
| localhost | |
| localhost | root |
+-----------+------+
2 rows in set (0.00 sec)

there is currently one user.

so i pretty much know i need
to add a user called bugs.

i looked up the mysql documentation online
and adding a user seems to be
be more about 'grant' than 'create user'
anyway the link is:
http://dev.mysql.com/doc/mysql/en/adding-users.html

GRANT ALL PRIVILEGES on *.* to 'bugs'@'localhost'
-> IDENTIFIED BY 'password' with GRANT OPTION;
GRANT ALL PRIVILEGES on *.* to 'bugs'@'%'
->IDENTIFIED BY 'password' WITH GRANT OPTION;

so i have created user 'bugs' on the bugs database
with the password 'password'
i have deliberately made this simple i may change
the passwords later but for now i want something
simple easy to remember as move along.

i then reran ./checksetup.pl from the bugzilla
source dirctory same problem again
but the inuited that i would need to check
the password entry :

$db_pass = ''

ah!

i changed this to
$db_pass = 'password'
and re-ran ./checksetup.pl

tada it start creating a bunch
of tables and user accounts.

i went back and put the link in my
browser;
http://localhost/bugzilla/
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.0.52 (Gentoo/Linux) Server at xxxx Port 80

so what next?
i could debug the index.cgi script?
or is it something in the localconfig script?

i found the following line in the error logs
[Fri Apr 01 13:43:00 2005] [alert] [client 192.168.x.x] /var/www/localhost/htdocs/bugzilla/.htaccess: AllowOverride not allowed

i did some digging in the bugzilla docs and found this.

4.2.6. .htaccess files and security
....
The default .htaccess file may not provide adequate access restrictions, depending on your web server configuration. Be sure to check the entries for your Bugzilla directory so that the .htaccess file is allowed to override web server defaults. For instance, let's assume your installation of Bugzilla is installed to /usr/local/bugzilla . You should have this entry in your httpd.conf file:
<Directory /usr/local/bugzilla/>
Options +FollowSymLinks +Indexes +Includes +ExecCGI
AllowOverride All
</Directory>


I DID NOT HAVE THIS.
I added the following and went back and tried the site.
tada! the bugzilla site came up.