Difference between pages "Building a Kernel from Source" and "Hostname"

(Difference between pages)
 
 
Line 1: Line 1:
Setting up a proper kernel yourself - lean, mean and tailored to your hardware,  is the challenge by which a linux user can graduate to becoming a Funtoo knight ;-)
+
==Introduction==
 
+
A hostname is a unique name created to identify a machine on a network. In computer networking, a hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet. Hostnames may be simple names consisting of a single word or phrase, or they may be structured.
Even though many of us are using enterprise-ready kernels in datacenters, there is almost nobody who hasn't at least considered building a kernel for his laptop / PC.
+
==Configuration==
We are showing here how an intermediate Linux user can use an alternative to the standard beginners "genkernel" approach, to compile a custom kernel, in a relatively speedy and easy set up.
+
In Funtoo Linux <code>/etc/conf.d/hostname</code> is the only configuration file for setting a hostname. In OpenRC framework <code>/etc/conf.d/foo</code> is the configuration file for a corresponding Init script <code>/etc/init.d/foo</code>.  With the case of hostname, default value in <code>/etc/conf.d/hostname</code> is set to ''localhost'', means when system boots and OpenRC's <code>/etc/init.d/hostname</code> script started a hostname getting only ''localhost'' name.  How it looks?  In your shell promt this will look in following way, an example for root:
 
+
== Minimum Requirements ==
+
* '''Understand the command line'''
+
* '''Know where the kernel files are located'''
+
 
+
== Assumptions ==
+
You start from an installed Funtoo system on the disk, or at least, you are on stage3 in a chrooted environment from a live cd, following somehow the Funto [[Installation (Tutorial)|Installation Tutorial]].
+
 
+
== Less advanced version ==
+
=== Emerging the kernel sources ===
+
To begin, we have to figure out which kernel sources we will use. If you are unsure about which sources are available and what their benefits and drawbacks are, check out the [[Funtoo_Linux_Kernels| Kernels]] page.
+
 
+
After you have made a decsion as to which kernel you want to install, emerge it:
+
 
<console>
 
<console>
###i## emerge vanilla-sources
+
localhost ~ # ##i## Hello :)
 
</console>
 
</console>
Portage will now go about installing the sources to ''/usr/src''. It will also symlink the kernel-version directory to a directory called ''linux''.
+
Let's play a bit with a configuration. Open <code>/etc/conf.d/hostname</code> with your favorite editor and set a hostname of your choice. Below, I will use a real examples  from one of my working test boxes.
 
+
=== Configuring the kernel ===
+
Now that the kernel sources are on your system, you should configure them. To do this, change your directory to ''/usr/src/linux''
+
 
<console>
 
<console>
###i## cd /usr/src/linux
+
localhost ~ # ##i## nano /etc/conf.d/hostname
 
</console>
 
</console>
As we are now in the kernel sources directory, we can run a script that allows us to modify them. Run:
+
Let's set it to hostname="oleg-stable.host.funtoo.org". Save the file and restart  a hostname service:
 
<console>
 
<console>
###i## make menuconfig
+
localhost ~ # ##i## service hostname restart
 
</console>
 
</console>
While you edit the sources, keep the following in mind:
+
Now, let's examine our changes, after a restarting a hostname
* To build something into your kernel, press y when you have it selected.
+
* To exclude something from your kernel, press n when you have it selected.
+
* To build something as a module, press m.
+
 
+
Things that you may need to include in your kernel:
+
* Wireless/LAN drivers
+
* Support for your graphics card
+
* Support for your audio card
+
* Support for USB devices
+
{{fancynote| Many pages on the wiki will tell you the kernel requirements for the application that they are about. Keep your eyes open for the blue background, white text sections of pages. Like on this one: [[uvesafb| uvesafb]]}}
+
 
+
=== Building and installing the kernel sources ===
+
After you finish configuring your kernel sources, you will need to build them. To build your sources, run the following:
+
 
<console>
 
<console>
###i## make
+
oleg-stable ~ # ##i## Hello :)
 
</console>
 
</console>
{{fancytip| You can add -j<number of processing cores + 1> after make to build the kernel more quickly.}}
+
== Diving deeper==
 
