Gentoo – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Thu, 25 Feb 2021 03:15:45 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 How to Write Gentoo Ebuilds https://linuxhint.com/write-gentoo-ebuilds/ Sun, 21 Feb 2021 19:58:28 +0000 https://linuxhint.com/?p=90769 If you do not have the Gentoo package that you desire, fear not! You can build your own! To do this, you will need some experience with compiling software using the known Linux toolkits make, gcc, and others. To create a Gentoo package, ’emake’ is used to control and tune the process. Using these tools, you can create very slim packages that run quickly and reliably.

Ebuild Structure

To create your own ebuild, you must start with the correct *.ebuild file. Your ebuild file is the heart of your whole ebuild. The ebuild file depends on many other files, much like make does. In fact, in most cases, your ebuild will depend on make, though it is your choice. The following is the tree of neovim:
/mnt/SW/projects/System/Gentoo/gentoo/app-editors/neovim
├── files
│ ├── neovim-0.4.3-gcc-10-fix.patch
│ ├── neovim-0.4.4-cmake_luaversion_patch
│ ├── neovim-0.4.4-cmake-release-type.patch
│ └── sysinit.vim
├── Manifest
├── metadata.xml
├── neovim-0.4.4-r100.ebuild
└── neovim-9999.ebuild

So, what do you use these files for in your application? The *.ebuild file is the obvious file. This file contains the SRC_URI, which directly points to the code. Other information in the file includes the description, the website, and further information necessary for compiling the package.

The Manifest file contains the hash that uniquely identifies the code.

The metadata.xml file contains the maintainer’s name and email address, the project name, and a few flags for compiling. The remote identity is also located in this file, like the GitHub repository for the upstream. The files directory contains any patches you may need and any special settings that you require. The above example shows a file with appropriate settings according to the Gentoo maintainers.

Inside the Ebuild File

The values inside the file are easy to understand, for the most part. The Description and Homepage are for the developer’s help. The EAPI number indicates which version of Gentoo will be run. You also have the License, which is quite clear; match the License to the code for which you are building an ebuild file.

Even trickier is SLOT, which is used if you need to have several versions. SLOT will then point this build to the version that you are supporting. Most software will have the 0 value, allowing only one version at a time.

KEYWORDS is the value that indicates which platforms to which your source code can compile. The given ones are amd65, x86, and possibly arm64. A full list is available on your Gentoo system. Note that if you want to contribute, you must set a tilde (~) in front of the architecture. This means that the code is untested, so make sure that the code is well-tested before you remove this symbol. Preferably, have many users view the code before removing the tilde.

The IUSE variable returns to the parameters that you want to set for your compiler.

You also have DEPEND, which comes in three different types. The RDEPEND values are the values that you use while running the code. The BDEPEND values are the build-dependent values. The package that you are trying to add to Gentoo will contain a file describing the necessary dependencies.

For simple packages, you do not need anything else. However, the specific package that you are working on will probably have some things that must be done before compiling the code. If this does not match what Gentoo developers have expected, you can set up your own.

Functions

In the file, the installer will use certain functions for the whole process. For example, to apply patches before running the command, the src_prepare() function will handle this situation.

The src_configure() function uses econf to set, i.e., ‘use_enable.’ In this function, you can unpack your files using the unpack command. You can also pass args to ./configure for your project using econf. As you can see, these functions are named according to their make equivalents, and many times, they pass arguments across.

The src_install() function performs the same function that make install would do in a C/C++ build. However, it does contain many options that you can look up in the reference document.

Most functions are there for when you have special case software. You will probably start digging through these functions when you try implementing your first package.

Example: SimulIDE Package File

Here, we present a file that was created for the SimulIDE package. The package requires a Qt5 development environment, so you will need to add that in your ebuild file. In the following image, you can see the RDEPEND values reflecting this idea. The libraries are already contained within the Gentoo repositories, which makes it easy to point to.

# Copyright 2021 Mats Tage Axelsson
# Distributed under the terms of the GNU General Public License v3

EAPI=7

DESCRIPTION="SimulIDE simulates your circuit designs, it includes Arduino emulation."
HOMEPAGE="https://www.simulide.com/p/home.html"
SRC_URI="https://mailfence.com/pub/docs/santigoro/web/SimulIDE_0.4.14/simulide_0.4.14-SR4_Sources.tar.gz"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~x86 ~amd64"

RDEPEND="dev-qt/qtsvg
         dev-qt/qtxml
         dev-qt/qtscript
         dev-qt/qtwidgets
         dev-qt/qtconcurrent
         dev-qt/qtserialport
         dev-qt/qtmultimedia"
DEPEND="${RDEPEND}
  dev-libs/libelf
  dev-embedded/avr-libc"

src_prepare() {
  unpack simulide_0.4.14-SR4_Sources.tar.gz
}

src_configure() {
  econf --with-popt
}

In the src_prepare() function, you can see that the package is unpacked before use.

Overlay

When you have trimmed and cleaned all your mistakes, you may want to add your package to the Gentoo project. Layman was created so that you can use experimental software for your main distribution install. The project is called Overlays, but the command to install it is called Layman.

