Use at your own risk, and YMMV!
# rpm --import
http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-4
# rpm -Uvh
ftp://sunsite.utk.edu/pub/linux/caos/centos/4.0/os/i386/CentOS/RPMS/centos-release-4-0.1.i386.rpm
# yum install glibc glibc-common
# yum install {kernel|kernel-smp} *(if this give you errors installing lvm2 read the note at the end of the post)
# rpm -e kernel-smp-2.4.21-27.0.2.EL (the release number may vary depending on your system)
# yum upgrade
conflict between udev and kernel
# rpm -qa|grep kernel
# rpm -e kernel-2.4-whatever
Also remember before rebooting to view the new kernel's initrd image size and generate a new one to compare.
# ls -l initrd-2.6.9-5.0.3.ELsmp.img
-rw-r--r-- 1 root root 195325 Mar 2 16:09 initrd-2.6.9-5.0.3.ELsmp.img
# mkinitrd initrd-2.6.9-5.0.3.ELsmp.img.new 2.6.9-5.0.3.ELsmp
# ls -l initrd-2.6.9-5.0.3.ELsmp.img.new
-rw-r--r-- 1 root root 474840 Mar 3 11:39 initrd-2.6.9-5.0.3.ELsmp.img.new
If this differs in size, like mines, move the old image to a different file name and cut off the '.new' extension in the new one's filename
# mv initrd-2.6.9-5.0.3.ELsmp.img initrd-2.6.9-5.0.3.ELsmp.img.dist
# mv initrd-2.6.9-5.0.3.ELsmp.img.new initrd-2.6.9-5.0.3.ELsmp.img
You need this in order to permit grub loading the new initrd (or change the grub.conf to point to the new generated initrd image, make your choice).
As you see the rpm generated initrd is smaller than the manually generated, which means there's something wrong in the rpm postinstall script. Make sure of this and take a lot of care before rebooting (otherwise be ready with a rescue CD to boot and follow the above procedure).
P.S.: you may have need of cutting the "smp" letters in the kernel name, depending on your hardware configuration.
I forgot to mention some important changes between 3.4 and 4.0 release. One of most important is the name changing of some packages, like rpmdb. On CentOS 3.4 that package has the name "rpmdb-redhat" while in 4.0 it has "rpmdb-CentOS". There's now way to upgrade it since it's a totally different name and the package install paths are different by the old one.
Just install the new rpmdb-CentOS through Yum or simply downloading it and installing with rpm -ivh, then remove with rpm -e the old rpmdb-redhat.
*NOTE: Possible errors installing lvm2 package
==============================
Yum may give errors trying to install the lvm2 package, since lvm1 is already installed and files may go to be conflicting (I had this issue only on two systems, the third worked perfectly, don't ask me why). The only solution I found is to manually install the downloaded rpms located in the /var/cache/yum/base/packages directory, just remember to use the --replacefiles switch to install lvm2, and later erase lvm1, like described below:
# cd /var/cache/yum/base/packages
# rpm -Uvh --replacefiles lvm2*.rpm (and some dependencies must follow)