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.9 2006/04/05 21:32:15 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."
108 curl --fail --silent --max-time 60 "$1"
111 for mirror in "${mirrors[@]}" ; do
112 baseurl=$mirror/linux/core/$releasever/$basearch/os
113 if fetch $baseurl/repodata/repomd.xml >/dev/null ; then
119 if [ -z "$baseurl" ] ; then
120 echo "Error: linux/core/$releasever/$basearch/os/repodata/repomd.xml"
121 echo " could not be found in any of the following locations:"
123 for mirror in ${mirrors[@]} ; do
132 if [ $verbose -eq 0 ] ; then
137 # Minimally initialize /dev in reference image. If installed, the dev
138 # or udev RPMs will fill in the rest.
140 mknod -m 666 $vroot/dev/null c 1 3
141 mknod -m 666 $vroot/dev/zero c 1 5
142 mknod -m 666 $vroot/dev/full c 1 7
143 mknod -m 644 $vroot/dev/random c 1 8
144 mknod -m 644 $vroot/dev/urandom c 1 9
145 mknod -m 666 $vroot/dev/tty c 5 0
146 mknod -m 666 $vroot/dev/ptmx c 5 2
147 # For bash command substitution
148 ln -nsf ../proc/self/fd $vroot/dev/fd
149 # For df and linuxconf
150 touch $vroot/dev/hdv1
151 # For mkinitrd (in case a kernel is being installed)
152 for i in $(seq 0 7) ; do
153 mknod -m 640 $vroot/dev/loop$i b 7 $i
156 # Do not tolerate errors
159 # Mount /dev/pts in reference image
160 mkdir -p $vroot/dev/pts
161 mount -t devpts none $vroot/dev/pts
163 # Mount /dev/shm in reference image
164 mkdir -p $vroot/dev/shm
165 mount -t tmpfs none $vroot/dev/shm
167 # Mount /proc in reference image
169 mount -t proc none $vroot/proc
174 umount $vroot/dev/shm
175 umount $vroot/dev/pts
178 # Clean up before exiting if anything goes wrong
181 # Create a dummy /etc/fstab in reference image
183 cat >$vroot/etc/fstab <<EOF
184 # This fake fstab exists only to please df and linuxconf.
185 /dev/hdv1 / ext2 defaults 1 1
187 cp $vroot/etc/fstab $vroot/etc/mtab
189 # Prevent all locales from being installed in reference image
190 mkdir -p $vroot/etc/rpm
191 cat >$vroot/etc/rpm/macros <<EOF
192 %_install_langs en_US:en
194 %__file_context_path /dev/null
197 # Necessary for some scripts
198 mkdir -p $vroot/etc/sysconfig
199 echo "NETWORKING=yes" > $vroot/etc/sysconfig/network
201 # Trick rpm and yum, who read the real root /etc/rpm/macros file
202 # rather than the one installed in the reference image, despite what
203 # you might expect the --root and --installroot options to mean. Both
204 # programs always read $HOME/.rpmmacros.
205 export HOME=$vroot/tmp
207 cp $vroot/etc/rpm/macros $vroot/tmp/.rpmmacros
209 # Initialize RPM database in reference image
210 mkdir -p $vroot/var/lib/rpm
211 rpm --root $vroot --initdb
212 rpm --root $vroot --import $baseurl/RPM-GPG-KEY-fedora
214 # Initialize yum in reference image
215 mkdir -p $vroot/var/cache/yum $vroot/var/log
216 cat >$vroot/etc/yum.conf <<EOF
218 cachedir=/var/cache/yum
220 logfile=/var/log/yum.log
222 distroverpkg=redhat-release
228 # Prevent yum-2.4 from loading additional repository definitions
229 # (e.g., from /etc/yum.repos.d/)
233 name=Fedora Core $releasever - $basearch - base
237 for optional in core/updates extras ; do
238 if fetch $mirror/linux/$optional/$releasever/$basearch/repodata/repomd.xml ; then
239 cat >>$vroot/etc/yum.conf <<EOF
241 [$(basename $optional)]
242 name=Fedora Core $releasever - $basearch - $(basename $optional)
243 baseurl=$mirror/linux/$optional/$releasever/$basearch/
248 # If we are being built as part of an automated RPM build, solve the
249 # bootstrap problem by including any just built packages in the yum
250 # configuration. This cooperates with the PlanetLab build system.
251 if [ -n "$RPM_BUILD_DIR" ] ; then
252 RPM_RPMS_DIR=$(cd $(dirname $RPM_BUILD_DIR)/RPMS && pwd -P)
254 if [ -x /usr/bin/yum-arch ] ; then
255 yum-arch $RPM_RPMS_DIR
258 if [ -x /usr/bin/createrepo ] ; then
259 if [ -f $RPM_RPMS_DIR/yumgroups.xml ] ; then
260 groupfile="-g yumgroups.xml"
262 createrepo $groupfile $RPM_RPMS_DIR
264 # If run under sudo, allow user to delete the headers/ and
265 # repodata/ directories.
266 if [ -n "$SUDO_USER" ] ; then
267 chown -R $SUDO_USER $RPM_RPMS_DIR
269 cat >>$vroot/etc/yum.conf <<EOF
272 name=Bootstrap - $basearch - $RPM_RPMS_DIR/
273 baseurl=file://$RPM_RPMS_DIR/
277 # glibc must be specified explicitly for the correct arch to be
278 # chosen. coreutils are basically mandatory for any useful
280 echo "* Installing glibc and coreutils" >&3
281 yum -c $vroot/etc/yum.conf --installroot=$vroot -y install glibc coreutils
284 if [ ${#groups[*]} -gt 0 ] ; then
285 echo "* Installing optional groups" >&3
286 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
287 groupinstall "${groups[@]}"
290 if [ ${#packages[*]} -gt 0 ] ; then
291 echo "* Installing optional packages" >&3
292 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
293 install "${packages[@]}"
296 # FC2 dev %preinstall checks /proc/mounts to make sure that /dev is
297 # not currently mounted as devfs. If it thinks it is, it will refuse
298 # to install the package. On a modern system running udev that mounts
299 # /dev as tmpfs, this check fails. Since we are installing into a
300 # chroot, whether /dev is mounted on the host system or not doesn't
301 # matter. If dev was explicitly mentioned in the packages list, force
303 if [ "$releasever" = "2" ] ; then
304 for package in "${packages[@]}" ; do
305 if [ "$package" = "dev" ] && ! rpm --root $vroot -q dev >/dev/null 2>&1 ; then
306 rpm --root $vroot -Uvh --noscripts $baseurl/Fedora/RPMS/dev-3.3.13-1.i386.rpm
313 echo "* Cleaning up" >&3
314 yum -c $vroot/etc/yum.conf --installroot=$vroot -y \
318 rm -f $vroot/var/lib/rpm/__db*
320 # Set time zone to UTC
321 if [ -f $vroot/usr/share/zoneinfo/UTC -a -f $vroot/etc/localtime ] ; then
322 rm -f $vroot/etc/localtime
323 ln -s /usr/share/zoneinfo/UTC $vroot/etc/localtime