Archive

You are currently browsing the archives for the howto category.

Oct

12

Quick ‘n dirty way to wig together an RPM

By cormander

The following is a non-elegant, non-standard, don’t-ever-do-this-unless-you-know-what-you-are-doing way of creating an RPM based off of what you have installed on your system. If I get some time later I’ll create a more “proper” script and update this article with a link to it.

Say you have kernel-xen-2.6.18-92.el5 installed on your system, but don’t have the RPM for it. Say all centos mirror servers simultaneously combusted; poof, gone. Say you wanted to roll out the kernel to other nodes, but wanted to do it with RPM. Here is how you’d create a hack-n-slash RPM file with all the files from the RPM:

Create this file: /tmp/filelist

/lib/modules/2.6.18-92.el5
/boot/config-2.6.18-92.el5
/boot/initrd-2.6.18-92.el5.img
/boot/symvers-2.6.18-92.el5.gz
/boot/System.map-2.6.18-92.el5
/boot/vmlinuz-2.6.18-92.el5

The above is a list of files and directories you want to copy into the RPM. With the following script, if you list a directory, do not list any subdirs. I haven’t even bothered testing that yet. I’ll refine that if I ever take another, more in-depth whack at this.

Create this script: mkRPMfromBinaries.sh

(be sure to edit the name/version/release values with what you want your package to be)

#!/bin/bash

name=kernel-xen
version=2.6.18
release=92

filelist=/tmp/filelist

if [ ! -f $filelist ]; then
        echo "Please create a list of files to make the RPM from in: $filelist"
        exit 1
fi

cat << EOF > /tmp/$name.spec
Name: $name
Version: $version
Release: $release%{?dist}
Summary: CHANGEME

Group: System Environment/Base
License: CHANGEME
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

AutoReq: on

%description
CHANGEME

%prep

%build

%install
rm -rf \$RPM_BUILD_ROOT

