# Settings !!!*** PLEASE MODIFY THESE ***!!!
export MIRROR="ftp://ftp.mirror.ac.uk/mirror/fedora.redhat.com/6/i386/os/Fedora/RPMS/"
export TMPDIR=`pwd`"/tmp2"
export ROOT_FS=`pwd`"/FedoraCore6-x86-root_fs"
export RPM_DIR=`pwd`"/RPMS"
export CHROOTCMD="linux32 chroot"
export RPMCMD="linux32 rpm"
export PACKAGES="packages.i386"
export ARCHES="i386 i486 i586 i686 noarch"
export DEBUG=""
export DUPES=""
function doGetRPM() {
rpmfile=""
if [ ! -z "$DEBUG" ]; then
echo "grep $1 $PACKAGES | grep $2 | wc -l"
fi
rpmfilescount=`grep ^$1 $PACKAGES | grep $2 | wc -l`
#echo "filecount=$rpmfilescount"
if [ "$rpmfilescount" -eq 0 ]; then
if [ ! -z "$DEBUG" ]; then
echo "No RPMs found for $1 - $2"
fi
else
if [ "$rpmfilescount" == "1" ]; then
# echo "Found "`$grep`
rpmfile=`grep ^$1 $PACKAGES | grep $2`
else
if [ ! -z "$DEBUG" ]; then
echo "Too many packages matching $1: $rpmfilescount"
fi
rpmfile=`grep ^$1 $PACKAGES | grep $2 | sort | head -n 1`
fi
fi
}
function getRPM() {
for arch in $ARCHES; do
doGetRPM $1- $arch
if [ ! -z "$rpmfile" ]; then
return
fi
done
for arch in $ARCHES; do
doGetRPM $1 $arch
if [ ! -z "$rpmfile" ]; then
return
fi
done
echo "No RPM package found for $1"
exit 1
}
function fetch() {
base=$1
getRPM $base
local=$RPM_DIR"/$rpmfile"
echo "fetch() base=$base, local=$local, rpmfile=$rpmfile"
if [ ! -e "$local" ]; then
echo "Downloading $base ($rpmfile)"
wget -c -O $local "$MIRROR$rpmfile"
fi
}
function rpminstall() {
base=$1
fetch $base
stripped=`echo $base | sed 's+/.noarch++g' | sed 's+/.86++g'`
exists="0"
if [ ! -z "$DUPES" ]; then
exists=`$RPMCMD -qa --root $TMPDIR | grep $stripped | wc -l`
fi
if [ "$exists" -ne "0" ]; then
echo "skipped: $stripped"
else
$RPMCMD -Uvh --root $TMPDIR $local
rm -fr $TMPDIR/var/lib/rpm/__db*
fi
}
function rpminstallgroup() {
echo "SIZE="$#
list=""
while [ $# -ne 0 ]
do
package=$1
fetch $package
stripped=`echo $1 | sed 's+/.noarch++g' | sed 's+/.x86_64++g'`
exists="0"
if [ ! -z "$DUPES" ]; then
exists=`$RPMCMD -qa --root $TMPDIR | grep $stripped | wc -l`
fi
if [ "$exists" -ne "0" ]; then
echo "skipped: $stripped"
else
list="$list $local"
fi
shift
done
# echo "installing list=$list"
# echo "installcommand=$RPMCMD -ivh --root $TMPDIR $list"
$RPMCMD -Uvh --root $TMPDIR $list
rm -fr $TMPDIR/var/lib/rpm/__db*
}
# Making the filesystem
if [ ! -e "$ROOT_FS" ]; then
dd if=/dev/zero of=$ROOT_FS bs=1024 count=1 seek=1572864
mkfs.ext3 $ROOT_FS
else
echo "Filesystem already created"
fi
if [ ! -e "$TMPDIR" ]; then
mkdir $TMPDIR
mount -o loop $ROOT_FS $TMPDIR
else
echo "Filesystem already mounted"
fi
mkdir -p $RPM_DIR
#rpm bug?
mkdir -p $TMPDIR/var/lock/rpm
mkdir -p $TMPDIR/var/lib/rpm
if [ ! -e "$TMPDIR/var/lib/rpm" ]; then
echo "initrpm:"
echo "$RPMCMD --initdb --root $TMPDIR"
$RPMCMD --initdb --root $TMPDIR
rm -fr $TMPDIR/var/lib/rpm/__db*
fi
if [ ! -e "$TMPDIR/dev" ]; then
mkdir $TMPDIR/dev
mknod $TMPDIR/dev/null c 1 3
fi
echo "going to fetch"
# pretend to have a kernel (we don't need one):
fetch kernel-2.6.18-1.2798.fc6.i686.rpm
$RPMCMD -Uvh --justdb --force --nodeps --root $TMPDIR $local
rm -fr $TMPDIR/var/lib/rpm/__db*
mkdir -p $TMPDIR/etc
# copy the fstab, passwd, shadow and group (root=/dev/ubda)
cp fstab $TMPDIR/etc/
cp passwd $TMPDIR/etc/
cp group $TMPDIR/etc/
cp shadow $TMPDIR/etc/
mkdir $TMPDIR/usr/kerberos
# Installing the packages
# no deps for these - got problems otherwise
packages="fedora-release-notes glibc libsepol pam passwd usermode setup filesystem basesystem util-linux libgcc tzdata termcap libtermcap zlib zip man-pages mktemp bash ncurses info gawk vim-common libattr libacl libstdc++ pcre grep cracklib-dicts glib2 fedora-release chkconfig sed iputils rootfiles ethtool audit-libs popt libsysfs sysfsutils cpio less gzip readline tar db4 iproute mingetty libselinux libsemanage SysVinit module-init-tools hwdata sysklogd udev procps diffutils libcap vim-minimal findutils device-mapper e2fsprogs-libs e2fsprogs net-tools shadow lvm2 MAKEDEV psmisc bzip2-libs libxml beecrypt expat sqlite tcp_wrappers gdbm coreutils cracklib python openssl libgssapi krb5-libs libselinux-python initscripts db4 glibc-headers audit-libs-python policycoreutils libselinux-python libsemanage mkinitrd dmraid rpm rpm-libs"
for package in $packages; do
fetch $package
$RPMCMD -Uvh --force --noscripts --nodeps --root $TMPDIR $local
rm -fr $TMPDIR/var/lib/rpm/__db*
done
mkdir $TMPDIR/etc/profile.d
# some extras
packages="which vixie-cron krb5-libs python-urlgrabber neon elfutils-libelf elfutils-libs elfutils openssh openssh-clients openssh-server wget python-elementtree python-sqlite elfutils rpm-python yum-metadata-parser dhcp"
for package in $packages; do
rpminstall $package
done
#$RPMCMD -e --nodeps --root $TMPDIR rpm
#fetch rpm
#$RPMCMD -ivh --force --nodeps --root $TMPDIR $local
# rpm gets confused by these:
rm -f $TMPDIR/var/lib/rpm/__db*
# yum needs to be installed by the real rpm...
fetch yum-3.0.6
cp $local $TMPDIR/root
$CHROOTCMD $TMPDIR rpm -Uvh /root/yum*rpm
rm $TMPDIR/root/yum*rpm
# ldconfig the newly installed libraries
ldconfig -r $TMPDIR
# create the ubd devices
if [ ! -e "$TMPDIR/dev/ubda" ]; then
if [ -e "$TMPDIR/dev" ]; then
for ((i=0; i<8; i++))
do
let=$(echo $i|tr '0-7' 'a-z')
mknod $TMPDIR/dev/ubd$let b 98 $[16 * $i]
for ((p=1; p<=16; p++)) do
mknod $TMPDIR/dev/ubd$let$p b 98 $[16 * $i + $p]
done
done
else
echo "/dev not found!"
exit 1
fi
fi
# basic devices so we can boot without an initrd:
cp -avpr /dev/console /dev/null /dev/zero $TMPDIR/dev
mkdir $TMPDIR/dev/pts
# copy current resolv
cp /etc/resolv.conf $TMPDIR/etc
# use yum to update the system
mount -t proc none $TMPDIR/proc
echo "/dev/ROOT / ext3 rw 0 0" > $TMPDIR/etc/mtab
$CHROOTCMD $TMPDIR rpm --rebuilddb
$CHROOTCMD $TMPDIR yum update
umount $TMPDIR/proc
# tweak the inittab to only use tty0 and add it to securetty
tweaked=`grep tty0 $TMPDIR/etc/inittab | wc -l`
if [ "$tweaked" -eq "0" ]; then
cp $TMPDIR/etc/inittab $TMPDIR/etc/inittab.save
grep -v "mingetty" $TMPDIR/etc/inittab.save > $TMPDIR/etc/inittab
echo "# We launch just one console for UML:" >> $TMPDIR/etc/inittab
echo "c0:1235:respawn:/sbin/mingetty tty0" >> $TMPDIR/etc/inittab
echo "# UML modification: use tty0" >> $TMPDIR/etc/securetty
echo "tty0" >> $TMPDIR/etc/securetty
fi
# We need an /etc/hosts file!
echo "127.0.0.1 localhost localhost.localdomain" > $TMPDIR/etc/hosts
# make the first network interface start with dhcp
#cp $TMPDIR/etc/rc.d/rc.inet1.conf $TMPDIR/etc/rc.d/rc.inet1.conf.save
chroot $TMPDIR yum install dhclient
cp ifcfg-eth0 $TMPDIR/etc/sysconfig/networking/devices/ifcfg-eth0
cp ifcfg-eth0 $TMPDIR/etc/sysconfig/networking/profiles/default/ifcfg-eth0
cp ifcfg-eth0 $TMPDIR/etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETWORKING=yes" > $TMPDIR/etc/sysconfig/network
echo "HOSTNAME=localhost.localdomain" >> $TMPDIR/etc/sysconfig/network
# clear specific settings:
echo "" > $TMPDIR/etc/resolv.conf
# clear rest of image
dd if=/dev/zero of=$TMPDIR/blank >& /dev/null
sync
rm $TMPDIR/blank
umount $TMPDIR
rmdir $TMPDIR
echo "Done!"
参考连接: http://uml.nagafix.co.uk/FedoraCore6/