2010-07-09 05:22:37 +02:00
|
|
|
|
2010-07-10 22:43:22 +02:00
|
|
|
APPLIANCE=base
|
|
|
|
HOSTNAME=$(APPLIANCE)
|
2010-07-09 05:22:37 +02:00
|
|
|
RAW_IMAGE=$(HOSTNAME).img
|
|
|
|
QCOW_IMAGE=$(HOSTNAME).qcow
|
|
|
|
VMDK_IMAGE=$(HOSTNAME).vmdk
|
2010-11-05 04:17:00 +01:00
|
|
|
KERNEL_CONFIG = kernel.config
|
2010-07-09 05:22:37 +02:00
|
|
|
VIRTIO=NO
|
|
|
|
TIMEZONE=UTC
|
|
|
|
DISK_SIZE=6.0G
|
|
|
|
SWAP_SIZE=30
|
|
|
|
CHROOT=chroot
|
|
|
|
ARCH=amd64
|
|
|
|
MAKEOPTS=-j4
|
|
|
|
PRUNE_CRITICAL=NO
|
2010-09-18 08:43:14 +02:00
|
|
|
HEADLESS=NO
|
|
|
|
ACCEPT_KEYWORDS="amd64"
|
2010-07-09 05:22:37 +02:00
|
|
|
|
|
|
|
INSTALL=install
|
|
|
|
M4=m4
|
|
|
|
M4_DEFS=-D HOSTNAME=$(HOSTNAME)
|
|
|
|
M4C=$(M4) $(M4_DEFS)
|
2010-10-03 17:29:27 +02:00
|
|
|
NBD_DEV=/dev/nbd0
|
2010-11-05 04:10:54 +01:00
|
|
|
PKGDIR =
|
2010-07-09 05:22:37 +02:00
|
|
|
USEPKG=--usepkg --binpkg-respect-use=y
|
2010-11-05 04:10:54 +01:00
|
|
|
RSYNC_MIRROR = rsync://mirrors.rit.edu/gentoo/
|
2010-07-09 05:22:37 +02:00
|
|
|
KERNEL=gentoo-sources
|
2010-07-10 22:43:22 +02:00
|
|
|
PACKAGE_FILES=$(APPLIANCE)/package.*
|
|
|
|
WORLD=$(APPLIANCE)/world
|
|
|
|
CRITICAL=$(APPLIANCE)/critical
|
2010-07-09 05:22:37 +02:00
|
|
|
|
2010-10-06 13:37:32 +02:00
|
|
|
include $(APPLIANCE)/Makefile.inc
|
2010-07-09 05:22:37 +02:00
|
|
|
|
|
|
|
all: image
|
|
|
|
|
|
|
|
$(RAW_IMAGE):
|
|
|
|
qemu-img create -f raw $(RAW_IMAGE) $(DISK_SIZE)
|
|
|
|
|
2010-11-05 04:10:54 +01:00
|
|
|
partitions: $(RAW_IMAGE)
|
|
|
|
parted -s $(RAW_IMAGE) mklabel msdos
|
2010-11-05 13:59:18 +01:00
|
|
|
parted -s $(RAW_IMAGE) mkpart primary ext2 0 $(DISK_SIZE)
|
2010-11-05 04:10:54 +01:00
|
|
|
parted -s $(RAW_IMAGE) set 1 boot on
|
2010-07-10 20:04:04 +02:00
|
|
|
|
2010-10-03 17:29:27 +02:00
|
|
|
qemu-nbd -c $(NBD_DEV) $(RAW_IMAGE)
|
2010-07-10 20:04:04 +02:00
|
|
|
sleep 3
|
2010-11-05 13:59:18 +01:00
|
|
|
mkfs.ext2 -O sparse_super -L "$(APPLIANCE)" $(NBD_DEV)p1
|
2010-07-09 05:22:37 +02:00
|
|
|
touch partitions
|
|
|
|
|
2010-07-10 20:04:04 +02:00
|
|
|
mounts: $(CHROOT) stage3
|
|
|
|
if [ ! -e mounts ] ; then \
|
2010-07-10 02:22:55 +02:00
|
|
|
mount -t proc none $(CHROOT)/proc; \
|
|
|
|
mount -o bind /dev $(CHROOT)/dev; \
|
|
|
|
mount -o bind /var/tmp $(CHROOT)/var/tmp; \
|
2010-07-10 20:04:04 +02:00
|
|
|
fi
|
|
|
|
touch mounts
|
|
|
|
|
|
|
|
portage: stage3
|
2010-11-05 04:10:54 +01:00
|
|
|
rsync -L $(RSYNC_MIRROR)/snapshots/portage-latest.tar.bz2 portage-latest.tar.bz2
|
2010-11-05 06:53:07 +01:00
|
|
|
tar xjf portage-latest.tar.bz2 -C $(CHROOT)/usr
|
2010-11-05 04:10:54 +01:00
|
|
|
if [ -n "$(PKGDIR)" ]; then \
|
|
|
|
mkdir -p $(CHROOT)/usr/portage/packages; \
|
|
|
|
mount -o bind "$(PKGDIR)" $(CHROOT)/usr/portage/packages; \
|
2010-07-10 02:22:55 +02:00
|
|
|
fi
|
2010-07-10 20:04:04 +02:00
|
|
|
touch portage
|
|
|
|
|
|
|
|
preproot: stage3 mounts portage
|
|
|
|
cp -L /etc/resolv.conf $(CHROOT)/etc/
|
|
|
|
touch preproot
|
|
|
|
|
2010-11-06 09:41:15 +01:00
|
|
|
stage3:
|
|
|
|
mkdir -p $(CHROOT)
|
2010-11-06 23:46:07 +01:00
|
|
|
rsync $(RSYNC_MIRROR)/releases/`echo $(ARCH)|sed 's/i.86/x86/'`/autobuilds/latest-stage3.txt .
|
|
|
|
rsync $(RSYNC_MIRROR)/releases/`echo $(ARCH)|sed 's/i.86/x86/'`/autobuilds/`tail -n 1 latest-stage3.txt` stage3-$(ARCH)-latest.tar.bz2
|
2010-11-05 15:52:04 +01:00
|
|
|
tar xjpf stage3-$(ARCH)-latest.tar.bz2 -C $(CHROOT)
|
2010-07-10 20:04:04 +02:00
|
|
|
touch stage3
|
|
|
|
|
2010-11-05 06:53:07 +01:00
|
|
|
compile_options: portage make.conf locale.gen $(PACKAGE_FILES)
|
2010-07-10 20:04:04 +02:00
|
|
|
cp make.conf $(CHROOT)/etc/make.conf
|
2010-09-18 08:43:14 +02:00
|
|
|
echo ACCEPT_KEYWORDS=$(ACCEPT_KEYWORDS) >> $(CHROOT)/etc/make.conf
|
2010-07-10 20:04:04 +02:00
|
|
|
cp locale.gen $(CHROOT)/etc/locale.gen
|
|
|
|
chroot $(CHROOT) locale-gen
|
|
|
|
mkdir -p $(CHROOT)/etc/portage
|
2010-07-10 22:43:22 +02:00
|
|
|
for f in $(PACKAGE_FILES) ; do \
|
|
|
|
cp $$f $(CHROOT)/etc/portage/ ; \
|
|
|
|
done
|
2010-07-10 20:04:04 +02:00
|
|
|
touch compile_options
|
|
|
|
|
|
|
|
base_system: mounts compile_options
|
|
|
|
touch base_system
|
2010-07-09 05:22:37 +02:00
|
|
|
|
2010-11-05 04:17:00 +01:00
|
|
|
$(CHROOT)/boot/vmlinuz: base_system $(KERNEL_CONFIG)
|
2010-09-07 13:42:18 +02:00
|
|
|
chroot $(CHROOT) cp /usr/share/zoneinfo/$(TIMEZONE) /etc/localtime
|
2010-11-05 06:53:07 +01:00
|
|
|
chroot $(CHROOT) emerge -n $(USEPKG) sys-kernel/$(KERNEL)
|
2010-11-05 04:17:00 +01:00
|
|
|
cp $(KERNEL_CONFIG) $(CHROOT)/usr/src/linux/.config
|
2010-07-09 05:22:37 +02:00
|
|
|
chroot $(CHROOT) gcc-config 1
|
2010-07-10 20:04:04 +02:00
|
|
|
chroot $(CHROOT) make $(MAKEOPTS) -C /usr/src/linux oldconfig
|
|
|
|
chroot $(CHROOT) make $(MAKEOPTS) -C /usr/src/linux
|
|
|
|
chroot $(CHROOT) make $(MAKEOPTS) -C /usr/src/linux modules_install
|
|
|
|
chroot $(CHROOT) make $(MAKEOPTS) -C /usr/src/linux install
|
2010-07-09 05:22:37 +02:00
|
|
|
cd $(CHROOT)/boot ; \
|
|
|
|
k=`/bin/ls -1 --sort=time vmlinuz-*|head -n 1` ; \
|
|
|
|
ln -nsf $$k vmlinuz
|
|
|
|
|
2010-07-10 20:04:04 +02:00
|
|
|
sysconfig: preproot fstab
|
2010-07-09 05:22:37 +02:00
|
|
|
cp fstab $(CHROOT)/etc/fstab
|
|
|
|
if [ "$(VIRTIO)" == "YES" ] ; then \
|
|
|
|
sed -i 's/sda/vda/' $(CHROOT)/etc/fstab; \
|
|
|
|
fi
|
|
|
|
dd if=/dev/zero of=$(CHROOT)/.swap bs=1M count=$(SWAP_SIZE)
|
|
|
|
/sbin/mkswap $(CHROOT)/.swap
|
|
|
|
echo HOSTNAME=$(HOSTNAME) > $(CHROOT)/etc/conf.d/hostname
|
|
|
|
sed -i 's/^#TIMEZONE=.*/TIMEZONE="$(TIMEZONE)"/' $(CHROOT)/etc/conf.d/clock
|
2010-07-11 01:32:08 +02:00
|
|
|
sed -i 's/^#s0:/s0:/' $(CHROOT)/etc/inittab
|
2010-09-18 08:43:14 +02:00
|
|
|
if [ "$(HEADLESS)" == "YES" ] ; then \
|
|
|
|
sed -i 's/^\(c[0-9]:\)/#\1/' $(CHROOT)/etc/inittab ; \
|
|
|
|
fi
|
2010-07-09 05:22:37 +02:00
|
|
|
echo 'config_eth0=( "dhcp" )' > $(CHROOT)/etc/conf.d/net
|
|
|
|
chroot $(CHROOT) rc-update add net.eth0 default
|
2010-09-18 08:43:14 +02:00
|
|
|
chroot $(CHROOT) rc-update del consolefont boot
|
2010-07-09 05:22:37 +02:00
|
|
|
touch sysconfig
|
|
|
|
|
2010-07-10 20:04:04 +02:00
|
|
|
systools: sysconfig compile_options
|
|
|
|
chroot $(CHROOT) emerge -n $(USEPKG) app-admin/syslog-ng
|
2010-07-09 05:22:37 +02:00
|
|
|
chroot $(CHROOT) rc-update add syslog-ng default
|
2010-08-01 02:16:35 +02:00
|
|
|
chroot $(CHROOT) emerge -n $(USEPKG) sys-power/acpid
|
|
|
|
chroot $(CHROOT) rc-update add acpid default
|
2010-07-10 20:04:04 +02:00
|
|
|
chroot $(CHROOT) emerge -n $(USEPKG) net-misc/dhcpcd
|
2010-07-09 05:22:37 +02:00
|
|
|
touch systools
|
2010-07-10 20:04:04 +02:00
|
|
|
|
2010-09-18 08:43:14 +02:00
|
|
|
grub: systools grub.conf $(CHROOT)/boot/vmlinuz
|
2010-07-09 05:22:37 +02:00
|
|
|
chroot $(CHROOT) emerge -nN $(USEPKG) sys-boot/grub
|
2010-07-10 20:04:04 +02:00
|
|
|
cp grub.conf $(CHROOT)/boot/grub/grub.conf
|
2010-07-09 05:22:37 +02:00
|
|
|
if [ "$(VIRTIO)" == "YES" ] ; then \
|
|
|
|
sed -i 's/sda/vda/' $(CHROOT)/boot/grub/grub.conf ; \
|
|
|
|
fi
|
2010-09-18 08:43:14 +02:00
|
|
|
if [ "$(HEADLESS)" == "YES" ] ; then \
|
|
|
|
sed -i -f grub-headless.sed $(CHROOT)/boot/grub/grub.conf ; \
|
|
|
|
fi
|
2010-07-09 05:22:37 +02:00
|
|
|
touch grub
|
|
|
|
|
2010-10-06 13:37:32 +02:00
|
|
|
software: systools issue etc-update.conf $(CRITICAL) $(WORLD)
|
|
|
|
$(preinstall)
|
2010-07-10 22:03:39 +02:00
|
|
|
cp etc-update.conf $(CHROOT)/etc/
|
2010-11-06 22:49:19 +01:00
|
|
|
|
|
|
|
# some packages, like, tar need xz-utils to unpack, but it not part of
|
|
|
|
# the stage3 so may not be installed yet
|
|
|
|
chroot $(CHROOT) emerge -1n $(USEPKG) app-arch/xz-utils
|
|
|
|
|
|
|
|
chroot $(CHROOT) emerge $(USEPKG) --update --newuse --deep `cat $(WORLD)`
|
|
|
|
|
|
|
|
# Need gentoolkit to run revdep-rebuild
|
|
|
|
chroot $(CHROOT) emerge -1n $(USEPKG) app-portage/gentoolkit
|
2010-07-10 20:04:04 +02:00
|
|
|
chroot $(CHROOT) revdep-rebuild -i
|
2010-11-06 22:49:19 +01:00
|
|
|
|
2010-07-09 05:22:37 +02:00
|
|
|
cp issue $(CHROOT)/etc/issue
|
|
|
|
chroot $(CHROOT) emerge --depclean --with-bdeps=n
|
2010-11-05 04:17:00 +01:00
|
|
|
chroot $(CHROOT) etc-update
|
2010-07-09 05:22:37 +02:00
|
|
|
chroot $(CHROOT) gcc-config 1
|
2010-10-06 13:37:32 +02:00
|
|
|
$(postinstall)
|
2010-07-10 22:03:39 +02:00
|
|
|
chroot $(CHROOT) passwd -d root
|
|
|
|
chroot $(CHROOT) passwd -e root
|
2010-07-09 05:22:37 +02:00
|
|
|
if [ "$(PRUNE_CRITICAL)" = "YES" ] ; then \
|
2010-07-10 22:43:22 +02:00
|
|
|
chroot $(CHROOT) emerge -C `cat $(CRITICAL)` ; \
|
2010-07-09 05:22:37 +02:00
|
|
|
fi
|
|
|
|
touch software
|
|
|
|
|
|
|
|
device-map: $(RAW_IMAGE)
|
|
|
|
echo '(hd0) ' $(RAW_IMAGE) > device-map
|
|
|
|
|
2010-07-10 20:04:04 +02:00
|
|
|
image: $(RAW_IMAGE) grub partitions device-map grub.shell systools software
|
2010-07-09 05:22:37 +02:00
|
|
|
mkdir -p loop
|
2010-11-05 06:53:07 +01:00
|
|
|
mount -o noatime $(NBD_DEV)p1 loop
|
2010-07-09 05:22:37 +02:00
|
|
|
mkdir -p gentoo
|
|
|
|
mount -o bind $(CHROOT) gentoo
|
|
|
|
if [ "$(PRUNE_CRITICAL)" = "YES" ] ; then \
|
2010-11-05 06:53:07 +01:00
|
|
|
rsync -ax --exclude-from=rsync-excludes --exclude-from=rsync-excludes-critical gentoo/ loop/ ; \
|
|
|
|
else \
|
|
|
|
rsync -ax --exclude-from=rsync-excludes gentoo/ loop/ ; \
|
2010-07-09 05:22:37 +02:00
|
|
|
fi
|
|
|
|
loop/sbin/grub --device-map=device-map --no-floppy --batch < grub.shell
|
|
|
|
umount gentoo
|
2010-11-05 06:53:07 +01:00
|
|
|
rmdir gentoo
|
|
|
|
umount loop
|
2010-07-09 05:22:37 +02:00
|
|
|
sleep 3
|
|
|
|
rmdir loop
|
2010-10-03 17:29:27 +02:00
|
|
|
qemu-nbd -d $(NBD_DEV)
|
2010-07-09 05:22:37 +02:00
|
|
|
touch image
|
|
|
|
|
|
|
|
$(QCOW_IMAGE): $(RAW_IMAGE) image
|
|
|
|
qemu-img convert -f raw -O qcow2 -c $(RAW_IMAGE) $(QCOW_IMAGE)
|
|
|
|
|
|
|
|
qcow: $(QCOW_IMAGE)
|
|
|
|
|
|
|
|
|
|
|
|
$(VMDK_IMAGE): $(RAW_IMAGE) image
|
|
|
|
qemu-img convert -f raw -O vmdk $(RAW_IMAGE) $(VMDK_IMAGE)
|
|
|
|
|
|
|
|
vmdk: $(VMDK_IMAGE)
|
|
|
|
|
2010-11-05 13:06:13 +01:00
|
|
|
umount:
|
|
|
|
umount -l $(CHROOT)/usr/portage/packages
|
|
|
|
umount -l $(CHROOT)/var/tmp
|
|
|
|
umount -l $(CHROOT)/dev
|
|
|
|
umount -l $(CHROOT)/proc
|
2010-07-09 05:22:37 +02:00
|
|
|
|
2010-11-06 09:41:15 +01:00
|
|
|
remove_checkpoints:
|
2010-07-10 20:04:04 +02:00
|
|
|
rm -f mounts compile_options base_system portage
|
2010-09-18 08:43:14 +02:00
|
|
|
rm -f parted grub stage3 software preproot sysconfig systools image partitions device-map
|
2010-11-06 09:41:15 +01:00
|
|
|
|
|
|
|
clean: umount remove_checkpoints
|
2010-07-09 05:22:37 +02:00
|
|
|
rm -rf loop
|
|
|
|
rm -rf gentoo
|
|
|
|
rm -rf $(CHROOT)
|
|
|
|
|
|
|
|
realclean: clean
|
|
|
|
rm -f $(RAW_IMAGE) $(QCOW_IMAGE) $(VMDK_IMAGE)
|
2010-11-05 13:06:13 +01:00
|
|
|
|
2010-11-06 23:46:07 +01:00
|
|
|
distclean:
|
2010-11-06 09:41:15 +01:00
|
|
|
rm -f *.qcow *.img *.vmdk
|
2010-11-06 23:46:07 +01:00
|
|
|
rm -f latest-stage3.txt stage3-*-latest.tar.bz2
|
2010-11-06 09:41:15 +01:00
|
|
|
rm -f portage-latest.tar.bz2
|
2010-11-06 23:46:07 +01:00
|
|
|
|
|
|
|
.PHONY: qcow vmdk clean umount realclean distclean remove_checkpoints
|