#!/bin/bash # The currect work dir contains a dir named ./chroot (which can be # a symlink to a partition as in my case) and is where we are going # to build the system. # # ./embedded_packages contains packages built using: # emerge -B # # The packages are then placed inside /usr/portage/packages/ # I moved them to a dir named embedded_packages in the current # work dir for easy access and so they dont get mixed with the host's # packages. # Next we untar the packages into the chroot. # - baselayout is the standard gentoo baselayout with all the bells # and whisltes. # # - tinylogin gives us a getty and some other usefull stuff such as # passwd and su. We will symlink the names of the tools later. # # - busybox gives us pretty much the rest of the necessary standard # unix tools. We will symlink the names of the tools later. # # - standard glibc. Overkill but I still havent tried with uClibc. # and rest of the stuff to comply with baselayout. # # Please note that the bare minimum is extracted from all the following # packages apart from glibc and baselayout. In these two cases everything is # dumped into the chroot without looking any further. # # Note regarding devfsd: The system works without devfsd but since it didnt # fill much space I thought of including it. # # Note regarding bash: we have busybox, but many baselayout rc scripts require # bash and since I didnt want to touch baselayout I was forced to include # bash. # # Note regarding e2fsprogs: baselayout uses fsck and also fsck.ext3 in my case # since I use ext3. So I only extract these from the package. # # Note regarding net-tools and coreutils: baselayout uses hostname and install # so I only extract these files from these packages. # # gawk and grep are also used by baselayout so they are included although in # the case of gawk the bare minimum is extracted. # Here is a brief list of the packages you need to create using emerge -B # baselayout, tinylogin, busybox, glibc, grep, devfsd, bash, gawk, # e2fsprogs, net-tootls and coreutils. # # Remember once you create these move them to ./embedded_packages (or change # the path below). tar xjpf ./embedded_packages/baselayout-* -C ./chroot/ tar xjpf ./embedded_packages/tinylogin-* -C ./chroot/ tar xjpf ./embedded_packages/busybox-* -C ./chroot/ tar xjpf ./embedded_packages/glibc-* -C ./chroot/ tar xjpf ./embedded_packages/grep-* -C ./chroot/ tar xjpf ./embedded_packages/devfsd-* -C ./chroot/ tar xjpf ./embedded_packages/bash-* -C ./chroot/ ./bin/bash ln -s /bin/bash ./chroot/bin/sh tar xvjpf ./embedded_packages/gawk-* -C ./chroot/ \ ./lib/rcscripts/* ./usr/bin/awk ./usr/bin/gawk \ ./usr/share/awk/* ./usr/lib/awk/* ./bin/gawk ./bin/gawk-* ./bin/awk \ tar xjpvf ./embedded_packages/e2fsprogs-* -C ./chroot/ \ ./lib/libuuid.so.1 ./lib/libblkid.so.1.0 ./lib/libblkid.so.1 \ ./lib/libuuid.so.1.2 ./sbin/fsck ./sbin/fsck.ext3 ./sbin/e2fsck \ ./lib/libext2fs.so.2 ./lib/libext2fs.so.2.4 ./lib/libcom_err.so* tar xvjpf ./embedded_packages/net-tools-* -C ./chroot/ \ ./bin/hostname tar xvjpf ./embedded_packages/coreutils-* -C ./chroot/ \ ./bin/install # I dont know where to get /dev so I just copy it from my host system. If you # know a better way let me know. I could use a stage file, but I preferred # this method since while building the embedded system it is more plausible # the user has a /dev than a stage file at hand. cp -a /dev ./chroot/ # Now the symlinks for tinylogin and busybox # # NOTE: If you see any errors while linking dont worry and ignore them. ln -s /bin/busybox ./chroot/bin/basename ln -s /bin/busybox ./chroot/bin/cat ln -s /bin/busybox ./chroot/bin/chgrp ln -s /bin/busybox ./chroot/bin/chmod ln -s /bin/busybox ./chroot/bin/chown ln -s /bin/busybox ./chroot/bin/chroot ln -s /bin/busybox ./chroot/bin/cp ln -s /bin/busybox ./chroot/bin/cut ln -s /bin/busybox ./chroot/bin/date ln -s /bin/busybox ./chroot/bin/dd ln -s /bin/busybox ./chroot/bin/df ln -s /bin/busybox ./chroot/bin/dirname ln -s /bin/busybox ./chroot/bin/dmesg ln -s /bin/busybox ./chroot/bin/du ln -s /bin/busybox ./chroot/bin/echo ln -s /bin/busybox ./chroot/bin/env ln -s /bin/busybox ./chroot/bin/false ln -s /bin/busybox ./chroot/bin/grep ln -s /bin/busybox ./chroot/bin/gunzip ln -s /bin/busybox ./chroot/bin/gzip ln -s /bin/busybox ./chroot/bin/head ln -s /bin/busybox ./chroot/bin/kill ln -s /bin/busybox ./chroot/bin/killall ln -s /bin/busybox ./chroot/bin/ln ln -s /bin/busybox ./chroot/bin/ls ln -s /bin/busybox ./chroot/bin/lsmod ln -s /bin/busybox ./chroot/bin/mkdir ln -s /bin/busybox ./chroot/bin/mknod ln -s /bin/busybox ./chroot/bin/more ln -s /bin/busybox ./chroot/bin/mount ln -s /bin/busybox ./chroot/bin/mv ln -s /bin/busybox ./chroot/bin/pidof ln -s /bin/busybox ./chroot/bin/ping ln -s /bin/busybox ./chroot/bin/ps ln -s /bin/busybox ./chroot/bin/pwd ln -s /bin/busybox ./chroot/bin/readlink ln -s /bin/busybox ./chroot/bin/rm ln -s /bin/busybox ./chroot/bin/rmdir ln -s /bin/busybox ./chroot/bin/sed ln -s /bin/busybox ./chroot/bin/sleep ln -s /bin/busybox ./chroot/bin/sort ln -s /bin/busybox ./chroot/bin/sync ln -s /bin/busybox ./chroot/bin/tail ln -s /bin/busybox ./chroot/bin/tar ln -s /bin/busybox ./chroot/bin/test ln -s /bin/busybox ./chroot/bin/touch ln -s /bin/busybox ./chroot/bin/true ln -s /bin/busybox ./chroot/bin/umount ln -s /bin/busybox ./chroot/bin/uname ln -s /bin/busybox ./chroot/bin/uniq ln -s /bin/busybox ./chroot/bin/wc ln -s /bin/busybox ./chroot/bin/whoami ln -s /bin/busybox ./chroot/bin/yes ln -s /bin/busybox ./chroot/bin/zcat ln -s /bin/busybox ./chroot/sbin/halt ln -s /bin/busybox ./chroot/sbin/ifconfig ln -s /bin/busybox ./chroot/sbin/init ln -s /bin/busybox ./chroot/sbin/losetup ln -s /bin/busybox ./chroot/sbin/lsmod ln -s /bin/busybox ./chroot/sbin/mkswap ln -s /bin/busybox ./chroot/sbin/modprobe ln -s /bin/busybox ./chroot/sbin/pidof ln -s /bin/busybox ./chroot/sbin/pivot_root ln -s /bin/busybox ./chroot/sbin/poweroff ln -s /bin/busybox ./chroot/sbin/reboot ln -s /bin/busybox ./chroot/sbin/route ln -s /bin/busybox ./chroot/sbin/swapoff ln -s /bin/busybox ./chroot/sbin/swapon ln -s /bin/busybox ./chroot/usr/bin/basename ln -s /bin/busybox ./chroot/usr/bin/cat ln -s /bin/busybox ./chroot/usr/bin/chgrp ln -s /bin/busybox ./chroot/usr/bin/chmod ln -s /bin/busybox ./chroot/usr/bin/chown ln -s /bin/busybox ./chroot/usr/bin/chroot ln -s /bin/busybox ./chroot/usr/bin/chvt ln -s /bin/busybox ./chroot/usr/bin/clear ln -s /bin/busybox ./chroot/usr/bin/cmp ln -s /bin/busybox ./chroot/usr/bin/cp ln -s /bin/busybox ./chroot/usr/bin/cut ln -s /bin/busybox ./chroot/usr/bin/date ln -s /bin/busybox ./chroot/usr/bin/dd ln -s /bin/busybox ./chroot/usr/bin/df ln -s /bin/busybox ./chroot/usr/bin/dirname ln -s /bin/busybox ./chroot/usr/bin/du ln -s /bin/busybox ./chroot/usr/bin/echo ln -s /bin/busybox ./chroot/usr/bin/env ln -s /bin/busybox ./chroot/usr/bin/false ln -s /bin/busybox ./chroot/usr/bin/fbset ln -s /bin/busybox ./chroot/usr/bin/find ln -s /bin/busybox ./chroot/usr/bin/free ln -s /bin/busybox ./chroot/usr/bin/head ln -s /bin/busybox ./chroot/usr/bin/kill ln -s /bin/busybox ./chroot/usr/bin/killall ln -s /bin/busybox ./chroot/usr/bin/ln ln -s /bin/busybox ./chroot/usr/bin/ls ln -s /bin/busybox ./chroot/usr/bin/mkdir ln -s /bin/busybox ./chroot/usr/bin/mknod ln -s /bin/busybox ./chroot/usr/bin/mv ln -s /bin/busybox ./chroot/usr/bin/pidof ln -s /bin/busybox ./chroot/usr/bin/pwd ln -s /bin/busybox ./chroot/usr/bin/readlink ln -s /bin/busybox ./chroot/usr/bin/reset ln -s /bin/busybox ./chroot/usr/bin/rm ln -s /bin/busybox ./chroot/usr/bin/rmdir ln -s /bin/busybox ./chroot/usr/bin/sed ln -s /bin/busybox ./chroot/usr/bin/sleep ln -s /bin/busybox ./chroot/usr/bin/sort ln -s /bin/busybox ./chroot/usr/bin/sync ln -s /bin/busybox ./chroot/usr/bin/tail ln -s /bin/busybox ./chroot/usr/bin/telnet ln -s /bin/busybox ./chroot/usr/bin/test ln -s /bin/busybox ./chroot/usr/bin/touch ln -s /bin/busybox ./chroot/usr/bin/true ln -s /bin/busybox ./chroot/usr/bin/uname ln -s /bin/busybox ./chroot/usr/bin/uniq ln -s /bin/busybox ./chroot/usr/bin/uptime ln -s /bin/busybox ./chroot/usr/bin/vi ln -s /bin/busybox ./chroot/usr/bin/wc ln -s /bin/busybox ./chroot/usr/bin/wget ln -s /bin/busybox ./chroot/usr/bin/which ln -s /bin/busybox ./chroot/usr/bin/whoami ln -s /bin/busybox ./chroot/usr/bin/xargs ln -s /bin/busybox ./chroot/usr/bin/yes ln -s /bin/busybox ./chroot/usr/sbin/klogd ln -s /bin/busybox ./chroot/usr/sbin/syslogd ln -s /bin/tinylogin ./chroot/bin/login ln -s /bin/tinylogin ./chroot/bin/su ln -s /bin/tinylogin ./chroot/bin/login ln -s /bin/tinylogin ./chroot/sbin/getty ln -s /bin/tinylogin ./chroot/usr/bin/passwd ln -s /bin/tinylogin ./chroot/usr/sbin/adduser # We need to substitute all occurances of agetty to getty in etc/inittab # # Note that this is the *only* modification we are going to do to baselayout. cat ./chroot/etc/inittab | sed s:agetty:getty:g > ./chroot/etc/inittab.new mv ./chroot/etc/inittab.new ./chroot/etc/inittab # Clean up doc, man, info, locales, zoneinfo, include (if you can think of # more let me know) rm -Rf ./chroot/usr/share/{doc,man,info,locale,i18n,zoneinfo} rm -Rf ./chroot/usr/include rm -Rf ./chroot/usr/lib/locale # fix /etc/hostname and warn regarding /etc/fstab echo "using an arbitary ./chroot/etc/hostname..." echo tinytest.europeansoftware.com >./chroot/etc/hostname echo "please fix your ./chroot/etc/fstab and set your bootloader and you are ready..." # I kept an fstab in the current work dir.. so I dont have to modify it every # time I recreate the chroot. cp ./fstab ./chroot/etc/fstab