for i in \$(cat $filelist); do
        mkdir -p \`dirname \$RPM_BUILD_ROOT/\$i\`
        cp -a \$i \$RPM_BUILD_ROOT/\$i
done

%clean
rm -rf \$RPM_BUILD_ROOT

%files -f $filelist
%defattr(-,root,root,-)

%changelog
EOF

rpmbuild -bb /tmp/$name.spec

Make it executable, and run it (as root). Assuming you have the 2.6.18-92.el5 kernel-xen package installed, it’ll create a RPM for you.

Note that the RPM it generates doesn’t have the pre or post scripts, and is nothing more than a container for all the files you specified. It’s a very hackish way to create an RPM. Don’t ever do this. Not ever! I’m serious! And since you’re doing it anyway, don’t come crying to me if you get unintended results.

Have a great day.

Jun

27

Installing a 32bit build chroot

By cormander

Sometimes it’s just easier to have a 32bit system to build 32bit packages on, but we don’t always have that option. And creating a virtual machine may just be too much overhead. After all, you just want some 32bit packages to be built on your 64bit system and not have to worry about multi-arch problems at build time. Here is how I usually solve the problem.

First, fool rpm into thinking this is a 32bit system:

mv /etc/rpm/platform /etc/rpm/platform.orig

echo i686-redhat-linux > /etc/rpm/platform

Then make your target directory. In this case I’m doing Fedora 11:

mkdir -p /var/distro/Fedora11.i386
cd /var/distro/Fedora11.i386

Now you’re in the directory you’re going to install in. This is important as I reference this directory throughout this tutorial as $(pwd). If you cd out of this directory in the middle of these steps, you’re bound to run into problems.

Setup some basic items:

mkdir -p dev proc sys root etc var/{log/yum,lib/rpm}

mount -t proc none proc
mount -t sysfs none sys

cp /etc/resolv.conf etc/

You don’t need an fstab, but no harm in creating one. You’ll actually avoid some meaningless errors by creating it:

cat << EOF > etc/fstab
/dev/xvda2              /                       ext3    defaults        1 1
/dev/xvda1              /boot                   ext2    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
EOF

Create your /dev/null device and give it the mark of the beast:

mknod dev/null c 1 3
chmod 666 dev/null

For Fedora 11:

rpm --root $(pwd) --import http://mirrors.kernel.org/fedora/releases/11/Fedora/i386/os/RPM-GPG-KEY-fedora
wget http://mirrors.kernel.org/fedora/releases/11/Fedora/i386/os/Packages/fedora-release-11-1.noarch.rpm
rpm --root $(pwd) --nodeps -ivh fedora-release-11-1.noarch.rpm

For CentOS 5:

rpm --root $(pwd) --import http://mirrors.kernel.org/centos/5/os/i386/RPM-GPG-KEY-CentOS-5
wget http://mirrors.kernel.org/centos/5/os/i386/CentOS/centos-release-5-3.el5.centos.1.i386.rpm
rpm --root $(pwd) --nodeps -ivh centos-release-5-3.el5.centos.1.i386.rpm

Now install. This may take a while, depending on your internet connection speed.

yum --installroot=$(pwd) -y install kernel rootfiles passwd vim-enhanced wget strace grub \
    openssh-server openssh-clients gcc patchutils diffutils gcc make rpm-build rpmdevtools sudo yum

Now wipe out the rpm db, it’ll get rebuilt next time it’s used:

rm -f var/lib/rpm/__db.00*

Lastly, don’t forget to restore your rpm arch configuration:

mv /etc/rpm/platform.orig /etc/rpm/platform

Now you can do this:

setarch i686 chroot $(pwd)

Anything you build while in this chroot is guaranteed to be completely 32bit and have no 64bit related build problems.

Oct

16

Run a script at boot w/o needing a full sysvinit-style script

By cormander

Sometimes you want something to run at boot, but you can’t use chkconfig because you haven’t written a full blown sysvinit-sytle script to facilitate the operation. You’d probably just want to add it to rc.local, but perhaps you want it to run before a certian sysviinit-style script, for example, before the network starts or before apache starts? The rc.local can’t do this, since it’s ran last.

Well here is a quick way to add a custom script to the boot process w/o too much work. Since I have to do this on occasion, I thought I’d post about it.

First you cd into your rc.d directory:

[root@localhost ~]# cd /etc/rc.d/

Now create your script in your favorite editor (or just copy it here):

[root@localhost rc.d]# vi rc.myscript

Don’t forget to make it executable!

[root@localhost rc.d]# chmod +x rc.myscript

Now create a link to it in /etc

[root@localhost rc.d]# cd ..
[root@localhost etc]# ln -s rc.d/rc.myscript ./

Now add it to each runlevel you want it to run in. You probably care most about runlevel 3 and 5:

[root@localhost etc]# cd rc3.d/
[root@localhost rc3.d]# ln -s ../rc.myscript S00myscript
[root@localhost rc3.d]# cd ..
[root@localhost etc]# cd rc5.d/
[root@localhost rc5.d]# ln -s ../rc.myscript S00myscript

The S00 portion of the link is important. S stands for “on startup” (or more correctly, on runlevel change where this would start). The K stands for “on shutdown” (or more correctly, on runlevel change where it needs to be turned off). Don’t worry about creating a link for the K as this isn’t a init script with “start/stop” commands.

The number is two digits, and determines when it is run, in numerical order, staring from 00. For example, network on my system is S10network which means it starts pretty early in the boot process. Apache is S85httpd which means it starts pretty late in the boot process.

Have a look to see when things boot up, and number yours accordingly.

Sep

23

Xen guest install guide

By cormander

Very similar to my Install FC9 into a chroot from a DVD iso article, I have created a new page on this site:

Quick CentOS5 Xen paravirt guest install

It’s a page because I’m going to keep it updated as much as possible with kernel versions and such so people can continue to copy/paste out of it.

Feedback is welcome, just send me an email.

May

15

Install FC9 into a chroot from a DVD iso

By cormander

I often download distributions just for a build environment, I don’t actually install it on the whole system. This makes testing basic packages among different flavors of linux very easy to do.

Since I mainly use these for building and running basic programs, I generally don’t want to have to add the extra overhead of using a virtual machine, so I put the entire OS inside of a chroot on my base OS.

In this example, I’m installing Fedora Core 9 into a chroot environment using the DVD iso I downlaoded, and the yum utility. The base OS I have here is CentOS 5, but it can be any OS that has yum installed.

These steps work to install pretty much any fedora distribution; in fact, anything these steps work for any distribution that is RPM based and uses “XML Repo” package headers, so it can be setup with yum. It works on CentOS, RHEL, and believe it or not, opensuse (the latest versions of the “yast” utility uses XML Repo).

Here we go:

# create target directories
mkdir -p /var/distro/Fedora-9/dev
mkdir -p /var/distro/Fedora-9/etc
mkdir -p /var/distro/Fedora-9/proc
mkdir -p /var/distro/Fedora-9/var/lib/rpm
mkdir -p /var/distro/Fedora-9/mnt/fc9-dvd
cp /etc/resolv.conf /var/distro/Fedora-9/etc/

# setup the installroot so yum works inside it
mknod /var/distro/Fedora-9/dev/null c 1 3
mount -t proc none /var/distro/Fedora-9/proc
rpm --root /var/distro/Fedora-9 --initdb

# mount your Fedora-9 DVD iso image
# NOTE: change /PATH/TO/ to the path to your .iso file
mount -o loop /PATH/TO/Fedora-9-i386-DVD.iso /var/distro/Fedora-9/mnt/fc9-dvd

# create a symlink to the target iso mount
ln -s /var/distro/Fedora-9/mnt/fc9-dvd /mnt/

# force the install of the release file so we can use its contents for yum
rpm --root /var/distro/Fedora-9 -Uvh --nodeps /var/distro/Fedora-9/mnt/fc9-dvd/Packages/fedora-release-9-2.noarch.rpm

# import the Fedora GPG key
rpm --root /var/distro/Fedora-9 --import http://download.fedora.redhat.com/pub/fedora/linux/releases/9/Fedora/i386/os/RPM-GPG-KEY-fedora

Now you need to edit the main repo file:

vi /var/distro/Fedora-9/etc/yum.repos.d/fedora.repo

Comment out the “mirrorlist” line, and under it add a new line:

baseurl=file:///mnt/fc9-dvd/

Also, edit the updates file and turn it off:

vi /var/distro/Fedora-9/etc/yum.repos.d/fedora-updates.repo

Change “enabled=1″ to “enabled=0″

Then proceed with the installation:

yum --installroot=/var/distro/Fedora-9 -y install wget bash gcc rpm-build \
   make yum rootfiles pam pam-devel bzip2-devel curl-devel gmp-devel \
   libjpeg-devel libpng-devel smtpdaemon ncurses-devel freetype-devel \
   vim-minimal

You can add stuff or remove stuff from that list as needed. I added gcc, rpm-build, patch, make, and a few devel packages because I use this as a build environment. You’re welcome to change the “yum install” line as you see fit.

After you’re done, simply chroot into the base directory:

chroot /var/distro/Fedora-9

From in there, you can use the system as normal.

NOTE: if you want to install updates, be sure to re-enable the updates repo!

vi /etc/yum.repos.d/fedora-updates.repo
yum update

And that’s it, you’re done. Happy Fedora’ing.

May

1

upgrade yum on centos5

By cormander

CentOS5 uses yum-3.0. Nothing wrong with this, it’s a good version (whole loads better then yum-2.x) but I miss the features that are coming out in the latest versions used in Fedora. I decided to try giving an upgrade to yum a whirl.

Short story even shorter, here is a list of RPMs I had to build from source to get all the new dependancies:

glib2-2.16.3-5.fc9.src.rpm
pygpgme-0.1-8.fc9.src.rpm
python-iniparse-0.2.3-3.fc9.src.rpm
python-setuptools-0.6c7-2.fc8.src.rpm
yum-3.2.14-10.fc9.src.rpm
yum-metadata-parser-1.1.2-8.fc9.src.rpm
yum-utils-1.1.13-2.fc9.src.rpm

As you might have noticed, they’re from fedora core 9. It hasn’t been released yet, but it’s so close to the release date that I’m not worried about them being that unstable.

I rebuilt these, installed their dependencies via yum to build / install them, and the upgrade to yum went perfect; I’m finding no conflicts so far. The only issue I had with rebuilding the source RPMs was the yum-metadata-parser package was trying to glob a non-existent file pattern so the build failed; a quick commenting out of this line in the %files section fixed the issue.

If I don’t encounter any problems with this upgrade between now and when I post all my RPMs from my packages directory, I’ll include pre-built RPMs for this yum upgrade on CentOS5 as well (and maybe even CentOS4).

Apr

25

Upgrade wordpress with a patch

By cormander

Wordpress 2.5.1 is out, and they recommend an upgrade. I was annoyed to find that they didn’t release a patch to upgrade from 2.5 -> 2.5.1… so I went ahead and made my own:

wget http://wordpress.org/wordpress-2.5.tar.gz
mv wordpress wordpress-2.5
wget http://wordpress.org/latest.tar.gz
mv wordpress wordpress-2.5.1
diff -ruN wordpress-2.5 wordpress-2.5.1 > upgrade.patch

Then I cd’d into my wordpress install and did:

patch –dry-run -p1 -i upgrade.patch

There were a few offsets, but no hunk failures… my hacks to wordpress have lived through the upgrade. Since this showed no failures, I went ahead and ran it without the –dry-run, and then logged into the admin section and clicked the “upgrade database” button.

All done. That wasn’t too bad.

Apr

13

Magpie RSS feeds

By cormander

For anyone who was wondering, I’m using Magpie RSS feeds on the front page: http://magpierss.sourceforge.net/

Mediawiki and Wordpress have rss capability by default. phpbb2 on the other hand, I’m using a rss plugin for.

It works great. Very simple to implement. Here is the specific function call I wrote to further simply the 4 feeds into one function:

function get_rss($feed) {

$rss = fetch_rss($feed);

for($i = 0; $i < 4; $i++) {
if ( !$rss->items[$i] ) break;
$str .= '<div class="poststamp">' . $rss->items[$i]['title'] . '</div>';
$str .= '<p>' . ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
"<a href=\"\\0\">\\0</a>",substr(strip_tags($rss->items[$i]['description']), 0, 150)) . '... ';
$str .= '<a class="more" href="' . $rss->items[$i]['link'] . '">Read More</a></p>';
}

return $str;
}

Hope this helps someone.

Apr

10

php PAM support (part 2)

By cormander

Nothing like spending my lunch break finding out (for the millionth time) that I’m an idiot. All the googling last night… compiling… all completely in the wrong direction. I tend to do this, dive into new things head-strong and go for hours before reading any offical docs. If I had just read the “how to install a pecl module” I would have saved myself hours. In my defense, the link wasn’t that obvious! Grr.

Here is how I got php-pam to install as a php module:

pecl install pam

I couldn’t believe it, that was it. Well, there were still steps to do after that, but it was all a breeze for me from then on. For the sake of you readers dieing to know how to complete the steps…

* ln -s login /etc/pam.d/php
* create the file /etc/php.d/pam.ini with these contents:
extension=pam.so
pam.servicename = “php”;
* chmod 444 /etc/shadow
* service httpd restart

Now a call in a php script to pam_auth(’username’,'password’); works, either returning true on success or false on failure. Now obviously having these lax permissions on /etc/shadow is a BAD thing, I simply did it as a proof-of-concept to get the php-pam to work (processes need read permissions to /etc/shadow if they want to use pam_unix.so, which is in the login configuration). So I went ahead and put 400 permissions back on /etc/shadow until I get an alternative method of pam auth for my scripts.

So turns out there will be a part 3 to this, but it’ll outline what I did to get all the users in a database and authenticating off of pam (probably using pam_exec.so or pam_userdb.so). Once I tie mediawiki, wodrpress, and phpbb together via PAM I’ll post patches on this site for the rest of the world to use.

As far as user management goes, I think I’m going to go with php deadlock because it’s small and simple, and I can edit it to add/remove some features I need/don’t need.

Until next time folks!

Apr

10

php PAM support (part 1)

By cormander

Now that I have phpbb, mediawiki, wodrpess, and a few other back-end applications on this webserver, all using different authentication schemas… I thought; “Why not tie it all together with PAM?”

Long story short (several hours of my time condensed down into a paragraph) php doesn’t come with PAM support. WHAT?!?!?!?! C’mon guys, give me a break! After all that googling for PAM plugins for the aforementioned software… I finally find a phpbb PAM plugin and look at it’s code; it uses a pam helper program to talk to pam, NOT a php function.

So I go to the php website, and sure enough, a search for pam comes up short. I went on google and searched for php PAM and didn’t like what I found. The only support for php-pam is with a pecl package (well, I guess that’s better then no PAM support at all).

http://pecl.php.net/package/PAM

So I downloaded the php source RPM I was using, then started to install the build dependencies via yum. Great, missing dependencies. That’s right, I disabled the centosplus after I upgraded php to version 5 because I had to rollback some of the other things it updated (broke) on my system (this is a centos4 box). Not wanting to go through that all over again, I decided to build it on my local machine.. since this webserver is a lowly virtual machine itself, not a whole lot of umph to it.

So I created a “poor man’s virtual machine”. What is that? It’s a chroot with all the build libs of a specific enviroment. Not that hard to do… it can be done very easily on any machine that has yum. It goes something like this:

mkdir -p /var/distro/centos4/
mkdir -p /var/distro/centos4/var/lib/rpm
mkdir -p /var/distro/centos4/proc
mkdir -p /var/distro/centos4/dev
mkdir -p /var/distro/centos4/etc
cp /etc/resolv.conf /var/distro/centos4/etc
mount -t proc none /var/distro/centos4/proc
mknod /var/distro/centos4/dev/null c 1 3
rpm --root /var/distro/centos4/ --initdb
wget http://mirror.centos.org/centos/4.6/os/i386/CentOS/RPMS/centos-release-4-4.4.i386.rpm
rpm -Uvh --nodeps --root /var/distro/centos4/ centos-release-4-4.4.i386.rpm
yum installroot=/var/distro/centos4/ -y install wget bash gcc rpm-build \
  make yum rootfiles pam pam-devel bzip2-devel curl-devel gmp-devel \
  libjpeg-devel libpng-devel smtpdaemon ncurses-devel freetype-devel

Then go to lunch. It’ll resolve all the RPM dependencies and download/install about 150 packages into your chroot /var/distro/centos4

After you get back and it’s done, run this:

chroot /var/distro/centos4/

Now you’re in a “Poor man’s virtual machine”. A nice little build environment of centos4 on a machine that’s something else (I’m running CentOS 5). From here, you can build the needed RPM and install any other libs you need w/o affecting your base system at all.

I’d use a tool like Xen or VMWare, but I don’t need a full blown virtual machine to be a build environment. Besides, those take up extra CPU, and when you’re compiling a big package, this works just as well and goes faster.

So, I do all this, add the pam-1.0.2.tgz to the source, make other nessisary edits to it (add –with-pam to the build) and rebuild the RPM. Well, pam got compiled into the cgi version of php, but no modularized .so file was created. Hmm… does this pam code not support being used as under php as an apache module, or did I just forget something.

I’ll find out later. This process went into the AM and I didn’t even have enough energy to write about it. I waited until morning. I’ll post part 2 of this scenario after it happens. I hope there isn’t a part 3.