CentOS bootstrapper for chroot(2) environment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi,

just some script built along: Unattended install & run CentOS-4.1 just using
chroot(1). Mostly a surprise for me it was so easy to reach that goal.

It requires rpm(1) based host OS and it was tested only on Fedora Core 4.
I needed it to do only a bit customized CentOS kernel package rebuild.


Regards,
Lace
-------------- next part --------------
#! /bin/bash
# Bootstrap for: CentOS-4.1
# $Id: centos-bootstrap,v 1.4 2005/09/03 03:07:17 short Exp $
# Latest:
# 	http://cvs.jankratochvil.net/viewcvs/nethome/src/centos-bootstrap?rev=HEAD


RPMS_URL_BASE=http://rsync.atworks.co.jp/centos/4.1/os/i386/CentOS/RPMS


if test $# != 1;then echo >&2 "Syntax: $0 <target-root-directory(DELETED!)>";exit 1;fi
ROOT="$1"
if test "${ROOT#/}" = "$ROOT";then echo >&2 "Absolute pathname required: $ROOT";exit 1;fi

cd /
umount $ROOT/proc
set -ex

KEY=/tmp/centos-bootstrap-$$-key
rm -rf $KEY
trap 'rm -f $KEY' EXIT
mkdir $KEY
cd $KEY
# wget(1) due to: https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=167483
wget -q -O - $RPMS_URL_BASE/centos-release-4-1.2.i386.rpm | rpm2cpio | cpio -id

rm -rf $ROOT
mkdir -p $ROOT/{etc,dev}
awk '/^[ \t]*[^#]/ { if ($2 == "/") { print; }}' </etc/fstab >$ROOT/etc/fstab
cp -a /dev/{null,urandom,random} `awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' </etc/fstab` $ROOT/dev/
rpm --root=$ROOT --initdb
rpm --root=$ROOT --import $KEY/usr/share/doc/centos-release-4/RPM-GPG-KEY
rm -rf $KEY
cd $RPMS
# For rpm(1) http:// downloads:
mkdir -p $ROOT/var/tmp
RPM=rpm
while read -r key val;do
	if test -n "$val";then RPM="$RPM $key $val";fi
	done <<EOH
--httpproxy `echo $http_proxy|sed -n 's#^[^/]*//\([^:/]*\).*$#\1#p'`
--httpport  `echo $http_proxy|sed -n 's#^[^/]*//[^:/]*:\([^/]*\).*$#\1#p'`
 --ftpproxy `echo  $ftp_proxy|sed -n 's#^[^/]*//\([^:/]*\).*$#\1#p'`
 --ftpport  `echo  $ftp_proxy|sed -n 's#^[^/]*//[^:/]*:\([^/]*\).*$#\1#p'`
EOH