Conclusion

Creating new packages for Gentoo is an undertaking that may stretch your abilities. Even so, if you have built many packages before using make and the gcc suite of tools, you should be able to pick this process up rather quickly. Also, be sure to contribute back to the community as much as you can.

]]>
Gentoo vs. Ubuntu Linux Comparison https://linuxhint.com/gentoo-vs-ubuntu-linux-comparison/ Thu, 18 Feb 2021 16:14:17 +0000 https://linuxhint.com/?p=90130

Habit is the enemy of change. If you have been using Linux for a while, you may have gotten used to the distribution it offers. If your situation and computing needs changing, then you should think it over. If not, you might want to consider learning a new system for the benefit of apprehension. Knowledge is a very light burden to bear.

Short Gentoo

The Gentoo system is aimed at savvier users, as such, it is inconvenient to start with. As an example, your installer is a command-line only, which means you need to compile the software, so you installed. However, there are some exceptions to this.

When you choose Gentoo, you must be prepared for the command-line. Other than that, you also need no default desktop. If you want a little bit more convenience, use a derivative. You can find a comparison of derivatives in this article.

While using a command-line installer seems to be inconvenient, it is advantageous once you get used to it. The Gentoo command line package manager, in particular, has a surprising number of features, including news! With this, you can read the latest news about Gentoo from the command line.

If you have a problem finding your application, you can add support for Flatpak with a package. If you want to use AppImage, you will need the required libfuse, which Gentoo delivers as sys-fs/fuse.

Short Ubuntu

Ubuntu is a polished version of Debian. Packages included will help you in finding derivatives easier.  This is the most popular distribution delivered by Canonical. You will always find references to Ubuntu when dealing with Linux.

You are presented with a great graphical installer when you choose Ubuntu. Before you start, remember to choose your favorite desktop environment. The default is GNOME, if you want KDE, then you need to choose Kubuntu. If you have other preferences, there are a variety of pre-sets available. If you start with the wrong one, you will end up with many unnecessary packages.

Adding software can be done in many ways. Standard is of course their own repositories, which uses Debian format files. Secondly, they have also chosen and designed snap as the secondary default. Aside from that, you can also use Flatpak and AppImage.

Basic Differences in philosophy

Ubuntu uses the Debian package manager, aimed mainly at binary packages. Though source code is available for most of the packages, this makes the installation faster. Also, hopping between desktop managers is less risky. Gentoo aims to deliver the source code and let the installer compile it for the platform you are using or plan to use. Gentoo tries, and usually succeeds, to create a system that is extremely optimized for the particular system you use. You can actually pick the specific CPU model if you wish. With the USE variable, you can force the binary to only support your specific desktop. Apart from that, you can compile every package and install it on both systems. Nevertheless, the philosophy leads to very different default behavior. This led to many flame wars.

Package Differences

The packages in Gentoo contain links to the upstream and seldom has any source code included. The bulk of the package system helps you set the compilation options and handle patches.

Packages in Ubuntu, in contrast, contain the entire binary or source code. Dependencies are controlled by both systems, though in Gentoo, you can use parameters called slots to have several versions installed. In Ubuntu, you must go through hoops to get several versions, though, with applications, you can use an AppImage.

Usage and Install Differences

The main objective of Gentoo is to optimize the system on every installation. As mentioned before, this leads to a long and, often, slow installation procedure. Proponents claim that this will lead to a faster and more stable system. This is probably true as long as you take the time to do the job at the install. For small systems, it is a good idea to run your installation with a distributed compiler, like distcc. This would speed up the compilation while leading to a more optimized system. For many users, this is a nuisance. Nonetheless, for both cases, you have special distributions and procedures for the popular Raspberry Pi. This includes an optimized Stage3 file, which is a basic system that can run on the target systems. The procedure is here, it shows you how to download the image and the Stage3. On top of that, you get a short introduction to cross-compiling using the Gentoo package ‘sys-devel/crossdev’. That package supports the Armv6, so you can install on the original and, crucially, the Pi Zero W.

For Ubuntu, you can choose and install images from their website. They are ready systems that aim to be servers or desktops of your choice. You can also use the source packages and compile the thing wherein it is less complicated as compared to using Gentoo.

On larger systems, like a laptop, you must measure performance or have exceptional demands to make a significant difference. Many lovers of Gentoo choose a suitable derivative and sticks with that. When they feel that they need an improvement, they recompile relevant parts of the system.

Who is the winner?

This is a very subjective question. The answer may differ for the same user from different circumstances. Ubuntu wins on ease to start, several of packages, and convenience. Gentoo has the advantage of becoming the most performance-wise, just as their goal is. You must choose what your priorities are and go for it. The number one thing that you must consider is the distribution that matches your needs for your system. Many times, Gentoo will win, but only after you have put in the effort for the right reasons.

Conclusion

For many users, choosing Gentoo is a giant leap. A leap that they never take but can be a serious mistake if you have important reasons to use your computer or system of computers.

]]>
How to upgrade Gentoo kernel https://linuxhint.com/upgrade-gentoo-kernel/ Mon, 08 Feb 2021 14:41:29 +0000 https://linuxhint.com/?p=89163 Gentoo is a rolling release, meaning that you have new updates available at regular intervals, but there are no major updates. The idea behind this is never to have incompatible parts of the system because they belong to different major releases. You upgrade as you need to. In many other distributions, the new kernels come with the new release. In Gentoo, you have new kernels when it has been tested. You can, of course, take the latest kernel out there and run that. With the caveat that you may be quite lonely on the forums if you have problems.

Existing kernel

You may not want your own kernel. For the first boot, a standard kernel may do. This way, you get the system running, and you can boot it at any time and set everything up correctly. Compiling a kernel can also take time, so using an existing kernel can be useful. To do this, copy the kernel and the modules to the correct locations. In the newer CD, the files are in the boot directory. Usually called ‘Gentoo’, you should find them easily. One caveat is that you must make sure they are the kernel and ‘.igz’ files. Use the file command for that.

$ file /boot/*
/mnt/cdrom/boot/EFI:               directory
/mnt/cdrom/boot/gentoo:            Linux kernel x86 boot executable bzImage,
version 5.4.80-gentoo-r1-x86_64 (root@catalyst) #1 SMP Sun Jan 17 23:41:47 UTC
2021, RO-rootFS, swap_dev 0x3, Normal VGA
/mnt/cdrom/boot/gentoo-config:     Linux make config build file, ASCII text
/mnt/cdrom/boot/gentoo.igz:        XZ compressed data
/mnt/cdrom/boot/System-gentoo.map: ASCII text

As you can see, the files are clearly marked with this method so you know which one to use. Next, you need to copy modules. The modules are in your lib/modules directory, one per kernel you run.

$ cp -R /lib/modules/5.8.0-generic /mnt/gentoo/lib/modules

For the directory, you can also use ‘uname -r’ to get the name.

Install tools

Gentoo comes with tools for many advanced tasks. When compiling a kernel, you usually use ‘make config’ which you can also use inside Gentoo. However, you also have a Gentoo tool; genkernel. It can compile your kernel automatically with given standard settings. You need to be aware that you can also install a kernel just by using the emerge packaging tool. You need to pick a kernel package that suits your platform. You can see a few choices below.

$ emerge –ask sys-kernel/installkernel-gentoo

$ emerge –ask sys-kernel/installkernel-systemd-boot

One of the tools to compile your kernel, after installing sources is ‘genkernel’.

$ genkernel

The genkernel tool runs all the scripts you need to upgrade the kernel after downloading new sources.

Using Source Code

This requires more compile power, but it is one of the reasons that you choose Gentoo. In fact, all documentation assumes you want to compile your kernel and has binary kernels as an alternative. The big change about this happened in September 2020 when the Gentoo developers released pre-built kernels. You have many packages to choose from, but the procedure is the same for all of them. Pick a kernel, from here! There are many more, but you can pick those after you are done. In here, you pick the newest kernel form Gentoo.

$ emerge –ask –update –deep –with-bdeps=y –newuse sys-kernel/gentoo-sources

This implies that you are choosing to upgrade only the kernel. A full system upgrade will often upgrade the sources for a new kernel. After this, you will have several kernels, select the one you want to use.

$ eselect kernel list $ eselect kernel set 3

The system has now changed the link to /usr/src/linux. All tools will use that symbolic link. You should then copy the old config file, so most of your new kernel has the same values. The old file is available in many places; one is in your running system.

$ zcat /proc/config.gz /usr/src/linux/config

Now, you can start the kernel configuration. You do this with any of the standard packages, ‘make config’, ‘make menuconfig’ and so on. However, Gentoo has an ace up its sleeve; genkernel! This tool takes all the steps and does the whole process for you. Mind you, to optimise; you need to add a few options.

$ genkernel –oldconfig –menuconfig

You can run without any parameters, but then you have no choices about your kernel configuration. This procedure is enough for creating and installing a new kernel. Setting the parameters is a big challenge.

Using pre-built kernels

Are you sure you want to compile your own kernel? You have several choices to get a binary kernel. If you set the value below, the install of the debiansources will install the binary kernel saving you the hassle of compiling your own.

$ echo "sys-kernel/debian-sources binary" >> /etc/portage/package.use

$ emerge debian-sources

You can also get the newest stable kernel directly from the developers from their site. To install and upgrade run emerge to install it.

$ emerge –ask sys-kernel/gentoo-kernel-bin

More kernels are available, and the distribution kernels are also available.

Using unsupported Source Code

You may have your own changes to the kernel code. To handle this situation, you want to turn off the automatic handling of that code. To make sure that Portage knows what dependencies need to be handled, you need to tell it you put it there but should not be updated automatically.

The file you need to fill up to inform Portage is /etc/portage/profile/package.provided

#Marking gentoo-sources-4.9.16 as manually installed
sys-kernel/gentoo-sources-4.9.16

This way, you can use any code and do what you want without having the scripts change things around unexpectedly.

Intel Micro Code

When you have finished compiling, you should make sure you have the microcode for your processor. These packages are for the Intel processor.

$ emerge intel-microcode iucodetool

Skip this if you have an AMD processor.

Grub

You must update-grub the way you do on other distributions, with a twist.

$ grub-install –efi-directory=/boot /dev/vda

The efi stuff is needed when you do not mount your boot partition on default: ‘boot/efi’. Special for Gentoo is this little guy, which will set up all your boot related stuff.

$ ego boot update

Check that it found the kernel and intramfs, the command lists all the successes and failures. Make sure it all works.

Removing sources

Since you install the sources with the package manager, you can also use the package manager to remove them and clean the tree between compiles.

To clean your tree:

$ emerge –ask –depclean gentoo-sources

To remove a certain kernel:

$ emerge –ask –noreplace gentoo-source:5.4.83

If you want to remove the current stable branch!

Other choices

A fairly recent project in Gentoo is to add “distribution kernels”. There are three available, once you have chosen one, the system will upgrade the kernel during a regular upgrade.

Conclusion

Gentoo was built for the tinkerer from the beginning, which makes it a powerful tool for optimisation. Nowadays, you can let the distribution handle the kernel for you. You will miss out on the fine-tuning, but you can dig into that at any time by adding sources with the standard packages. All and all, Gentoo is becoming accessible to more people without sacrificing tweaking capability. Way to go; Gentoo!

]]>
Best Gentoo Linux Derivatives https://linuxhint.com/best-gentoo-linux-derivatives/ Sun, 07 Feb 2021 18:27:23 +0000 https://linuxhint.com/?p=89292 Getting started with Gentoo requires some knowledge of Linux inner workings. This can be time-consuming and frustrating, especially if you have never done it or you have relied on automated install methods for a long time. With that said, it is worthwhile finding out more about your system. You could find many interesting points that can help your private computing or even your career. Many corporations use the Gentoo base and create an internal distribution. One example is Chromium OS; many others are specialized versions for their needs.

Why derivatives?

When the designers made Gentoo, they decided to give the user full control. This is great, but it means that you have to do a lot of heavy lifting. The settings and tweaks are not the most obvious until you have read up on processors and many other parts of the system.

If you pick one of the derivatives, you can cut the learning curve and still have the advantage of tweaking your system for your hardware. When people create derivatives, they have a special need. When this need matches yours, you have a derivative distribution where most work has already been done. You can, of course, still tweak, and hopefully, contribute back to the community.

Calculate Linux

Calculate Linux comes in many flavors; this includes Desktop, server and cloud. The Desktop comes in many editions to support Cinnamon, KDE, LXQt, MATE and Xfce. You can also get the Scratch that has the X server. You can also go the other way and get the Xfce Edition Scientific. As you can see, there is a great choice of desktops and since it is Gentoo compatible you can also set your choice of Desktop afterwards. Using the Gentoo Portage system is complex and needs a lot of practice to master. You may end up with a very fast machine, but setting up will not be trivial. Calculate has a graphical setup feature that shows all options, and you can choose any edition you want from that installer. You need to know what partitions you want if you want to use existing ones and so on. Once you have made your choices, you need to wait for installing and compiling your software. The installer reminds me of the old days when nothing was assumed. You had to know what you were doing. With that said, if you know these things, the install is all done for you and updates are handled automatically. Calculate also comes as a server, a cloud instance using lxc, and you can create a server to handle all the users on your network. The server is an LDP server specially set up for this distribution; you can also use it for other operating systems. The glory of open protocols!

Pentoo Linux

As you may guess from the name, the Pentoo Linux is a specialised distribution for penetration testing. You are supposed to put it on a USB stick. The design goes so far so that you can save your changes to the stick. This is not advanced, but few people use a USB stick that way. When installed, it comes with the XFCE4 window manager to stay lean. The other tools of note are opencl cracking library and a kernel for hacking WiFi connections.

http://www.pentoo.ch/download/

Sabayon Linux

This distribution looks like the others when it comes to packages that are included. You get a full set of office tools and the browsers you may need. You have several packages for maintaining the system and software. The ISO comes with a nice installer. This needs a lot of memory to use; the install option from Grub is a much faster alternative. You do have fewer options than from the live environment. You can let the installer partition the disk for you or roll your own. Tested packages you can pick up include Kodi for playing videos, many server choices, and a home desktop system. As with many Gentoo distributions, you also have the option to run a cloud edition. They are available as Docker, LXD/LXC and Vagrant image.

Funtoo

This is the one you must consider. Why? Because the founder is the lead developer for Gentoo! This does not mean that it meets your needs, but it means it is fully compatible with Gentoo. In fact, installing it, you should use the Gentoo install ISO and download the stage3 file that suits your system and needs. In this case, you are also stuck with the same install as Gentoo. The only difference is that you can get many different stage3 files. You can choose a desktop environment in this step.

Again, as with the other distributions, you also have cloud versions. LXD is the maintainers favourite; you also have Docker images. The way to start them and use them are well documented on their website. This distribution has the advantage of having many well-tested versions that you can download as stage3 files. The other distributions also have great installers so that they will save you more hassle. Not that you would choose Gentoo is if you want to avoid the hassle.

Conclusion

Choosing a derivative Gentoo distribution will help you to get started with Gentoo and the package management system quicker. This is great if you have just a few things you want to tweak. It is also useful when you the option to perfect your settings in the future. In general, you should shop around for a distribution that matches your needs and consider a community surrounding the distribution you will have much in common with. For active computing, you need an active community.

]]>
Gentoo Linux Installation Tutorial https://linuxhint.com/gentoo-linux-installation/ Sat, 30 Jan 2021 16:21:13 +0000 https://linuxhint.com/?p=88113

The installation procedure for Gentoo involves more steps than other distributions. This is intentional so you can control the steps in a more clear way. Using this strategy, you can get started with less than 4GiB of disk and memory of down to 256MiB, 512MiB if you want to use the liveDVD. You also have the opportunity to tweak your system to be as efficient as you can make it. Your first try will be slower if you are not well versed in Linux and all the intricate details, but you can end up with a very lean system.

The media choices

Choosing where to start; As long as you have regular hardware and many times odd hardware, you should use the minimal installation CD to install. This method is also the Stage3 method. If all goes well, you will never bother with Stage1 and Stage2, but they are there for extreme install situations.

  • Minimal installation CD
  • The occasional Gentoo LiveDVD
  • Tarballs for installing exotic hardware or situations.

The tarballs

You can download compressed files that have a file system with files for the init system and basic packages. Pick one that suits your needs. If you are uncertain, take the ‘systemd’ one. This is the most common.

The other stage files are for advanced users. Developers mostly use the Stage1 and Stage2 files; if you do need them, you already know most of Gentoo.

First Boot

Download the minimal CD and burn it to a USB stick. You should consider adding the ISO file to a virtual machine and practice from there! Files are on the Gentoo site.

When the minimal CD boots, it will give you 15 seconds to choose a kernel. The intention of this is to handle a situation where the framebuffer does not work, or some other odd boot problems occur. If you do nothing, the system falls back to booting from the internal disk. If you have problems, you need to specify kernel parameters like the below.

$ gentoo scandelay

This takes the ‘gentoo’ kernel and sends the ‘scandelay’ option. Other options are a long list that you should investigate before you start, though this is not needed on most hardware.

You can also add users at this stage. These users will only work in the install system, so it is seldom useful.

Network

To get started, you can do everything on a console but using a terminal has its advantages. If you want to do this, start sshd and set a password for the root user. Start by checking your IP address.

$ ip a

Then start sshd:

$ /etc/init.d/sshd start

Then set the password for the root user, or create a new temporary user.

$ passwd

You get a long printout that suggests a safe password. Handy if you have low energy or imagination. Now that you have both, you can ssh into your install system. One warning; when you start over from the CD, the ssh key will be re-created! Any key you have on your other system needs to be erased.

Preparing the disks

The disks are prepared as with many other distributions. To make it easier to follow the rest of their documentation, name your partitions as per the Gentoo standard. For a system that you will actually use, you should have a plan here. Preferably, one which has sizes for your ‘home’ as well as the ”. Necessary parts are the ‘/’ and the ‘/boot’. For UEFI, you should have 350 Megabytes of the disk for the boot files. Use your favorite partition editor. For the UEFI partition, use ‘mkfs.vfat -F 32 /dev/sda1’ and for the main use ‘mkfs.ext4 /dev/sda2’.

Mounting the main disks

You should have at least one boot disk of 350 MiB and one that will host your system as you start. A swap partition is also good to have. You can mount the with the standard command.

$ mount /dev/sda2 /mnt/gentoo

There is no reason to mount the ‘boot’ disk until you enter the chroot environment later. You can also mount user disks or partitions, but only if you are making the final system.

Downloading the tarballs

You can download the tarballs before you start or during install. Alternatively, the install environment has the ‘Links’ browser, so you can do it with the terminal. Download the files to the Gentoo disk.

$ cd /mnt/gentoo $ links www.gentoo.org/dowloads

Once you have the files on your disk, unpack them with the tar command.

$ tar -xvf stage3-amd64-systemd-20210120T214504Z.tar.xz

Install base system

You actually have a very basic and generic system already; that is what the Stage3 file is all about. For example, you make.conf file is there with standard settings. It needs to have a mirror, though, set one using the tool.

$ mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf

It adds the value: GENTOOMIRRORS=”http://ftp.ntua.gr/pub/linux/gentoo/ https://mirror.wheel.sk/gentoo“, with your chosen mirrors, naturally. You also have an automatic option where you can specify protocol or speed constraints. There is also the deep option, where the tool actually downloads a 100KiB file to measure.

You also need an ebuild repository. This repository keeps track of what is available for upgrades. You can change this, which you will do when you look for a derivative of Gentoo. You can take the default from the newly created directory structure.

$ cd /mnt/gentoo $ mkdir –parents etc/portage/repos.conf $ cp usr/share/portage/config/repos.conf etc/portage/repos.conf/gentoo.conf

Usually, you do not change this. The cases when you do need to change it is when you have your own mirror. The below commands are directly from the gentoo.org website. They set up the environment for installing.

$ cp –dereference etc/resolv.conf /mnt/gentoo/etc $ mount –types proc /proc /mnt/gentoo/proc $ mount –rbind /sys /mnt/gentoo/sys $ mount –make-rslave /mnt/gentoo/sys $ mount –rbind /dev /mnt/gentoo/dev $ mount –make-rslave /mnt/gentoo/dev

Now, you are prepared to move into the environment you are creating.

$ chroot /mnt/gentoo /bin/bash $ source /etc/profile $ export PS1="(chroot) ${PS1}"

Inside the environment, you also need to mount the boot partition.

$ mount /dev/sda2 /boot

Which partition this is should be clear from earlier steps. On a UEFI install, you have created the ESP where you store all boot information. Next, you download the repository information into the directory defined by your repos.conf file.

$ emerge-webrsync

Here you see the first mention of emerge. This command handles all your upgrades and installation. The next vital command you need to know about is eselect. With eselect, you read the latest news about Portage

$ eselect read news

Or choose your profile;

$ eselect profile list $ eselect profile set 3

You choose the number from the list or use the entire name you see in the list. Now you MUST set the @world set to ensure the system is updated according to your system, not the stage3 you used.

$ emerge –ask –verbose –update –deep –newuse @world

The most powerful variable in GENTOO! The USE variable sets what support needs to be compiled into your programs. Used correctly, you can make your system much leaner than with other methods. You can change this to stop supporting KDE if you are certain you will not run KDE. Gentoo will then compile all programs without that support, making the binary smaller. If you decide to switch to KDE, you have to start over and re-compile all your applications.

USE="-kde gnome qt5 alsa"

All of the values are set in the default values, so what you put is a change from the normal. The first time you build it is probably better just to get the system running.

Time zone and locales

Next, set the time zone. Fill in the values in the files.

$ ls usr/share/zoneinfo $ echo "Europe/Athens" > /etc/timezone

Use emerge to configure the time correctly.

$ emerge –config sys-libs/timezone-data

Add data in your locales file:

en_GB ISO-8859-1

en_GB.UTF-8 UTF-8

Configure using the file you just created.

$ locale-gen

This is the standard for all installs in the Linux world. This is the Gentoo specific:

$ eselect locale list $ eselect locale set 3

$ env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

Automatic kernel configuration

Before you run the script, you must add your boot partition in the /etc/fstab file.

/dev/sda2      /boot    ext4    defaults      0  2

In Gentoo, you have the freedom to compile your own kernel for each machine you want to start. The better way to start is to get binary kernels that suit your needs. When you feel ready to get into the complexities of kernel compilation, do that on your running system. To pick a kernel, run emerge as always;

$ emerge –ask sys-kernel/gentoo-kernel-bin

The emerge command will install your kernel and set everything up!

Time to configure the system

Create the networking files.

/etc/conf.d/net

config_eth0="dhcp"

modules="ifconfig"

/etc/conf.d/hostname

hostname="Gentoo"

$ emerge –ask net-misc/dhcpcd

This will install the dhcpcd program for handling dhcp. The default for Gentoo is dhcp.

Settings for dhcpcd using systemd are to enable the service.

$ systemctl –now enable net@enp1s0.service

Before you can boot into the new system, you need to have your boot loader installed. Here is how you choose GRUB2.

$ emerge –ask sys-boot/grub:2

$ grub-install /dev/sda –efi-directory=/boot

$ grub-mkconfig -o /boot/grub/grub.cfg

Now, you need to update your /etc/fstab file for the live system.

/etc/fstab

/dev/sda1               /boot           ext4            noauto,noatime  1 2

/dev/sda2               /               ext4            noatime         0 1

The ‘/dev/sda’ numbers will differ depending on your partitioning scheme. You can also use unique UUID numbers. You need to figure those out using the ‘blkid’ command.

Restart into your new system

You will now be able to boot into your live system. Remove the install media and try it out. If you have missed anything, you can always start over with the install media. Many problems are details, so you have all the files downloaded and can do only part of the installation. In that installation, you still have ’emerge’ available, and that is the tool you use for your upgrades and tweaking the system.

Conclusion

Gentoo does not have its own installer, which means you need to prepare what you want to achieve. You can do this by choosing the size of disks and investigating any specific needs for your system. If you want to get started quickly, you should choose a derivative and tweak from there until you feel certain that you can handle all details in a Linux system’s initial setup.

]]>
Install Gentoo in VirtualBox https://linuxhint.com/install-gentoo-virtualbox/ Sun, 04 Mar 2018 19:36:14 +0000 https://linuxhint-com.zk153f8d-liquidwebsites.com/?p=23319

Installing Gentoo as a VirtualBox VM

Gentoo is one of the most esoteric distributions out there. It offers customizability at the expense of user-friendliness. It does, however, shed light on the internal workings of a Linux installation. To experiment with a Gentoo environment inside a VM is probably a great way to start learning about operating systems in general.

Let’s go through a step-by-step process of installing the base OS along with the explanation behind every step.

1. Getting the right installation media

The easiest way to install Gentoo is by using the Hybrid ISO (LiveDVD). Which means that the disk image can be used for installing the operating system onto another disk or it can just be used as a live environment to boot into for diagnostic purposes.

You can get the image file here. Pick the one that belongs to your hardware platform. Modern Intel and AMD processors usually offer AMD64 architecture.

Next you need to create a VM on VirtualBox. Open VirtualBox, and click on the button that says “New” now you can enter the name of the VM and select ‘Type’ as Linux and ‘Version’ as Gentoo 64-bit.

Set the memory size to 2048MB and then click on “Create” to proceed with the creation of virtual hard disk.

The default values would work just fine in this case (although we are going to work with 32GB of disk space instead of 8GB) and now you can click on ‘Create’ one last time to finalize the details.

Now, select the newly created VM from VirtualBox dashboard and you will be prompted with a start-up disk. Click on the file icon beside it and in the file explorer that opens after that navigate to the gentoo livecd iso file that you have downloaded earlier.

Once you start up the VM you will see the boot menu with the following options:

Selecting x86_64 is the most appropriate option in this case.

After that you will be greeted with a login screen with default gentoo user, click on login without entering any password (as indicated in the screenshot below).

You are now technically inside a Gentoo Operating System. However, this is a live media, which means you can’t use it as a system installed in your (virtual) hard disk. But you can use this environment to install Gentoo onto your virtual hard disk.

2. Partitioning the virtual hard disk

The .vdi disk that we created earlier is just a raw disk at this point, attached to the virtual machine and the VM itself is running the Gentoo live media. Now to install the Gentoo environment onto this disk so that it can boot itself we would need to do several things.

  1. Make the disk bootable.
  2. Format the disk with a filesystem
  3. Install the base Gentoo image onto the root filesystem.

To accomplish the 1st task we just need to make 4 partitions of the following size and preferably in the following order.

  1. Bootloader partition for grub: 50MB in size
  2. Boot partition formatted ext4: 500MB in size
  3. Swap partition for swap file: 2000MB in size
  4. Root partition for main OS and related binaries to reside. Formatted with ext4 filesystem and is going to take the remaining majority of the space of the virtual disk.

To make the partitions we first need to get the name of the virtual disk attached to the system. Open terminal (konsole) and run sudo -i to become root user and then run lsblk to list all the block storage devices.The device name in our case is sda is sda and it is of size 32GB. Next we need to enter parted utility to partition this disk. To do so run, as root:

$ parted -a optimal /dev/sda

Now we are in parted utility CLI, let’s start by listing all the partitions by typing print:

And we get an error message saying that the disk is not recognized. This is to be expected since the installation process with Gentoo is not automated, you get to manually configure every little detail including the partitioning details for your base system. First things first, let’s give our disk a proper label.

(parted) mklabel gpt

GPT labels are essential for uniquely identifying a device even after, say, the system reboots and the device is plugged in a different port this label will be responsible for telling the operating system that the disk has just changed SATA ports but it’s still the same data and format as before.

Partition the disk by running the following commands (Lines starting with ‘#’ symbol are comments to explain the command above them):

(parted)unit MB
#Sets the unit to MegaBytes

(parted)mkpart primary 1 20
#Makes a primary partition starting from 1 MegaByte to #20th for bios

(parted)mkpart primary 21 500
#Partition /boot filesystem

(parted)mkpart primary 501 2500
#Partition of size 2000MB made for swap

(parted)mkpart primary 2501 -1
#Partition for the /(root) filesystem. -1 indicates that
#this partition goes upto the very end of the disk.

You can see that each partition has a number and is of the type primary. However, they are not formatted with any particular file system or have any use names given or flags set to them. Let’s do that.

(parted)name 1 grub
(parted)set 1 bios_grub on
#The partition number 1 has its bios_grub flag set to one
#and is given an appropriate name.
(parted)name 2 boot
(parted)name 3 swap
(parted)name 4 root
(parted)quit

After setting appropriate names to all the 4 partitions and 1 bios_grub flag to the first partition we quit the parted utility. Now we move on to formatting the partitions with an appropriate filesystem in our usual bash shell (still as root user) by first running the following command:

$lsblk
#To list all the partition and check their device node names

You can see that the partitioning scheme has labeled the first partition sda1 which corresponds to grub partition and so on and so forth until sda4. The devices are present in /dev directory as /dev/sda1 , /dev/sda2 and so on.

To format them accordingly, run the commands:

$mkfs.ext4 /dev/sda2
$mkfs.ext4 /dev/sda4
$mkswap /dev/sda3
$swapon /dev/sda3

Now we can mount these partitions into the current live environment so that all the necessary operations like building the kernel can be performed in there and stored persistently.

$mount /dev/sda4 /mnt/gentoo
$mkdir /mnt/gentoo/boot
$mount /dev/sda2 /mnt/gentoo/boot

Our would be root partition is mounted at /mnt/gentoo of the current livecd environment and similarly our would be boot partition is mounted on /mnt/gentoo/boot.

3. Getting tarball and using chroot

Now that we have our disk prepared for us, it is time for us to get the tarball of gentoo source code and place it in there. In the live CD environment, open the browser open this link and click on the Stage3 archives under the amd64 section at the top of the page.

Once the download is complete, copy the tarball to the /mnt/gentoo directory and extract it’s content in there.

$cp /home/gentoo/Downloads /mnt/gentoo
$tar xpf stage3-*.tar.xz --xattrs-include='*.*'
--numeric-owner

In the second command, the tar utility is used to uncompress the tarball. xpf  tells the tar command that we want to x extract, p preserve permissions on the files and f to imply that we are extracting files and not standard input.

The file extension may not be tar.xz in your case. Observe the name of your tarball file and type in accordingly.

The --xattrs-include part of the command preserves the attributes (read, write and execute) of individual files

And the --numeric-owner ensures a group and user ID number as approved by the Gentoo convention for a typical setup.

If you see the contents that would be extracted in your /mnt/gentoo directory they would resemble a typical Unix root environment with directory like /etc /sbin, etc. The idea behind this is that, once all the files necessary for a working Gentoo environment are extracted we will change our root directory to /mnt/gentoouse tools and package managers to configure it. The package manager would make changes in the / directory but it would be cheated into making changes in /mnt/gentoo directory instead.

Since our would be root partition is mounted on this directory, all the changes would be made over there and then we would boot off this new environment once we are done.

But first, let’s make a few changes in the configuration files:

$nano /gentoo/mnt/etc/portage/make.conf

After the CFLAGS line you should add the following lines which would let portage to treat c++ files the same way as c files. Portage is gentoo’s package manager, loosely speaking. It is used to fetch source code of programs so you can compile them all (automatically) on your native system.

$CXXFLAGS="${CFLAGS}"

Also copy the resolv.conf file from your livecd environment to the new root.

$cp -L /etc/resolv.conf /mnt/gentoo/etc/

Now we make sure that all the filesystems necessary for the Linux kernel to gather information about the system are available when it tries to boot. So we take the information gathered by the livecd image about our virtual machine and its hardware and we bind those to our new root filesystem.

$mount -t proc /proc /mnt/gentoo/proc
$mount --rbind /sys /mnt/gentoo/sys
$mount --rbind /dev /mnt/gentoo/dev

It’s time for us to chroot (change root) to /mnt/gentoo.

$chroot /mnt/gentoo /bin/bash
$source /etc/profile
$export PS1=”(chroot) $PS1

4. Compiling the Linux kernel

Let’s sync our portage tree (software repository) with the official version. This is similar to apt update in Ubuntu.

$emerge-webrsync

Once that finishes, we can select a profile for our system. Which essentially tunes the system for a specific use-case (server, workstation, etc.). We will be going with a KDE plasma environment listed at number six.

$eselect profile list
$eselect profile set 6

Time zone and locale configurations are next:

$ls /usr/share/zoneinfo

Locate your location in this directory. In this case, it was Asia/Dili

$cp /usr/share/zoneinfo/Continent/City /etc/localtime
$echo " Asia/Dili" > /etc/timezone

Next uncomment the location specific character set and language that you want to use from the file /etc/locale.gen. We uncommented the line en US.UTF-8 UTF-8.

$nano /etc/locale.gen

Apply the changes:

$locale-gen
$env-update && source /etc/profile

Now, we can get Linux kernel sources and start compiling them:

$emerge gentoo-sources
$emerge genkernel
$genkernel all

The last command will start compiling the kernel which would take a long time, especially if you have limited hardware resources.

5. Finishing touches

After the kernel compilation we just need to make a few more changes like installing grub, adding a user and making sure that the operating system mounts the essential filesystems automatically during the boot process.

To make sure that the last of those things happen, in the chrooted environment edit the file /etc/fstab where fstab stands for filesystem table:

$nano /etc/fstab

At the bottom of the file add the following lines:

/dev/sda2 /boot     ext4    defaults,noatime     0 2
/dev/sda4 /    ext4    noatime              0 1
/dev/sda3 none swap  sw                   0 0

Install DHCP client so your VM will have network connectivity.

$emerge dhcpcd

Make sure that the DHCP client starts at the boot process:

$rc-update add dhcpcd default

Setting a password for the root user is as simple as entering the command below and entering your new password when prompted:

$passwd

To add a new user named bob enter the command:

$useradd -m -G users,wheel,portage -s /bin/bash bob
$passwd bob ## This is to set a password for user bob

We would also need sudo so let’s install that:

$emerge sudo

And then allow the members of wheel group to execute any arbitrary command, we need to edit the /etc/sudoers file:

$visudo

Lastly, we need to install and configure grub bootloader:

$emerge grub
$grub-install /dev/sda
$grub-mkconfig -o /boot/grub/grub.cfg

Now we can exit the chroot environment, and unmount the filesystems:

$exit
$umount -l /mnt/gentoo/dev{/shm,/pts,}
$umount -l /mnt/gentoo{/boot,/proc,}
$shutdown now

Go to the VM’s setting and in the storage section, remove the livedvd image attached to the VM.

Upon starting the VM again you will be greeted with a tty interface to your newly installed Gentoo operating system. Login as using the username and password that you chose during the installation.

Conclusion

Just the installation process for Gentoo reveals a lot more about the internal workings and structure underneath most Unix environments. If one desires to attain a deeper knowledge of the system the Gentoo Handbook would be a great place to start!

]]>