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
|
|
|
|
VIRTIO=NO
|
|
|
|
TIMEZONE=UTC
|
|
|
|
DISK_SIZE=6.0G
|
|
|
|
SWAP_SIZE=30
|
|
|
|
CHROOT=chroot
|
|
|
|
ARCH=amd64
|
|
|
|
MAKEOPTS=-j4
|
|
|
|
PRUNE_CRITICAL=NO
|
|
|
|
|
|
|
|
INSTALL=install
|
|
|
|
M4=m4
|
|
|
|
M4_DEFS=-D HOSTNAME=$(HOSTNAME)
|
|
|
|
M4C=$(M4) $(M4_DEFS)
|
|
|
|
USEPKG=--usepkg --binpkg-respect-use=y
|
|
|
|
PARTED=/usr/sbin/parted
|
|
|
|
PORTAGE=/portage
|
|
|
|
DISTFILES=/var/portage/distfiles
|
2010-07-10 20:04:04 +02:00
|
|
|
STAGE3=ftp://ftp.osuosl.org/pub/gentoo/releases/$(ARCH)/autobuilds/current-stage3/stage3-$(ARCH)-*.tar.bz2
|
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
|
|
|
|
PREINSTALL=$(APPLIANCE)/preinstall
|
|
|
|
POSTINSTALL=$(APPLIANCE)/postinstall
|
2010-07-09 05:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
all: image
|
|
|
|
|
|
|
|
$(RAW_IMAGE):
|
|
|
|
qemu-img create -f raw $(RAW_IMAGE) $(DISK_SIZE)
|
|
|
|
|
|
|
|
partitions: parted $(RAW_IMAGE)
|
|
|
|
$(PARTED) -s -a optimal $(RAW_IMAGE) mklabel msdos
|
|
|
|
$(PARTED) -s -a optimal $(RAW_IMAGE) mkpart primary ext4 0 $(DISK_SIZE)
|
|
|
|
$(PARTED) -s -a optimal $(RAW_IMAGE) set 1 boot on
|
2010-07-10 20:04:04 +02:00
|
|
|
|
2010-07-22 05:08:35 +02:00
|
|
|
qemu-nbd -c /dev/nbd0 $(RAW_IMAGE)
|
2010-07-10 20:04:04 +02:00
|
|
|
sleep 3
|
2010-07-22 05:08:35 +02:00
|
|
|
mkfs.ext4 /dev/nbd0p1
|
2010-07-09 05:22:37 +02:00
|
|
|
touch partitions
|
|
|
|
|
|
|
|
parted:
|
|
|
|
emerge -n1 $(USEPKG) parted
|
|
|
|
touch parted
|
|
|
|
|
2010-07-10 20:04:04 +02:00
|
|
|
$(CHROOT):
|
|
|
|
mkdir -p $(CHROOT)
|
|
|
|
|
|
|
|
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
|
|
|
|
if [ ! -e portage ] ; then \
|
|
|
|
mkdir -p $(CHROOT)/usr/portage; \
|
2010-07-10 02:22:55 +02:00
|
|
|
mount -o bind $(PORTAGE) $(CHROOT)/usr/portage; \
|
|
|
|
mkdir -p $(CHROOT)/usr/portage/distfiles; \
|
2010-07-10 20:04:04 +02:00
|
|
|
mount -o bind $(DISTFILES) $(CHROOT)/usr/portage/distfiles ; \
|
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
|
|
|
|
|
|
|
|
stage3: chroot
|
2010-07-10 02:49:58 +02:00
|
|
|
if [ ! -e stage3 ] ; then \
|
|
|
|
wget -c -q -nc $(STAGE3); \
|
2010-07-10 20:04:04 +02:00
|
|
|
tar xjpf stage3-*.tar.bz2 -C $(CHROOT); \
|
2010-07-10 02:49:58 +02:00
|
|
|
fi
|
2010-07-10 20:04:04 +02:00
|
|
|
touch stage3
|
|
|
|
|
2010-07-10 22:43:22 +02:00
|
|
|
compile_options: make.conf locale.gen $(PACKAGE_FILES)
|
2010-07-10 20:04:04 +02:00
|
|
|
cp make.conf $(CHROOT)/etc/make.conf
|
|
|
|
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-07-10 20:04:04 +02:00
|
|
|
kernel: base_system kernel.config
|
|
|
|
chroot $(CHROOT) cp /usr/share/zoneinfo/GMT /etc/localtime
|
2010-07-09 05:22:37 +02:00
|
|
|
chroot $(CHROOT) emerge -N sys-kernel/$(KERNEL)
|
2010-07-10 20:04:04 +02: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
|
|
|
touch kernel
|
2010-07-09 05:22:37 +02:00
|
|
|
|
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-07-09 05:22:37 +02:00
|
|
|
echo 'config_eth0=( "dhcp" )' > $(CHROOT)/etc/conf.d/net
|
|
|
|
chroot $(CHROOT) rc-update add net.eth0 default
|
|
|
|
echo "127.0.0.1 $(HOSTNAME) localhost" > $(CHROOT)/etc/hosts
|
|
|
|
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-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
|
|
|
|
|
|
|
grub: systools grub.conf kernel
|
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
|
|
|
|
touch grub
|
|
|
|
|
2010-07-10 22:43:22 +02:00
|
|
|
software: systools issue etc-update.conf $(CRITICAL) $(WORLD) $(PREINSTALL) $(POSTINSTALL)
|
2010-07-22 05:08:35 +02:00
|
|
|
./$(PREINSTALL) "$(CHROOT)" $(HOSTNAME)
|
2010-07-10 20:04:04 +02:00
|
|
|
chroot $(CHROOT) emerge -DN $(USEPKG) system
|
2010-07-10 22:03:39 +02:00
|
|
|
cp etc-update.conf $(CHROOT)/etc/
|
|
|
|
chroot $(CHROOT) etc-update
|
2010-07-10 22:43:22 +02:00
|
|
|
chroot $(CHROOT) emerge -DNn $(USEPKG) `cat $(WORLD)`
|
2010-07-10 20:04:04 +02:00
|
|
|
chroot $(CHROOT) emerge -1n app-portage/gentoolkit
|
|
|
|
chroot $(CHROOT) revdep-rebuild -i
|
2010-07-09 05:22:37 +02:00
|
|
|
cp issue $(CHROOT)/etc/issue
|
|
|
|
chroot $(CHROOT) emerge --depclean --with-bdeps=n
|
|
|
|
chroot $(CHROOT) gcc-config 1
|
2010-07-22 05:08:35 +02:00
|
|
|
./$(POSTINSTALL) "$(CHROOT)" $(HOSTNAME)
|
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-07-22 05:08:35 +02:00
|
|
|
mount /dev/nbd0p1 loop/
|
2010-07-09 05:22:37 +02:00
|
|
|
mkdir -p gentoo
|
|
|
|
mount -o bind $(CHROOT) gentoo
|
|
|
|
rm -rf gentoo/usr/src/linux-*
|
|
|
|
rm -rf gentoo/tmp/*
|
|
|
|
rm -rf gentoo/var/tmp/*
|
|
|
|
if [ "$(PRUNE_CRITICAL)" = "YES" ] ; then \
|
|
|
|
rm -rf gentoo/usr/lib/python*/test ; \
|
|
|
|
rm -rf gentoo/usr/share/gtk-doc ; \
|
|
|
|
rm -rf gentoo/var/db/pkg ; \
|
|
|
|
rm -rf gentoo/usr/lib/perl* ; \
|
|
|
|
fi
|
|
|
|
rsync -ax gentoo/ loop/
|
|
|
|
loop/sbin/grub --device-map=device-map --no-floppy --batch < grub.shell
|
|
|
|
umount loop
|
|
|
|
umount gentoo
|
|
|
|
sleep 3
|
|
|
|
rmdir loop
|
|
|
|
rm -rf gentoo
|
2010-07-22 05:08:35 +02:00
|
|
|
qemu-nbd -d /dev/nbd0
|
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)
|
|
|
|
|
|
|
|
.PHONY: qcow vmdk clean
|
|
|
|
|
|
|
|
clean:
|
|
|
|
umount $(CHROOT)/usr/portage/distfiles $(CHROOT)/usr/portage $(CHROOT)/var/tmp $(CHROOT)/dev $(CHROOT)/proc || true
|
2010-07-10 20:04:04 +02:00
|
|
|
rm -f mounts compile_options base_system portage
|
2010-07-09 05:22:37 +02:00
|
|
|
rm -f parted grub stage3 software preproot sysconfig systools image kernel partitions device-map
|
|
|
|
rm -rf loop
|
|
|
|
rm -rf gentoo
|
|
|
|
rm -rf $(CHROOT)
|
|
|
|
|
|
|
|
realclean: clean
|
|
|
|
rm -f $(RAW_IMAGE) $(QCOW_IMAGE) $(VMDK_IMAGE)
|