Gentoo is justly appreciated for its flexibility: Portage allows you to build a system optimized for any tasks you may need to perform. And believe me, it’s really for the best if the cute blonde from your office should never compile Firefox on her own… Never mind my machismo, what can be better than a distribution you only have to build once! So that after 5 or 10 minutes of installation, you find yourself with the whole bunch of software you need and which you have assembled, configured and optimized to your liking.
This article describes how to build one’s own Gentoo-based distribution with Calculate Utilities 2.2. When you’re finished, you get a hybrid ISO which can be burnt to a CD/DVD or flashed on a USB stick, fully compatible with Gentoo, to be installed on a USB-HDD, a USB-Flash, or a HDD, supporting LVM and Raid installation, supporting numerous filesystems: ext4, ext3, ext2, reiserfs, btrfs, xfs, jfs, nilfs2 or fat32.
When I wrote this, I was thinking about Gentoo users in general, system administrators, teachers of computer science… In fact, all Linux fans might be interested.
Everything I describe below is done from the console, with
Of course, you must be running Gentoo for this to work, or any Gentoo-based distribution; you will also need Internet access. I personally was using 64-bit Calculate Linux Desktop 11.9 KDE.
Let’s start by installing
calculate-builder, the two utilities we’ll want. On Gentoo, add Calculate overlay first:
emerge layman layman -a calculate emerge calculate-assemble calculate-builder
Now decide on your configuration. Basically, you can choose from:
# Gentoo Stage3, a minimum minimorum to start building your system;
# Calculate Scratch Server (CSS), which is actually a very same Gentoo Stage3 that comes with a kernel, a bootloader, drivers, Portage and Calculate Utilities;
# Calculate Linux Scratch (CLS), which means CSS + Xorg + wireless;
# Calculate Linux Desktop with KDE, Gnome or XFCE environment (respectively CLD, CLDG or CLDX); Calculate Directory Server (CDS) should also work.
Depending on your tasks, download the latest Gentoo Stage tarball or Calculate Stage image and put it either in
cd /var/calculate/remote/stages wget http://mirror.yandex.ru/gentoo-distfiles/releases/x86/current-stage3/stage3-i686-20111018.tar.bz2
cd /var/calculate/linux wget http://mirror.cnet.kz/calculate/CLDX/stages/i686/cldx-20111024-i686.iso
Unlike Gentoo Stage4 tarballs, a Calculate Linux Stage image includes a Portage tree. If building from a Gentoo Stage, you will have to download a Portage snapshot and save it in
cd /var/calculate/remote/snapshots wget http://mirror.yandex.ru/gentoo-distfiles/snapshots/portage-20111024.tar.bz2
Note that the packages are regularly updated.
For the purposes of this article, I chose 32-bit CLDX, because:
- It comes with many useful programs out of the box;
- It is not Gnome- or KDE-bound;
- XFCE desktop environment is lightweight and can be easily uninstalled if not needed.
- Getting ready
cl-assemble will prepare your system for the building procedure. You are free to choose among available profiles. Calculate Linux profiles all have USE flags selected so that to assure maximum efficiency of the chosen DE. CLD is thus optimized for running Qt/KDE, CLDG, for Gtk/Gnome, and XFCE, for Gtk. CLDX is probably the best choice if you do not intend to use KDE or Gnome, considered cumbersome by some.
If you try to put “CLDX” as the profile, you will be prompted for a more precise name:
You will also have to specify the partition you want to install your new system on. It may be either a hard disk partition (10-15 GB) or a directory. If the latter is applied, some additional time will be spent on deleting old files. By default,
calculate-assemble uses Gentoo Stage3 and the latest Portage snapshot:
We, however, have decided upon 32-bit CLDX; it can be downloaded from here. To use this image, please specify the correct profile and, should you be running a 64-bit system (as I did), tell it explicitly that you want i686 architecture:
cl-assemble -p desktop/CLDX/x86/binary -d /dev/sda2 --source=CLDX --march=i686
It took about 10 minutes all in all on my machine:
- Upgrading the system
cl-make helps you build your system, but you should consider several options. If you want the system to be built from Stage3, use
"-m" (or "--make"); if you prefer using a Calculate image instead, apply the
"-u", (or "--update") option. The
"-V" (or "--withvideo") option will tell the system to copy proprietary video drivers. Copying without installing does not violate the GPL licence. You can still choose the proprietary driver, though, to be installed onto your system at booting time.
cl-make -u -V
You’ll note that I specified no profile. It would’ve made sense only if I wanted to build several systems simultaneously: for instance, both 32-bit and 64-bit versions. I’d then have put “-p amd64” and “-p x86”. The system would’ve compared the versions and tried to determine the relevant profile.
In my case, about 40 packages were updated.
Calculate Utilities log their activities in
Some values, such as Portage rsync server or available partitions, may be set in CU variables. Here is an example, taken from a real-life server:
Once the available partitions are set, you don’t have to use the corresponding option again.
I began writing this when the procedure started. Gtk and python turned out to be the first on the update list - I should’ve downloaded today’s Stage image, really! Even though I chose the binary profile, the newest packages are being compiled from the source. I’d better make myself a cuppa while the update is still running
- Making your modifications
That’s what you were looking for all along! Right, you can modify a lot of things:
- package contents;
- build flags;
- software settings;
- users’ environment settings;
- themes, etc.
As you’ve probably noticed, the system image was deployed in
/mnt/calculate-desktop-CLDX-x86-binary/; use this path to make your modifications. The screenshots below reveal that the system is being configured. All settings templates are stored in
/usr/share/calculate/templates/assemble/. Your only concern should be to prevent collisions: sometimes this can be fixed by creating your own templates for modifications, sometimes you should use alternative files. We are going to see every step in detail.
4.1. Build flags
USE flags are used for managing assembly settings. Cutting down dependencies might prove very useful:
- your programs will run faster;
- your system will be more secure;
- no more need to handle dependencies you don’t need;
- some disk space will be freed up.
Let’s have a look at the USE variable’s contents. Please execute:
linux32 chroot /mnt/calculate-desktop-CLDX-x86-binary /bin/bash -c “emerge --info”
Note that I suggest calling chroot with the
linux32 tool: this is because I was building a 32-bit system on a 64-bit platform. If such is not your case, no need to run
USE flags are quite a lot. For more information on them, see
/usr/portage/profiles/use.desc for global flags and
/usr/portage/profiles/use.local.desc for individual flags.
If you want flag modifications applied to all packages, edit
make.conf. While building the system, the
/etc/make.conf file will be overwritten, that’s why I recommend using
Try, for instance, disabling ipv6 support globally. You’ll have to append the following to
Let’s see where it gets you. This time, run the update command with the
-U option instead of
-u: you will thus save time on synchronizing Portage. Enter
cl-make -U -V:
Note. Since the Xorg server was recompiled while updating packages, its modules will be rebuilt at the end. If you start building the system several times, the program will analyze the
emerge.log file and rebuild Xorg drivers each time a new building procedure is launched. To avoid this, you can remove
var/log/emerge.log from the assemble directory. It will be deleted anyway when the ISO is created.
4.2. Package flags and masking
The paths used to modify USE flags and masks are:
etc/portage/package.unmask. Be aware that
emerge 2.2 is able to autounmask dependencies.
Let me explain how to unmask a package, e.g. the Firefox Internet browser. Start with chrooting:
linux32 chroot /mnt/calculate-desktop-CLDX-x86-binary env-update && source /etc/profile
To learn the correct package name and view all available versions, enter:
eix firefox * www-client/firefox Available versions: *3.6.12 3.6.20 ~3.6.21 ~3.6.22 ~7.0.1-r1
As you can see, the stable version is 3.6.20. Unmask version 7.0.1-r1:
To update the settings, you should use
dispatch-conf instead of
This tool helps you update masks and USE flags. In both cases, hit “u” to accept the suggested modifications.
You may want to check and write out other necessary package names. When you’re finished, check the dependencies:
emerge -p package1 package2 ..
4.3. Adding packages
All installed packages, but not their dependencies, are added to the ‘world’ file. Whenever you emerge a package, it is installed along with the dependent libraries. When the system does not need a library any longer, it can be removed by running
emerge --depclean. That’s why it is important that all packages (without their dependencies, though) be listed on the ‘world’ file. To delete such packages, run
emerge --unmerge, specifying the package name(s) as the argument. You can do it manually, too, by editing the world file and executing
emerge --depclean after that.
CU use metapackages to build dependencies trees, based on
app-misc/calculate-meta. In fact, USE flags handle the whole dependencies tree. Since you may have tried programs while building the system,
var/lib/portage/world will only contain this metapackage before the system image is created.
Portage provides a very nice tool, helping you add your packages to the distribution, which are sets. Sets allow you to create thematic software selections. For your convenience, sets support nesting. You can edit your package list in the
@custom set, which is stored in
/etc/portage/sets/custom. Just append the name of the package to it:
You can also create a new set under another name, e.g. ‘web’, which would contain your package, and put a link to it in the ‘custom’ file:
A set may thus contain nested sets as well as packages.
When updating the system, the programs from the set will be installed, since it is listed on its own ‘world’ file, located at
4.4. Removing packages
Clearing the world file and executing
emerge --depclean will result in a pure and simple Stage3. That is, a minimal configuration is still preserved as the ‘system’ set. To update the latter, run either
emerge system or
emerge @@system. The calculate-meta@ metapackage will calculate dependencies depending on the profile you chose. Special USE flags such as
calculate_noxfce and other are dedicated to removing some of the dependencies; their names are explicit enough. To see the whole list of available flags, please refer to
/var/lib/layman/calculate/profiles/desc/calculate.desc. For instance, you may disable wireless support. To do this, edit the
/etc/portage/make.conf file by appending to it:
4.5. Saving changes
Let’s sum it up: you have added Firefox, removed wireless support and will now sync the system image:
cl-make -U -V
firefox package will be installed, while the unnecessary dependencies will be removed:
- Creating the new system image
To finally create the image of your new system, use the
cl-image --live iso
The “–live” option saves several seconds when booting from a LiveCD or a USB-Flash. I recommend to use it with the latest Calculate Linux Stage image.
- Finalizing your installation
If needed, or when the installation is complete, you can break the procedure by executing:
I was experimenting with Calculate Linux Desktop XFCE and CLDX, its binary profile. Futher updates will be done through
emerge -uDNa world, all and every USE flag taken into consideration. If my flags are the same as in the binary repository, the binary package will be installed; if there are differences, the package will be compiled on my computer.
As a result, I got a system image with the software I had chosen. However, this article does not cover all possibilities. For instance, I could have wanted to create user environment templates, and more.
Next time, expect me to explain how to achieve similar results with more usability and without the hard disk
Originally written by Alexander Tratsevskiy