# rpm(8)
$RPM --root=$ROOT -i `set +x;while read -r line;do echo $RPMS_URL_BASE/$line;done <<EOH
rpm-4.3.3-9_nonptl.i386.rpm
bash-3.0-19.2.i386.rpm
glibc-2.3.4-2.9.i686.rpm
beecrypt-3.1.0-6.i386.rpm
mktemp-1.5-20.i386.rpm
libgcc-3.4.3-22.1.i386.rpm
basesystem-8.0-4.noarch.rpm
filesystem-2.3.0-1.i386.rpm
setup-2.5.37-1.1.noarch.rpm
glibc-common-2.3.4-2.9.i386.rpm
popt-1.9.1-9_nonptl.i386.rpm
shadow-utils-4.0.3-41.1.i386.rpm
coreutils-5.2.1-31.1.i386.rpm
pam-0.77-66.5.i386.rpm
libselinux-1.19.1-7.i386.rpm
sed-4.1.2-4.i386.rpm
cracklib-2.7-29.i386.rpm
db4-4.2.52-7.1.i386.rpm
initscripts-7.93.13.EL-2.centos4.i386.rpm
kernel-2.6.9-11.EL.i686.rpm
sysklogd-1.4.1-26_EL.i386.rpm
util-linux-2.12a-16.EL4.6.i386.rpm
grep-2.5.1-31.i386.rpm
gawk-3.1.3-10.1.i386.rpm
libstdc++-3.4.3-22.1.i386.rpm
glib2-2.4.7-1.i386.rpm
module-init-tools-3.1-0.pre5.3.i386.rpm
mkinitrd-4.2.1.3-1.i386.rpm
net-tools-1.60-37.EL4.6.i386.rpm
e2fsprogs-1.35-12.1.EL4.i386.rpm
findutils-4.1.20-7.i386.rpm
ncurses-5.4-13.i386.rpm
ethtool-1.8-4.i386.rpm
tzdata-2005f-1.EL4.noarch.rpm
pcre-4.5-3.i386.rpm
gzip-1.3.3-13.i386.rpm
lvm2-2.01.08-1.0.RHEL4.i386.rpm
less-382-4.i386.rpm
chkconfig-1.3.13.2-1.i386.rpm
cpio-2.5-7.EL4.1.i386.rpm
device-mapper-1.01.01-1.RHEL4.i386.rpm
tar-1.14-4.i386.rpm
readline-4.3-13.i386.rpm
info-4.7-5.i386.rpm
zlib-1.2.1.2-1.i386.rpm
centos-release-4-1.2.i386.rpm
cracklib-dicts-2.7-29.i386.rpm
mingetty-1.07-3.i386.rpm
iputils-20020927-16.i386.rpm
rpm-libs-4.3.3-9_nonptl.i386.rpm
bzip2-libs-1.0.2-13.i386.rpm
libacl-2.2.23-5.i386.rpm
libtermcap-2.0.8-39.i386.rpm
libattr-2.4.16-3.i386.rpm
termcap-5.4-3.noarch.rpm
elfutils-libelf-0.97-5.i386.rpm
psmisc-21.4-4.i386.rpm
iproute-2.6.9-3.i386.rpm
procps-3.2.3-8.1.i386.rpm
SysVinit-2.85-34.i386.rpm
libsepol-1.1.1-2.i386.rpm
udev-039-10.8.EL4.i386.rpm
MAKEDEV-3.15-2.i386.rpm
hotplug-2004_04_01-7.5.i386.rpm
usbutils-0.11-6.1.i386.rpm
hwdata-0.146.10.EL-1.noarch.rpm
wget-1.9.1-17.i386.rpm
openssl-0.9.7a-43.2.i686.rpm
krb5-libs-1.3.4-12.i386.rpm
EOH
`

chroot $ROOT /bin/rpm --rebuilddb

# Do not install yum(8) just by 'rpm --root', later --rebuilddb would:
# 	rpmdb: Program version 4.2 doesn't match environment version
# FIXME: Analyse and bugreport:
# On "http" installation AND using --httpproxy: CentOS-4.1 rpm-4.3.3-9_nonptl would crash:
# 	warning: package yum = 2.2.1-1.centos4 was already added, replacing with yum <= 2.2.1-1.centos4
# 	...
# 	error: Failed dependencies:
# 		/usr/bin/python is needed by yum-2.2.1-1.centos4.noarch
# 		...
# while with FC4 rpm-4.4.1-22 it would work fine (it would just corrupt 'rpmdb' here).
# yum(8)
lines="`cat <<EOH
yum-2.2.1-1.centos4.noarch.rpm
python-2.3.4-14.1.i386.rpm
rpm-python-4.3.3-9_nonptl.i386.rpm
libxml2-python-2.6.16-6.i386.rpm
gmp-4.1.4-3.i386.rpm
libxml2-2.6.16-6.i386.rpm
elfutils-0.97-5.i386.rpm
binutils-2.15.92.0.2-13.i386.rpm
gdbm-1.8.0-24.i386.rpm
centos-yumconf-4-4.2.noarch.rpm
EOH
`"
chroot $ROOT /usr/bin/wget -nv `set +x;for line in $lines;do echo $RPMS_URL_BASE/$line;done`
chroot $ROOT /bin/rpm -i $lines
chroot $ROOT /bin/rm -f $lines

chroot $ROOT /usr/bin/yum -y update

# For: kernel-2.6.9-11.EL.src.rpm
chroot $ROOT /usr/bin/yum -y install `cat <<EOH
rpm-build
bzip2
m4
make
gnupg
kernel-utils
gcc
redhat-rpm-config
diffutils
EOH
`

echo OK

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux