3 # Builds a Fedora Core reference image. Requires the build server to
4 # host a local yum repository in one of:
6 # /usr/share/mirrors/fedora
7 # /var/www/html/mirrors/fedora
9 # Otherwise, tries using CoBlitz:
11 # http://coblitz.planet-lab.org/pub/fedora
13 # Mark Huang <mlhuang@cs.princeton.edu>
14 # Copyright (C) 2004-2006 The Trustees of Princeton University
16 # $Id: mkfedora,v 1.3 2006/03/29 19:19:19 mlhuang Exp $
19 export PATH=/sbin:/bin:/usr/sbin:/usr/bin
24 # Default yum repositories to try
26 file:///usr/share/mirrors/fedora
27 file:///var/www/html/mirrors/fedora
28 ftp://smoke.cs.princeton.edu/pub/mirrors/fedora
29 ftp://128.112.137.30/pub/mirrors/fedora
30 http://coblitz.planet-lab.org/pub/fedora
31 ftp://mirror.cs.princeton.edu/pub/mirrors/fedora
34 # Release and architecture to install
38 # Yum groups to install
46 echo "Usage: mkfedora [OPTION]... [basedir]"
47 echo " -l url Fedora mirror location. Defaults to try:"
48 for mirror in "${mirrors[@]}" ; do
51 echo " -r release Fedora release number (default: $releasever)"
52 echo " -a arch Fedora architecture (default: $basearch)"
53 echo " -g group1 -g group2 ..."
54 echo " Yumgroups to install (default: none)"
55 echo " -p package1 -p package2 ..."
56 echo " Additional packages to install (default: none)"
58 echo " -h This message"
63 while getopts "l:r:a:g:p:vh" opt ; do
66 if echo $OPTARG | grep -q -i '^\(file\|http[s]*\)://' ; then
69 mirrors=(file://$OPTARG)
79 groups[${#groups[*]}]="$OPTARG"
82 packages[${#packages[*]}]="$OPTARG"
94 shift $(($OPTIND - 1))
95 if [ ! -d "$1" ] ; then
99 vroot=$(cd $1 && pwd -P)
101 if [ $UID -ne 0 ] ; then
102 echo "Error: You must run this script as root."
106 # Old versions of curl don't understand file:// URLs
110 if curl --fail --silent --max-time 60 $url ; then
113 if [ -f ${url#file://} ] ; then
121 for mirror in "${mirrors[@]}" ; do
122 baseurl=$mirror/linux/core/$releasever/$basearch/os
123 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
129 if [ -z "$baseurl" ] ; then
130 echo "Error: linux/core/$releasever/$basearch/os/repodata/repomd.xml"
131 echo " could not be found in any of the following locations:"
133 for mirror in ${mirrors[@]} ; do
142 if [ $verbose -eq 0 ] ; then
148 tmp=$(mktemp -d /tmp/mkfedora.XXXXXX)
150 # Minimally initialize /dev in reference image. If installed, the dev
151 # or udev RPMs will fill in the rest.
153 mknod -m 666 $vroot/dev/null c 1 3
154 mknod -m 666 $vroot/dev/zero c 1 5
155 mknod -m 666 $vroot/dev/full c 1 7
156 mknod -m 644 $vroot/dev/random c 1 8
157 mknod -m 644 $vroot/dev/urandom c 1 9
158 mknod -m 666 $vroot/dev/tty c 5 0
159 mknod -m 666 $vroot/dev/ptmx c 5 2
160 # For bash command substitution
161 ln -nsf ../proc/self/fd $vroot/dev/fd
162 # For df and linuxconf
163 touch $vroot/dev/hdv1
165 # Mount /dev/pts in reference image
166 mkdir -p $vroot/dev/pts
167 mount -t devpts none $vroot/dev/pts
169 # Mount /dev/shm in reference image
170 mkdir -p $vroot/dev/shm
171 mount -t tmpfs none $vroot/dev/shm
173 # Mount /proc in reference image
175 mount -t proc none $vroot/proc
180 umount $vroot/dev/shm
181 umount $vroot/dev/pts
185 # Clean up before exiting if anything goes wrong
186 trap "cleanup; exit 1" ERR
188 # Create a dummy /etc/fstab in reference image
190 cat >$vroot/etc/fstab <<EOF
191 # This fake fstab exists only to please df and linuxconf.
192 /dev/hdv1 / ext2 defaults 1 1
194 cp $vroot/etc/fstab $vroot/etc/mtab
196 # Prevent all locales from being installed in reference image
197 mkdir -p $vroot/etc/rpm
198 cat >$vroot/etc/rpm/macros <<EOF
199 %_install_langs en_US:en
201 %__file_context_path /dev/null
204 # Necessary for some scripts
205 mkdir -p $vroot/etc/sysconfig
206 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
208 # Trick rpm and yum, who read the real root /etc/rpm/macros file
209 # rather than the one installed in the reference image, despite what
210 # you might expect the --root and --installroot options to mean. Both
211 # programs always read $HOME/.rpmmacros.
212 export HOME=$vroot/tmp
214 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
216 # Initialize RPM database in reference image
217 mkdir -p $vroot/var/lib/rpm
218 rpm --root $vroot --initdb
219 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
221 # Initialize yum in reference image
222 mkdir -p $vroot/var/cache/yum $vroot/var/log
223 cat >$vroot/etc/yum.conf <<EOF
225 cachedir=/var/cache/yum
227 logfile=/var/log/yum.log
229 distroverpkg=redhat-release
235 # Prevent yum-2.4 from loading additional repository definitions
236 # (e.g., from /etc/yum.repos.d/)
240 name=Fedora Core $releasever - $basearch - base
244 for optional in core/updates extras ; do
245 if fetch $mirror/linux/$optional/$releasever/$basearch/repodata/repomd.xml ; then
246 cat >>$vroot/etc/yum.conf <<EOF
248 [$(basename $optional)]
249 name=Fedora Core $releasever - $basearch - $(basename $optional)
250 baseurl=$mirror/linux/$optional/$releasever/$basearch/
255 # If we are being built as part of an automated RPM build, solve the
256 # bootstrap problem by including any just built packages in the yum
257 # configuration. This cooperates with the PlanetLab build system.
258 if [ -n "$RPM_BUILD_DIR" ] ; then
259 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
261 if [ -x /usr/bin/yum-arch ] ; then
262 yum-arch $RPM_RPMS_DIR
265 if [ -x /usr/bin/createrepo ] ; then
266 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
267 groupfile="-g yumgroups.xml"
269 createrepo $groupfile $RPM_RPMS_DIR
271 # If run under sudo, allow user to delete the headers/ and
272 # repodata/ directories.
273 if [ -n "$SUDO_USER" ] ; then
274 chown -R $SUDO_USER $RPM_RPMS_DIR
276 cat >>$vroot/etc/yum.conf <<EOF
279 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
280 baseurl=file://$RPM_RPMS_DIR/
284 # glibc must be specified explicitly for the correct arch to be chosen.
285 echo "* Installing glibc" >&3
286 yum -c $vroot/etc/yum.conf --installroot=$vroot -y install glibc
289 if [ ${#groups[*]} -gt 0 ] ; then
290 echo "* Installing optional groups" >&3
291 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
292 groupinstall "${groups[@]}"
295 if [ ${#packages[*]} -gt 0 ] ; then
296 echo "* Installing optional packages" >&3
297 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
298 install "${packages[@]}"
301 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
302 # not currently mounted as devfs. If it thinks it is, it will refuse
303 # to install the package. On a modern system running udev that mounts
304 # /dev as tmpfs, this check fails. Since we are installing into a
305 # chroot, whether /dev is mounted on the host system or not doesn't
306 # matter. If dev was explicitly mentioned in the packages list, force
308 if [ "$releasever" = "2" ] ; then
309 for package in "${packages[@]}" ; do
310 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
311 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
318 echo "* Cleaning up" >&3
319 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
323 rm -f $vroot/var/lib/rpm/__db*
325 # Disable all services in reference image
326 chroot $vroot /bin/sh -c "/sbin/chkconfig --list | awk '{ print \$1 }' | xargs -i /sbin/chkconfig {} off"