#!/bin/bash
#
# mk-images
#
# Copyright (C) 2007 Red Hat, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
LANG=C
PATH=$PATH:/sbin:/usr/sbin
IMAGEUUID=$(date +%Y%m%d%H%M).$(uname -i)
TMPDIR=${TMPDIR:-/tmp}
usage () {
echo "usage: mk-images []"
exit 0
}
NEEDGR=yes
DEBUG=""
BUILDARCH=`uname -m`
BOOTISO="boot.iso"
while [ $# -gt 0 ]; do
case $1 in
--nogr)
NEEDGR=""
shift
;;
--debug)
DEBUG="--debug"
shift
;;
--noiso)
BOOTISO=""
shift
;;
--arch)
BUILDARCH=$2
shift; shift
;;
--mindir)
INSTIMGTEMPLATE=$2
shift; shift
;;
--stg2dir)
IMGPATH=$2
shift; shift
;;
--product)
PRODUCT=$2
shift; shift
;;
--version)
VERSION=$2
shift; shift
;;
--bugurl)
BUGURL=$2
shift; shift
;;
--output)
TOPDESTPATH=$2
shift; shift
;;
*)
yumconf=$1
shift
;;
esac
done
if [ -z "$TOPDESTPATH" -o -z "$INSTIMGTEMPLATE" -o -z "$IMGPATH" -o -z "$PRODUCT" -o -z "$VERSION" ]; then usage; fi
TOPDIR=$(echo $0 | sed "s,/[^/]*$,,")
if [ $TOPDIR = $0 ]; then
$TOPDIR="."
fi
TOPDIR=$(cd $TOPDIR; pwd)
# modules that are needed. this is the generic "needed for every arch" stuff
COMMONMODS="fat vfat nfs sunrpc lockd floppy cramfs loop edd pcspkr squashfs ipv6 virtio_pci"
USBMODS="ohci-hcd uhci-hcd ehci-hcd hid mousedev usb-storage sd_mod sr_mod ub appletouch"
FIREWIREMODS="ohci1394 sbp2 fw-ohci fw-sbp2 firewire-sbp2 firewire-ohci"
IDEMODS="ide-cd ide-cd_mod"
SCSIMODS="sr_mod sg st sd_mod scsi_mod iscsi_tcp"
FSMODS="fat msdos vfat ext2 ext3 ext4dev reiserfs jfs xfs gfs2 lock_nolock cifs"
LVMMODS="dm-mod dm-zero dm-snapshot dm-mirror dm-multipath dm-round-robin dm-emc dm-crypt"
RAIDMODS="raid0 raid1 raid5 raid6 raid456 raid10 linear"
CRYPTOMODS="sha256_generic cbc aes_generic crypto_blkcipher crc32c"
PCMCIASOCKMODS="yenta_socket i82365 tcic pcmcia"
DRMMODS="drm i810 i830 i915 mga nouveau r128 radeon savage sis tdfx via"
INITRDMODS="$USBMODS $FIREWIREMODS $IDEMODS $SCSIMODS $FSMODS $LVMMODS $RAIDMODS $CRYPTOMODS $COMMONMODS $PCMCIASOCKMODS $DRMMODS =scsi =net"
. $(dirname $0)/buildinstall.functions
# Set, verify, and create paths
IMAGEPATH=$TOPDESTPATH/images
FULLMODPATH=$TMPDIR/instimagemods.$$
FINALFULLMODPATH=$IMGPATH/modules
INSTIMGPATH=$TOPDESTPATH/images
KERNELBASE=$TMPDIR/updboot.kernel.$$
KERNELNAME=vmlinuz
if [ "$BUILDARCH" = "ia64" ]; then
KERNELDIR="/boot/efi/EFI/redhat"
else
KERNELDIR="/boot"
fi
if [ "$BUILDARCH" = "sparc64" ]; then
BASEARCH=sparc
else
BASEARCH=$BUILDARCH
fi
# explicit block size setting for some arches (FIXME: we compose
# ppc64-ish trees as ppc, so we have to set the "wrong" block size)
if [ "$BUILDARCH" = "sparc64" ]; then
CRAMBS="--blocksize 8192"
elif [ "$BUILDARCH" = "sparc" ]; then
CRAMBS="--blocksize 4096"
else
CRAMBS=""
fi
if [ $BUILDARCH = x86_64 -o $BUILDARCH = s390x ]; then
LIBDIR=lib64
else
LIBDIR=lib
fi
rm -rf $IMAGEPATH
rm -rf $FULLMODPATH
rm -rf $FINALFULLMODPATH
rm -rf $KERNELBASE
mkdir -p $IMAGEPATH
mkdir -p $FULLMODPATH
mkdir -p $FINALFULLMODPATH
mkdir -p $KERNELBASE
mkdir -p $INSTIMGPATH
# Stuff that we need
TRIMPCIIDS=$IMGPATH/usr/lib/anaconda-runtime/trimpciids
GETKEYMAPS=$IMGPATH/usr/lib/anaconda-runtime/getkeymaps
GENINITRDSZ=$IMGPATH/usr/lib/anaconda-runtime/geninitrdsz
MKS390CDBOOT=$IMGPATH/usr/lib/anaconda-runtime/mk-s390-cdboot
GENMODINFO=$IMGPATH/usr/lib/anaconda-runtime/genmodinfo
KEYMAPS=$TMPDIR/keymaps-$BUILDARCH.$$
SCREENFONT=$IMGPATH/usr/lib/anaconda-runtime/screenfont-${BASEARCH}.gz
MODLIST=$IMGPATH/usr/lib/anaconda-runtime/modlist
MODINFO=$TMPDIR/modinfo-$BUILDARCH.$$
LOADERBINDIR=$IMGPATH/usr/lib/anaconda-runtime/loader
BOOTDISKDIR=$IMGPATH/usr/lib/anaconda-runtime/boot
LANGTABLE=$IMGPATH/usr/lib/anaconda/lang-table
PCIIDS=$IMGPATH/usr/share/hwdata/pci.ids
XDRIVERS=$IMGPATH/usr/share/hwdata/videoaliases
XDRIVERDESCS=$IMGPATH/usr/share/hwdata/videodrivers
REQUIREMENTS="$TRIMPCIIDS $PCIIDS $XDRIVERDESCS $GENMODINFO
$LANGTABLE $GETKEYMAPS"
dieLater=
for n in $REQUIREMENTS; do
if [ ! -f $n ]; then
echo "$n doesn't exist"
dieLater=1
fi
done
for n in $BOOTDISKDIR; do
if [ ! -d $n ]; then
echo "$n doesn't exist"
dieLater=1
fi
done
if [ -n "$dieLater" ]; then exit 1; fi
if [ "$BUILDARCH" != "s390" -a "$BUILDARCH" != "s390x" ]; then
# go ahead and create the keymaps so we only have to do it once
if [ -f $IMGPATH/usr/lib/anaconda-runtime/keymaps-override-$BUILDARCH ]; then
echo "Found keymap override, using it"
cp $IMGPATH/usr/lib/anaconda-runtime/keymaps-override-$BUILDARCH $KEYMAPS
else
echo "Running: $GETKEYMAPS $BUILDARCH $KEYMAPS $IMGPATH"
$GETKEYMAPS $BUILDARCH $KEYMAPS $IMGPATH
if [ $? != 0 ]; then
echo "Unable to create keymaps and thus can't create initrd."
exit 1
fi
fi
fi
findPackage() {
name=$1
pkg=$(repoquery --qf "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}" -c $yumconf --archlist=$KERNELARCH $name.$KERNELARCH)
if [ -n "$pkg" ]; then
echo $pkg
return
fi
echo "cannot find package $name" >&2
}
rundepmod () {
where=$1
$FAKEARCH /sbin/depmod -a -F $KERNELROOT/boot/System.map-$version \
-b $where $version
}
# This loops to make sure it resolves dependencies of dependencies of...
resdeps () {
items="$*"
deplist=""
for item in $items ; do
deps=$(awk -F ':' "/$item.ko: / { print gensub(\".*/$item.ko: \",\"\",\"g\") }" $KERNELROOT/lib/modules/$version/modules.dep)
for dep in $deps ; do
depfile=${dep##*/}
depname=${dep%%.ko}
deplist="$deplist $depname"
done
done
items=$(for n in $items $deplist; do echo $n; done | sort -u)
echo $items
}
expandModuleSet() {
SET=""
for name in $1; do
char=$(echo $name | cut -c1)
if [ $char = '=' ]; then
NAME=$(echo $name | cut -c2-)
SET="$SET $($MODLIST --modinfo-file $MODINFO $NAME)"
else
SET="$SET $name"
fi
done
echo $SET
}
makemoduletree() {
MMB_DIR=$1
MMB_MODULESET=$(resdeps $2)
mkdir -p $MMB_DIR/lib
mkdir -p $MMB_DIR/modules
mkdir -p $MMB_DIR/firmware
ln -snf ../modules $MMB_DIR/lib/modules
ln -snf ../firmware $MMB_DIR/lib/firmware
echo "Copying kernel modules..."
cp -a $KERNELROOT/lib/modules/* $MMB_DIR/lib/modules/
echo "Removing extraneous modules..."
find $MMB_DIR/lib/modules/ -name *.ko | while read module ; do
m=${module##*/}
modname=${m%%.ko}
echo $MMB_MODULESET | grep -wq $modname || {
rm -f $module
}
done
# Copy in driver firmware we want during installation. NOTE: This isn't
# the ideal solution, but we'll do this for now. What we really want is
# for the kernel modules to include a modinfo field that names the firmware
# file we should have. If we can get that it would make it even easier to
# push the kernel people to depend on the firmware packages in the kernel,
# but we have to take small steps first.
for module in $MODSET ; do
case $module in
ipw2100)
cp $KERNELROOT/lib/firmware/ipw2100* $MBD_DIR/firmware
;;
ipw2200)
cp $KERNELROOT/lib/firmware/ipw-2.4* $MBD_DIR/firmware
cp $KERNELROOT/lib/firmware/ipw2200* $MBD_DIR/firmware
;;
iwl3945)
cp $KERNELROOT/lib/firmware/iwlwifi-3945* $MBD_DIR/firmware
;;
iwl4965)
cp $KERNELROOT/lib/firmware/iwlwifi-4965* $MBD_DIR/firmware
;;
atmel)
cp $KERNELROOT/lib/firmware/atmel_*.bin $MBD_DIR/firmware
;;
zd1211rw)
cp -r $KERNELROOT/lib/firmware/zd1211 $MBD_DIR/firmware
;;
qla2xxx)
cp $KERNELROOT/lib/firmware/ql* $MBD_DIR/firmware
;;
esac
done
# clean up leftover cruft
find -H $MMB_DIR/lib/modules -type d -exec rmdir -f {} \; 2>/dev/null
$MODLIST --modinfo-file $MODINFO --ignore-missing --modinfo \
$MMB_MODULESET > $MMB_DIR/lib/modules/module-info
# compress modules
find -H $MMB_DIR/lib/modules -type f -name *.ko -exec gzip -9 {} \;
rundepmod $MMB_DIR
rm -f $MMB_DIR/lib/modules/*/modules.*map
rm -f $MMB_DIR/lib/modules/*/{build,source}
# create the pci.ids, from modules.alias and the X driver aliases
awk '!/^(\t\t|#)/ { print ;if ($0 == "ffff Illegal Vendor ID") nextfile; }' < $PCIIDS | \
$TRIMPCIIDS $MMB_DIR/lib/modules/*/modules.alias $XDRIVERS/* > ../pci.ids
}
makeproductfile() {
root=$1
rm -f $root/.buildstamp
echo $IMAGEUUID > $root/.buildstamp
echo $PRODUCT >> $root/.buildstamp
echo $VERSION >> $root/.buildstamp
if [ -n "$BUGURL" ]; then
echo $BUGURL >> $root/.buildstamp
fi
}
instbin() {
ROOT=$1
BIN=$2
DIR=$3
DEST=$4
install -s -m 755 $ROOT/$BIN $DIR/$DEST
get_dso_deps $ROOT "$BIN"
local DEPS="$DSO_DEPS"
mkdir -p $DIR/$LIBDIR
for x in $DEPS ; do
cp -Lfp $ROOT/$x $DIR/$LIBDIR
done
pushd $DIR/$LIBDIR
if [ -f ld-linux.so.2 ]; then
rm -f ld-linux.so.2
linker="$(ls -1 ld-*.*.*.so)"
found=$(echo $linker | wc -l)
if [ $found -ne 1 ]; then
echo "Found too many dynamic linkers:" >&2
echo $linker >&2
exit 1
fi
ln -s $linker ld-linux.so.2
fi
popd
}
setupShellEnvironment() {
echo "tcp 6 TCP" > $MBD_DIR/etc/protocols
# PAM configuration
for i in pam_limits.so pam_env.so pam_unix.so pam_deny.so; do
cp -f $IMGPATH/$LIBDIR/security/$i $MBD_DIR/$LIBDIR/security
done
cp -f $IMGPATH/etc/pam.d/other $MBD_DIR/etc/pam.d
cat > $MBD_DIR/etc/pam.d/login << EOF
#%PAM-1.0
auth required pam_env.so
auth sufficient pam_unix.so likeauth nullok
auth required pam_deny.so
account required pam_unix.so
password sufficient pam_unix.so nullok use_authtok md5 shadow
password required pam_deny.so
session required pam_limits.so
session required pam_unix.so
EOF
cp -f $MBD_DIR/etc/pam.d/login $MBD_DIR/etc/pam.d/sshd
cp -f $MBD_DIR/etc/pam.d/login $MBD_DIR/etc/pam.d/remote
cp -f $IMGPATH/etc/security/{limits.conf,pam_env.conf} $MBD_DIR/etc/security/
# key generation takes ages on s390, you really don't want this for every
# installation attempt. These are NOT the keys of the installed system!
mkdir -m 0700 -p $MBD_DIR/etc/ssh
echo -n "Generating SSH1 RSA host key: "
/usr/bin/ssh-keygen -q -t rsa1 -f $MBD_DIR/etc/ssh/ssh_host_key \
-C '' -N '' >&/dev/null
echo
echo -n "Generating SSH2 RSA host key: "
/usr/bin/ssh-keygen -q -t rsa -f $MBD_DIR/etc/ssh/ssh_host_rsa_key \
-C '' -N '' >&/dev/null
echo
echo -n "Generating SSH2 DSA host key: "
/usr/bin/ssh-keygen -q -t dsa -f $MBD_DIR/etc/ssh/ssh_host_dsa_key \
-C '' -N '' >&/dev/null
echo
(cd $MBD_DIR/etc/ssh; \
chmod 600 ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; \
chmod 644 ssh_host_key.pub ssh_host_rsa_key.pub ssh_host_dsa_key.pub; )
cat > $MBD_DIR/etc/ssh/sshd_config <&1| awk '/^\t([[:alnum:]_\.\[]+,)+/' | sed 's/,//g' | sed 's/ +//');
while [ -n "$1" ]; do
if [ $1 != "busybox" -a $1 != "sh" ]; then
# if file doesnt already exist, link to busybox
if [ ! -f "$1" ]; then
ln -sf ./busybox $1
else
[ -n "$DEBUG" ] && echo "Overriding busybox version of $1"
fi
fi
shift
done )
}
makeinitrd() {
EXTRAINITRDPATH=""
INITRDSIZE=""
KEEP=""
PADSIZE=""
LOADERBIN=""
INITRDMODULES=""
MYLANGTABLE=$LANGTABLE
MYLOADERTR=loader.tr
while [ x$(echo $1 | cut -c1-2) = x"--" ]; do
if [ $1 = "--initrdto" ]; then
EXTRAINITRDPATH=$2
shift; shift
continue
elif [ $1 = "--keep" ]; then
KEEP=yes
shift
continue
elif [ $1 = "--initrdsize" ]; then
INITRDSIZE=$2
shift; shift
continue
elif [ $1 = "--loaderbin" ]; then
LOADERBIN=$2
shift; shift
continue
elif [ $1 = "--modules" ]; then
INITRDMODULES=$2
shift; shift
continue
fi
echo "Unknown option passed to makeinitrd"
exit 1
done
if [ -z "$LOADERBIN" ]; then
echo "no loader binary specified!" >&2
exit 1
fi
if [ -z "$INITRDMODULES" ]; then
echo "warning: no loader modules specified!" >&2
fi
if [ -z "$INITRDSIZE" ]; then
echo "I don't know how big to make the initrd image!" >&2
exit 1
fi
MBD_DIR=$TMPDIR/makebootdisk.dir.$$
MBD_FSIMAGE=$TMPDIR/makebootdisk.initrdimage.$$
MBD_BOOTTREE=$TMPDIR/makebootdisk.tree.$$
rm -rf $MBD_DIR $MBD_FSIMAGE
mkdir -p $MBD_DIR/modules
mkdir -p $MBD_DIR/sbin
mkdir -p $MBD_DIR/dev
mkdir -p $MBD_DIR/etc
mkdir -p $MBD_DIR/proc
mkdir -p $MBD_DIR/selinux
mkdir -p $MBD_DIR/sys
mkdir -p $MBD_DIR/tmp
mkdir -p $MBD_DIR/etc/terminfo/{a,b,d,l,s,v,x}
mkdir -p $MBD_DIR/etc/udev/rules.d
mkdir -p $MBD_DIR/etc/modprobe.d
mkdir -p $MBD_DIR/var/run
mkdir -p $MBD_DIR/var/lock/rpm
if [ "$BUILDARCH" = "ppc" -o "$BUILDARCH" = "ppc64" ]; then
mkdir -p $MBD_DIR/dev/iseries
fi
if [ "$BUILDARCH" = "s390" -o "$BUILDARCH" = "s390x" ]; then
mkdir -m 111 -p $MBD_DIR/var/empty/sshd
mkdir -p $MBD_DIR/etc/{pam.d,security}
mkdir -p $MBD_DIR/$LIBDIR/security
cp $IMGPATH/$LIBDIR/libpam_misc.so.0.* $MBD_DIR/$LIBDIR/libpam_misc.so.0
ln -s /tmp $MBD_DIR/var/state/xkb
cp $IMGPATH/usr/bin/xauth $MBD_DIR/sbin/xauth
cp $IMGPATH/usr/sbin/cmsfs* $MBD_DIR/sbin/
fi
if [ -n "$INITRDMODULES" ]; then
MODSET=`expandModuleSet "$INITRDMODULES"`
makemoduletree $MBD_DIR "$MODSET"
fi
# set up the arch bits
echo $arch > $MBD_DIR/etc/arch
echo "Setting up arch bits"
instbin $IMGPATH ${LOADERBINDIR##$IMGPATH}/$LOADERBIN $MBD_DIR /sbin/loader
if [ "$BUILDARCH" != "s390" -a "$BUILDARCH" != "s390x" ]; then
instbin $IMGPATH ${LOADERBINDIR##$IMGPATH}/init $MBD_DIR /sbin/init
ln -s ./init $MBD_DIR/sbin/reboot
ln -s ./init $MBD_DIR/sbin/halt
ln -s ./init $MBD_DIR/sbin/poweroff
else
instbin $IMGPATH ${LOADERBINDIR##IMGPATH}/shutdown $MBD_DIR /sbin/shutdown
instbin $IMGPATH /usr/lib/anaconda-runtime/loader/linuxrc.s390 $MBD_DIR /sbin/init
instbin $IMGPATH /usr/sbin/dasdfmt $MBD_DIR /sbin/dasdfmt
fi
if [ "$BUILDARCH" != "s390" -a "$BUILDARCH" != "s390x" ]; then
install -m 644 $KEYMAPS $MBD_DIR/etc/keymaps.gz
install -m 644 $SCREENFONT $MBD_DIR/etc/screenfont.gz
fi
install -m 644 $MYLANGTABLE $MBD_DIR/etc/lang-table
install -m 644 $IMGPATH/etc/passwd $MBD_DIR/etc/passwd
install -m 644 $IMGPATH/etc/group $MBD_DIR/etc/group
install -m 644 $IMGPATH/etc/nsswitch.conf $MBD_DIR/etc/nsswitch.conf
instbin $IMGPATH /usr/bin/mount $MBD_DIR /sbin/mount
instbin $IMGPATH /usr/sbin/mount.nfs $MBD_DIR /sbin/mount.nfs
instbin $IMGPATH /usr/bin/umount $MBD_DIR /sbin/umount
ln -s mount.nfs $MBD_DIR/sbin/umount.nfs
instbin $IMGPATH /usr/sbin/udevd $MBD_DIR /sbin/udevd
instbin $IMGPATH /usr/sbin/udevadm $MBD_DIR /sbin/udevadm
ln -s udevadm $MBD_DIR/sbin/udevsettle
# Indirect dependencies
install -m 755 $IMGPATH/$LIBDIR/libnss_dns.so.2 $MBD_DIR/$LIBDIR/
install -m 755 $IMGPATH/$LIBDIR/libnss_files.so.2 $MBD_DIR/$LIBDIR/
install -m 755 $IMGPATH/$LIBDIR/libgcc_s.so.1 $MBD_DIR/$LIBDIR/
install -m 644 $IMGPATH/etc/udev/udev.conf $MBD_DIR/etc/udev/udev.conf
for i in $IMGPATH/etc/udev/rules.d/*.rules ; do
install -m 644 $i $MBD_DIR/etc/udev/rules.d/${i##*/}
done
rm -f $MBD_DIR/etc/udev/rules.d/*persistent*
rm -f $MBD_DIR/etc/udev/rules.d/*generator*
install -m 644 $LOADERBINDIR/$MYLOADERTR $MBD_DIR/etc/loader.tr
for i in a/ansi d/dumb l/linux s/screen v/vt100 v/vt100-nav v/vt102 x/xterm x/xterm-color g/gnome ; do
[ -f $IMGPATH/usr/share/terminfo/$i ] && \
install -m 644 $IMGPATH/usr/share/terminfo/$i $MBD_DIR/etc/terminfo/$i
done
makeproductfile $MBD_DIR
for n in insmod rmmod modprobe; do
instbin $IMGPATH /usr/sbin/$n $MBD_DIR /sbin/$n
done
ln -s /usr/bin/sh $MBD_DIR/sbin/sh
ln -s /sbin/init $MBD_DIR/init
ln -s /proc/mounts $MBD_DIR/etc/mtab
ln -s sbin $MBD_DIR/bin
mkdir -p $MBD_DIR/var/lib
ln -s ../../tmp $MBD_DIR/var/lib/xkb
# s390/s390x need sshd setup
if [ "$BUILDARCH" = "s390" -o "$BUILDARCH" = "s390x" ]; then
setupShellEnvironment
fi
cat > $MBD_DIR/.profile < $MBD_FSIMAGE
size=$(du $MBD_FSIMAGE | awk '{ print $1 }')
echo "Wrote $MBD_FSIMAGE (${size}k compressed)"
if [ -n "$EXTRAINITRDPATH" ]; then
mkdir -p `dirname $EXTRAINITRDPATH`
cp -a $MBD_FSIMAGE $EXTRAINITRDPATH
fi
if [ -z "$KEEP" ]; then
rm -rf $MBD_FSIMAGE $MBD_BOOTTREE
fi
}
makeinstimage () {
imagename=$1
type=$2
tmp=$TMPDIR/instimage.dir.$$
rm -rf $tmpimage $tmp
mkdir -p $mntpoint $tmp
mkdir -p $tmp
(cd $INSTIMGTEMPLATE; find . | cpio --quiet -p $tmp)
makeproductfile $tmp
if [ -z "$type" -o "$type" = "cramfs" ]; then
echo "Running mkcramfs $CRAMBS $tmp $INSTIMGPATH/${imagename}2.img"
mkfs.cramfs $CRAMBS $tmp $TMPDIR/${imagename}2.img.$$
elif [ "$type" = "squashfs" ]; then
echo "Running mksquashfs $tmp $TMPDIR/${imagename}2.img -all-root -no-fragments -no-progress"
mksquashfs $tmp $TMPDIR/${imagename}2.img.$$ -all-root -no-fragments -no-progress
chmod 0644 $TMPDIR/${imagename}2.img.$$
fi
cp $TMPDIR/${imagename}2.img.$$ $INSTIMGPATH/${imagename}2.img
size=$(ls -l $INSTIMGPATH/${imagename}2.img | awk '{print $5}')
size=$(expr $size / 1024)
echo "Wrote $INSTIMGPATH/${imagename}2.img (${size}k)..."
relpath=${INSTIMGPATH#$TOPDESTPATH/}
echo "instimage = ${relpath}/${imagename}2.img" >> $TOPDESTPATH/.treeinfo
rm -rf $tmp
}
makemainimage () {
imagename=$1
type=$2
mmi_tmpimage=$TMPDIR/instimage.img.$$
mmi_mntpoint=$TMPDIR/instimage.mnt.$$
rm -rf $mmi_tmpimage $mmi_mntpoint
mkdir $mmi_mntpoint
if [ $type = "ext2" ]; then
SIZE=$(du -sk $IMGPATH | awk '{ print int($1 * 1.1) }')
if [ -d $IMGPATH/usr/lib/anaconda-runtime ]; then
ERROR=$(du -sk $IMGPATH/usr/lib/anaconda-runtime | awk '{ print $1 }')
SIZE=$(expr $SIZE - $ERROR)
fi
dd if=/dev/zero bs=1k count=${SIZE} of=$mmi_tmpimage 2>/dev/null
mke2fs -q -F $mmi_tmpimage > /dev/null
tune2fs -c0 -i0 $mmi_tmpimage >/dev/null
mount -o loop $mmi_tmpimage $mmi_mntpoint
(cd $IMGPATH; find . | fgrep -v "./usr/lib/anaconda-runtime" |
cpio -H crc -o) | (cd $mmi_mntpoint; cpio -iumd)
makeproductfile $mmi_mntpoint
umount $mmi_mntpoint
rmdir $mmi_mntpoint
elif [ $type = "squashfs" ]; then
makeproductfile $IMGPATH
echo "Running mksquashfs $IMGPATH $mmi_tmpimage -all-root -no-fragments -no-progress"
mksquashfs $IMGPATH $mmi_tmpimage -all-root -no-fragments -no-progress
chmod 0644 $mmi_tmpimage
SIZE=$(expr `cat $mmi_tmpimage | wc -c` / 1024)
elif [ $type = "cramfs" ]; then
makeproductfile $IMGPATH
echo "Running mkcramfs $CRAMBS $IMGPATH $mmi_tmpimage"
mkfs.cramfs $CRAMBS $IMGPATH $mmi_tmpimage
SIZE=$(expr `cat $mmi_tmpimage | wc -c` / 1024)
fi
cp $mmi_tmpimage $INSTIMGPATH/${imagename}.img
chmod 644 $INSTIMGPATH/${imagename}.img
echo "Wrote $INSTIMGPATH/${imagename}.img (${SIZE}k)"
relpath=${INSTIMGPATH#$TOPDESTPATH/}
echo "mainimage = ${relpath}/${imagename}.img" >> $TOPDESTPATH/.treeinfo
rm $mmi_tmpimage
}
makeSecondStage() {
echo "[stage2]" >> $TOPDESTPATH/.treeinfo
echo "Building minstg.img"
makeinstimage "minstg" "squashfs"
[ $? = 0 ] || exit 1
echo "Building stage2.img"
makemainimage "stage2" "squashfs"
[ $? = 0 ] || exit 1
}
doPostImages() {
/bin/true
}
# this gets overloaded if we're on an EFI-capable arch (... with grub)
makeEfiImages()
{
/bin/true
}
# source the architecture specific mk-images file so we can call functions
# in it
if [ ${BUILDARCH} = s390x ]; then
# FIXME: this is a bad hack for s390, but better than copying for now
source $TOPDIR/mk-images.s390
elif [ ${BUILDARCH} = ppc64 ]; then
# ... and similar for ppc64
source $TOPDIR/mk-images.ppc
elif [ ${BUILDARCH} = "x86_64" -o ${BUILDARCH} = "i386" ]; then
source $TOPDIR/mk-images.x86
source $TOPDIR/mk-images.efi
else
source $TOPDIR/mk-images.${BUILDARCH}
fi
# Find the kernel, unpack it, and verify it
kerneltags="kernel"
efiarch=""
arches="$BUILDARCH"
if [ "$BUILDARCH" = "ppc" ]; then
arches="ppc64 ppc64iseries ppc"
elif [ "$BUILDARCH" = "i386" ]; then
arches="i586"
efiarch="ia32"
kerneltags="kernel kernel-xen"
elif [ "$BUILDARCH" = "x86_64" ]; then
kerneltags="kernel kernel-xen"
efiarch="x64"
elif [ "$BUILDARCH" = "ia64" ]; then
kerneltags="kernel kernel-xen"
efiarch="ia64"
fi
foundakernel=""
for KERNELARCH in $arches; do
for kernelvers in $kerneltags; do
kpackage=$(findPackage $kernelvers)
if [ "$KERNELARCH" = "i586" -a -z "$kpackage" ]; then
echo "No i586 kernel, trying i686..."
KERNELARCH="i686"
kpackage=$(findPackage $kernelvers)
fi
if [ -z "$kpackage" ]; then
echo "Unable to find kernel package $kernelvers"
continue
fi
yumdownloader -c $yumconf --archlist=$KERNELARCH $kpackage
kpackage="$kpackage.rpm"
if [ ! -f "$kpackage" ]; then
echo "kernel ($kernelvers) doesn't exist for $KERNELARCH. skipping"
continue
fi
KERNELROOT=$KERNELBASE/$KERNELARCH
mkdir -p $KERNELROOT
foundakernel="yes"
if [ "${kernelvers}" = "kernel-xen" ]; then kerneltag="xen" ; fi
if [ "$BUILDARCH" = "ia64" ]; then
vmlinuz=$(rpm --nodigest --nosignature -qpl $kpackage |grep ^/boot/efi/EFI/redhat/vmlinuz | head -n 1)
version=${vmlinuz##/boot/efi/EFI/redhat/vmlinuz-}
else
vmlinuz=$(rpm --nodigest --nosignature -qpl $kpackage |grep ^/boot/vmlinuz | head -n 1)
version=${vmlinuz##/boot/vmlinuz-}
fi
arch=$(rpm --nodigest --nosignature --qf '%{ARCH}\n' -qp $kpackage)
rpm2cpio $kpackage | (cd $KERNELROOT; cpio --quiet -iumd)
rm -f $kpackage
# expand out any available firmware too
for p in $(repoquery -c $yumconf '*firmware*') ; do yumdownloader -c $yumconf $p ; rpm2cpio *firmware*.rpm | (cd $KERNELROOT; cpio --quiet -iumd) ; rm -f *firmware*.rpm ; done
if [ ! -d "$KERNELROOT/lib/modules/$version" ]; then
echo "$KERNELROOT/lib/modules/$version is not a valid modules directory" 2>&1
exit 1
fi
if [ ! -f "$KERNELROOT/$KERNELDIR/${KERNELNAME}-$version" ]; then
echo "$KERNELROOT/$KERNELDIR/${KERNELNAME}-$version does not exist"
exit 1
fi
allmods=$(find $KERNELROOT/lib/modules/$version -name *.ko)
rundepmod $KERNELROOT
$GENMODINFO $KERNELROOT/lib/modules/$version > $MODINFO
# make the boot images
makeBootImages
makeEfiImages $yumconf
done
done
# do some clean up before making the cramfs of the second stage
rm -rf $INSTIMGTEMPLATE/usr/lib/anaconda-runtime $INSTIMGTEMPLATE/usr/lib/syslinux $IMGPATH/usr/lib/syslinux
if [ -n "$foundakernel" ]; then
makeSecondStage
rm -rf $KERNELBASE
fi
doPostImages
cd $TOPDIR