+
Notice, that in above output we seeing a shortened hostname and not a FQDN (Fully Qualified Domain Name). Don't be frustrated. This is  how  default bash promt <code>PS1</code> set. To get nice promts, please, follow http://www.funtoo.org/Prompt_Magic
When the kernel and its modules finish building, install them:
+
Another way to test our settings is using a '''hostname''' command. Here we will show only  some of it's features. Let's try to execute '''hostname''' command:
 
<console>
 
<console>
###i## make install modules_install
+
oleg-stable ~ # ##i## hostname
 +
oleg-stable.host.funtoo.org
 
</console>
 
</console>
Now that you have installed your kernel and modules, it is a good idea to install an initramfs. If your system has a separate ''/usr'' partition, is encrypted, or uses some other non-standard configuration, it will probably not boot without an initramfs. See [[Building_a_Kernel_from_Source#Initramfs| Initramfs]].
+
Now we see our fully qualified domain name hostname just how we configured it in <code>/etc/conf.d/hostname</code> in above paragraph. To get a short hostname we need to set '''-s ''' (short) argument to hostname command.  
 
+
== Advanced version ==
+
=== Getting ready to start ===
+
 
+
{{fancynote| In this case we are building a kernel that is booting root in LVM over encrypted LUKS container.
+
If you don't have this setup, don't worry, you just don't need all the modules, but everything else is similar.}}
+
First, there is the decision which linux kernel sources we need.
+
There are plenty of them in the repositories around, often it is not easy to distinguish between them.
+
 
+
I would always trust my distribution of choice and take what is has to offer - and funtoo has a lot to offer!
+
 
+
I really do recommend (especially if it is your first time) to build a debian-sourced genkernel like described in chapter 5 "Using Debian-Sources with Genkernel" in the [[Funtoo_Linux_Kernels| Funtoo Kernels Tutorial]].
+
 
+
From there you should have a running system booting nicely from your own build (just little bit bloated) kernel. This is more than you can expect from any other ready to go distribution.
+
 
+
{{fancynote| We are using RedHat's dracut in order to build a nice initramfs (containing all the necessary tools and extra drivers our kernel might need to start the system). Although dracut is the way to go, more sophisticated and not as buggy as gentoo's genkernel approach, more and more funtoo geeks start using slashbeast's better-initramfs, which we will cover at the end of this howto! So after having set up a genkernel from debian or gentoo sources we are going to build a kernel with either (or both) dracut or/and better-initramfs. So gentoo sources with genkernel is always my backup if anything is not working correctly on my system. For the slightly more geeky approach with my own initram I am using pf-sources, ck-sources or any other more or less heavily patched sources.}}
+
 
+
Let's go!
+
 
+
=== Kernel Sources ===
+
The source you use on your system is up to you. For a laptop or desktop system, the following are recommended:
+
* '''{{Package|sys-kernel/pf-sources}}'''
+
* '''{{Package|sys-kernel/ck-sources}}'''
+
* '''{{Package|sys-kernel/gentoo-sources}}'''
+
* '''{{Package|sys-kernel/git-sources}}'''
+
* '''{{Package|sys-kernel/sysrescue-std-sources}}'''
+
* '''{{Package|sys-kernel/debian-sources}}'''
+
{{fancynote| If you are unsure of which sources you would like to use, emerge <code>gentoo-sources</code>. That's always a safe bet for a general system. For more information on available kernels, check out: [[Funtoo Linux Kernels]]}}
+
 
+
=== Prerequisites ===
+
 
+
Regardless of the tools you already have installed, it is recommended to follow the steps below, even if you find them to be redundant.
+
First, we edit our <code>/etc/portage/make.conf</code>:
+
 
+
<pre>
+
#These compiler flags are just tweaking (optimazation) and NOT necessary:
+
CFLAGS="-O2 -pipe -march=native -ftracer -fforce-addr"
+
CXXFLAGS="${CFLAGS} -fpermissive -fomit-frame-pointer"
+
KDIR=/usr/src/linux
+
KERNEL="symlink build"
+
USE="$KERNEL ....here are your use flags...."
+
## These modules are available:
+
## DRACUT_MODULES="dracut_modules_biosdevname dracut_modules_btrfs dracut_modules_caps dracut_modules_crypt dracut_modules_crypt-gpg dracut_modules_dmraid dracut_modules_dmsquash-live dracut_modules_gensplash dracut_modules_iscsi dracut_modules_livenet dracut_modules_lvm dracut_modules_mdraid dracut_modules_multipath dracut_modules_nbd dracut_modules_nfs dracut_modules_plymouth dracut_modules_ssh-client dracut_modules_syslog"
+
## We will use these modules for LVM / LUKS:
+
DRACUT_MODULES="crypt lvm plymouth biosdevname dmraid crypt-gpg dmsquash-live ssh-client syslog"
+
</pre>
+
 
+
Next, we set the package keywords by adding the following to <code>/etc/portage/package.use</code>:
+
 
+
<pre>
+
sys-kernel/dracut dm net device-mapper crypt lvm
+
</pre>
+
 
+
{{fancynote| If you don't have lvm over encrypted LUKS you just add the "net" keyword here, or "selinux".}}
+
 
+
 
+
Next, we build our packages:
+
 
<console>
 
<console>
###i## emerge -av app-portage/gentoolkit sys-kernel/pf-sources sys-kernel/dracut sys-boot/plymouth sys-boot/plymouth-openrc-plugin
+
oleg-stable ~ # ##i## hostname -s
 +
oleg-stable
 
</console>
 
</console>
 
+
Good! Hostname offers more then just displaying a system host name but can also set one. Let's try:
=== Preparing the kernel ===
+
 
+
We go now to the sources directory and enter the following commands to update the kernel's .config  file:
+
 
<console>
 
<console>
###i## cd /usr/src/linux/
+
oleg-stable ~ # ##i## hostname foo.bar.baz
###i## make clean
+
oleg-stable ~ # ##i## hostname
  CLEAN  .
+
foo.bar.baz
  CLEAN  arch/x86/kernel/acpi/realmode
+
  CLEAN  arch/x86/kernel/cpu
+
  CLEAN  arch/x86/kernel
+
  CLEAN  arch/x86/vdso
+
  CLEAN  arch/x86/lib
+
  CLEAN  drivers/gpu/drm/radeon
+
  CLEAN  drivers/net/wan
+
  CLEAN  drivers/scsi/aic7xxx
+
  CLEAN  drivers/tty/vt
+
  CLEAN  drivers/video/logo
+
  CLEAN  firmware
+
  CLEAN  kernel
+
  CLEAN  lib/raid6
+
  CLEAN  lib
+
  CLEAN  security/apparmor
+
  CLEAN  security/selinux
+
  CLEAN  usr
+
  CLEAN  arch/x86/boot/compressed
+
  CLEAN  arch/x86/boot
+
  CLEAN  .tmp_versions
+
  CLEAN  vmlinux System.map .tmp_kallsyms2.S .tmp_kallsyms1.o .tmp_kallsyms2.o .tmp_kallsyms1.S .tmp_vmlinux1 .tmp_vmlinux2 .tmp_System.map
+
###i## zcat /proc/config.gz > /usr/src/linux/.config
+
 
</console>
 
</console>
 +
As you can see, we changed a hostname on-the-fly. This is not recommended way.
 +
{{fancywarning|Please, notice that using '''hostname''' command to configure will work temporary for a current session and will be reverted back to a value set in <code>/etc/conf.d/hostname</code> file with next system restart.}}
  
Next, we run <tt>make localmodconfig</tt>. You will get some questions which you can answer mostly with either M (compiled as a module) or Y (compiled directly into the kernel). If you are not sure what to choose, press enter, and the default option will be selected.
+
Now that we got a brief description of a hostname and basic configuration steps, its time to reflect another important case which is directly related to a Funtoo Linux hostname generation, a hosts.
<console>
+
###i## make localmodconfig
+
Enable different security models (SECURITY) [Y/n/?] y
+
Enable the securityfs filesystem (SECURITYFS) [Y/?] y
+
Socket and Networking Security Hooks (SECURITY_NETWORK) [Y/?] y
+
Security hooks for pathname based access control (SECURITY_PATH) [Y/?] y
+
Low address space for LSM to protect from user allocation (LSM_MMAP_MIN_ADDR) [65536] 65536
+
NSA SELinux Support (SECURITY_SELINUX) [Y/n/?] y
+
  NSA SELinux boot parameter (SECURITY_SELINUX_BOOTPARAM) [N/y/?] n
+
  NSA SELinux runtime disable (SECURITY_SELINUX_DISABLE) [N/y/?] n
+
  NSA SELinux Development Support (SECURITY_SELINUX_DEVELOP) [Y/n/?] y
+
  NSA SELinux AVC Statistics (SECURITY_SELINUX_AVC_STATS) [Y/n/?] y
+
  NSA SELinux checkreqprot default value (SECURITY_SELINUX_CHECKREQPROT_VALUE) [1] 1
+
  NSA SELinux maximum supported policy format version (SECURITY_SELINUX_POLICYDB_VERSION_MAX) [Y/n/?] y
+
    NSA SELinux maximum supported policy format version value (SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE) [19] 19
+
TOMOYO Linux Support (SECURITY_TOMOYO) [Y/n/?] y
+
  Default maximal count for learning mode (SECURITY_TOMOYO_MAX_ACCEPT_ENTRY) [2048] 2048
+
  Default maximal count for audit log (SECURITY_TOMOYO_MAX_AUDIT_LOG) [1024] 1024
+
  Activate without calling userspace policy loader. (SECURITY_TOMOYO_OMIT_USERSPACE_LOADER) [Y/n/?] y
+
AppArmor support (SECURITY_APPARMOR) [Y/n/?] y
+
  AppArmor boot parameter default value (SECURITY_APPARMOR_BOOTPARAM_VALUE) [1] 1
+
Integrity Measurement Architecture(IMA) (IMA) [Y/n/?] y
+
EVM support (EVM) [N/y/?] (NEW)
+
Default security module
+
  1. SELinux (DEFAULT_SECURITY_SELINUX)
+
  2. TOMOYO (DEFAULT_SECURITY_TOMOYO)
+
  3. AppArmor (DEFAULT_SECURITY_APPARMOR)
+
> 4. Unix Discretionary Access Controls (DEFAULT_SECURITY_DAC)
+
choice[1-4?]: 4
+
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
+
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
+
#
+
# configuration written to .config
+
#
+
warning: (GFS2_FS) selects DLM which has unmet direct dependencies (EXPERIMENTAL && INET && SYSFS && CONFIGFS_FS && (IPV6 || IPV6=n))
+
warning: (IMA) selects TCG_TPM which has unmet direct dependencies (HAS_IOMEM && EXPERIMENTAL)
+
warning: (MEDIA_TUNER) selects MEDIA_TUNER_TEA5761 which has unmet direct dependencies (MEDIA_SUPPORT && VIDEO_MEDIA && I2C && EXPERIMENTAL)
+
warning: (ACPI_HOTPLUG_CPU) selects ACPI_CONTAINER which has unmet direct dependencies (ACPI && EXPERIMENTAL)
+
</console>
+
  
Now comes the most adventurous part!
+
==Hosts case==
 +
As per man page <code>hosts</code> stands for static table lookup for hostnames and it's configuration file is <code>/etc/hosts</code>. Here is how it looks
 +
{{file|name=/etc/hosts|body=
 +
# Auto-generated hostname. Please do not remove this comment.
 +
127.0.0.1      oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
 +
::1            oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
 +
}}
 +
As you can see it has entries from our <code>/etc/conf.d/hostname</code>. As you may have guessed, in Funtoo Linux <code>/etc/hosts</code> file entries are auto-generated, when OpenRC hostname service starts. Previously, it is used to edit <code>/etc/hosts</code> manually. In Funtoo Linux there is no such need.
  
=== Building the Kernel ===
+
What about custom hosts entries? This can be easily configured with 'aliases'. For example you want to have a hosts for your remote router or a computer in home LAN. Let's try to modify <code>/etc/conf.d/hostname</code> with adding following - my remote computer oleg.distant.home has an IP 10.1.1.2:
<console>
+
<console>
###i## make -j8  bzImage
+
oleg-stable ~ # ##i## echo 'aliases="10.1.12 oleg.distant.home"' >> /etc/conf.d/hostname
###i## make -j8 modules
+
oleg-stable ~ # ##i## service hostname restart
###i## make modules_install
+
###i## make install
+
 
</console>
 
</console>
 
+
Examine our changes:
== Initramfs ==
+
{{fancywarning| Make sure that you have built and installed your kernel sources / modules before building an initramfs.}}
+
To get your initramfs up and running, check out the [http://www.funtoo.org/Initramfs Initramfs] page. After following all the directions on the page to get your initramfs set up, continue following the ones here.
+
 
+
Update the <tt>grub.cfg</tt> with boot update, then reboot and see how it works!
+
 
<console>
 
<console>
###i## boot-update -v
+
oleg-stable ~ # ##i## cat /etc/hosts
###i## reboot
+
 
</console>
 
</console>
 
+
{{file|name=/etc/hosts|body=
[[Category:HOWTO]]
+
# Auto-generated hostname. Please do not remove this comment.
[[Category:Featured]]
+
10.1.1.2        oleg.distant.home
[[Category:Kernel]]
+
127.0.0.1      oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
 +
::1            oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
 +
}}

Revision as of 16:06, February 24, 2015

Introduction

A hostname is a unique name created to identify a machine on a network. In computer networking, a hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet. Hostnames may be simple names consisting of a single word or phrase, or they may be structured.

Configuration

In Funtoo Linux /etc/conf.d/hostname is the only configuration file for setting a hostname. In OpenRC framework /etc/conf.d/foo is the configuration file for a corresponding Init script /etc/init.d/foo. With the case of hostname, default value in /etc/conf.d/hostname is set to localhost, means when system boots and OpenRC's /etc/init.d/hostname script started a hostname getting only localhost name. How it looks? In your shell promt this will look in following way, an example for root:

localhost ~ #  Hello :)

Let's play a bit with a configuration. Open /etc/conf.d/hostname with your favorite editor and set a hostname of your choice. Below, I will use a real examples from one of my working test boxes.

localhost ~ #  nano /etc/conf.d/hostname

Let's set it to hostname="oleg-stable.host.funtoo.org". Save the file and restart a hostname service:

localhost ~ #  service hostname restart

Now, let's examine our changes, after a restarting a hostname

oleg-stable ~ #  Hello :)

Diving deeper

Notice, that in above output we seeing a shortened hostname and not a FQDN (Fully Qualified Domain Name). Don't be frustrated. This is how default bash promt PS1 set. To get nice promts, please, follow http://www.funtoo.org/Prompt_Magic Another way to test our settings is using a hostname command. Here we will show only some of it's features. Let's try to execute hostname command:

oleg-stable ~ #  hostname
oleg-stable.host.funtoo.org

Now we see our fully qualified domain name hostname just how we configured it in /etc/conf.d/hostname in above paragraph. To get a short hostname we need to set -s (short) argument to hostname command.

oleg-stable ~ #  hostname -s
oleg-stable

Good! Hostname offers more then just displaying a system host name but can also set one. Let's try:

oleg-stable ~ #  hostname foo.bar.baz
oleg-stable ~ #  hostname 
foo.bar.baz

As you can see, we changed a hostname on-the-fly. This is not recommended way.

Warning

Please, notice that using hostname command to configure will work temporary for a current session and will be reverted back to a value set in /etc/conf.d/hostname file with next system restart.

Now that we got a brief description of a hostname and basic configuration steps, its time to reflect another important case which is directly related to a Funtoo Linux hostname generation, a hosts.

Hosts case

As per man page hosts stands for static table lookup for hostnames and it's configuration file is /etc/hosts. Here is how it looks

/etc/hosts
# Auto-generated hostname. Please do not remove this comment.
127.0.0.1       oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
::1             oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain

As you can see it has entries from our /etc/conf.d/hostname. As you may have guessed, in Funtoo Linux /etc/hosts file entries are auto-generated, when OpenRC hostname service starts. Previously, it is used to edit /etc/hosts manually. In Funtoo Linux there is no such need.

What about custom hosts entries? This can be easily configured with 'aliases'. For example you want to have a hosts for your remote router or a computer in home LAN. Let's try to modify /etc/conf.d/hostname with adding following - my remote computer oleg.distant.home has an IP 10.1.1.2:

oleg-stable ~ #  echo 'aliases="10.1.12 oleg.distant.home"' >> /etc/conf.d/hostname
oleg-stable ~ #  service hostname restart
Examine our changes:
oleg-stable ~ #  cat /etc/hosts
/etc/hosts
# Auto-generated hostname. Please do not remove this comment.
10.1.1.2        oleg.distant.home
127.0.0.1       oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
::1             oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain