Difference between pages "Initramfs" and "Hostname"

(Difference between pages)
m (Duncan.britton moved page Initramfsmove to Initramfs over redirect)
 
 
Line 1: Line 1:
== What is initramfs? ==
+
==Introduction==
[http://en.wikipedia.org/wiki/Initramfs Wikipedia] defines initramfs as:
+
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.
<blockquote>
+
==Configuration==
initramfs, abbreviated from "initial ram file system", is the successor of initrd. It is a cpio archive of the initial file system that gets loaded into memory during the Linux startup process. The Linux kernel mounts it as root file system and starts the init process from it. This will complete certain tasks before the real root file system is loaded; thus, initramfs needs to contain all of the device drivers and tools needed to mount the real root filesystem.
+
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:
</blockquote>
+
 
+
== Do I need an initramfs? ==
+
The reason to build a kernel with an initramfs is mostly for interoperability (e.g. live-cd's) and special features like an included busybox, ssh, etc. But mostly, and that's why we are doing this here now, to have a proper kernel up and running quick'n dirty in a reasonable time without fighting hours and days until a more or less exotic hardware is perfectly run by the kernel. After having a proper basic kernel running with the help of an initramfs, I really recommend you to go a step further and build a true kernel with all features includes without an initramfs. However, relying only on a kernel to boot a system can be quite time consuming, so we have provided several initramfs options for Funtoo. If you have decided to use an initramfs, not just a kernel, check out the options below and choose the one that you like the most.
+
 
+
== better-initramfs ==
+
Piotr's better-initramfs is a popular approach among Funtoo'ers to building an initramfs. It is quick, nice, and shiny. The biggest plus is that, once built, it is kernel version independent.
+
 
+
=== Installation ===
+
To install better-initramfs on your system, change to the <code>/opt</code> directory (or any other directory that you deem suitable) and clone the better-initramfs repository from bitbucket.
+
 
<console>
 
<console>
###i## cd /opt
+
localhost ~ # ##i## Hello :)
###i## git clone https://bitbucket.org/piotrkarbowski/better-initramfs.git
+
 
</console>
 
</console>
 
+
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.
=== Building <code>/initramfs.cpio.gz</code> ===
+
Now that you have better-initramfs on your system, we can make the <code>initramfs.cpio.gz</code> image and move it to <code>/boot</code>.
+
{{fancynote| do not run <code>make prepare</code> or <code>make image</code> until you have configured your kernel. If you have not installed / configured a kernel yet, check out: [[Building_a_Kernel_from_Source| Building a Kernel From Source]] and [[Funtoo_Linux_Kernels| Funtoo Linux Kernels]].}}
+
 
<console>
 
<console>
###i## cd better-initramfs
+
localhost ~ # ##i## nano /etc/conf.d/hostname
###i## bootstrap/bootstrap-all
+
###i## make prepare
+
###i## make image
+
###i## cp output/initramfs.cpio.gz /boot
+
 
</console>
 
</console>
 +
Let's set it to hostname="oleg-stable.host.funtoo.org". Save the file and restart  a hostname service:
 +
<console>
 +
localhost ~ # ##i## service hostname restart
 +
</console>
 +
Now, let's examine our changes, after a restarting a hostname
 +
<console>
 +
oleg-stable ~ # ##i## Hello :)
 +
</console>
 +
== 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
 +
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>
 +
oleg-stable ~ # ##i## hostname
 +
oleg-stable.host.funtoo.org
 +
</console>
 +
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.
 +
<console>
 +
oleg-stable ~ # ##i## hostname -s
 +
oleg-stable
 +
</console>
 +
Good! Hostname offers more then just displaying a system host name but can also set one. Let's try:
 +
<console>
 +
oleg-stable ~ # ##i## hostname foo.bar.baz
 +
oleg-stable ~ # ##i## hostname
 +
foo.bar.baz
 +
</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.}}
  
=== Configuring <code>/etc/boot.conf</code> ===
+
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.
Now that the <code>initramfs.cpio.gz</code> file is in <code>/boot</code>, we can configure what we want the initramfs to do for us when the system boots. Below is a table of options that better-initramfs supports (from [https://bitbucket.org/piotrkarbowski/better-initramfs better-initramfs Bitbucket page]):
+
==== Options ====
+
{| {{table}}
+
!Option
+
!Description
+
|-
+
|rescueshell
+
|Drop to the rescueshell before mounting rootfs to <code>/newroot</code>
+
|-
+
|sshd
+
|Run the sshd server when the initramfs loads. This allows you to ssh into your initramfs to fix any errors that may have occurred while booting.
+
|-
+
|sshd_wait=x
+
|Wait x number of seconds after starting sshd to continue booting the system.
+
|-
+
|sshd_port=x
+
|Change the port that sshd "listens" on. The default port for sshd is port 22.
+
|-
+
|binit_net_if=interface
+
|Choose which interface the network should be configured on. For example: wlan0, eth0, etc.
+
|-
+
|binit_net_addr=<ipaddr/cidr>
+
|Configure <code>ipaddr</code> with <code>cidr</code> netmask. For example: <code>11.11.11.2/24</code>. If you do not add a netmask, the netmask is assumed to be 32. Furthermore, you will have to configure <code>binit_net_gw</code>.
+
|-
+
|binit_net_gw=ipaddr
+
|The address of your gateway. Only needed if you want to connect to WAN.
+
|-
+
|rw
+
|Mount the rootfs as read-write. By default, the rootfs is mounted as read only.
+
|-
+
|mdev
+
|Use mdev instead of devtmpfs. This option can prove handy on older kernels.
+
|-
+
|softraid
+
|Detect and run RAID arrays.
+
|-
+
|init=
+
|Change the init system. For example, if you are using systemd, change this to <code>/usr/lib/systemd/systemd</code>. The default for this option (<code>/sbin/init</code>) will work fine with OpenRC.
+
|-
+
|tuxonice
+
|Try resuming with TuxOnIce.
+
|-
+
|uswsusp
+
|Try resuming the system with userspace software suspend. This depends on the <code>resume</code> option.
+
|-
+
|swsusp
+
|Try resuming the system with in-kernel suspend. This depends on the <code>resume</code> option.
+
|-
+
|resume=<device/path>
+
|Specify the device and path from which you want to resume.
+
|-
+
|lvm
+
|Scan for volume groups. If any are found, activate them.
+
|-
+
|luks
+
|Run <code>cryptsetup luksOpen</code> on the <code>enc_root</code> variable.
+
|-
+
|luks_trim
+
|Enable support for TRIM on your LUKS encrypted root device. This option is very helpful for those using SSDs.
+
|-
+
|enc_root=<device>
+
|The device that you wish to decrypt using <code>cryptsetup luksOpen</code>.
+
|-
+
|root=<device>
+
|The name of your root device.
+
|-
+
|rootfstype=<fstype>
+
|Specify the type of filesystem that your rootfs uses.
+
|-
+
|rootdelay=<time (as integer)>
+
|How long the initramfs should wait before attempting to mount devices.
+
|-
+
|rootflags=x
+
|Pass x flags to <code>mount</code> as it mounts your rootfs.
+
|}
+
  
==== Examples ====
+
==Hosts case==
Below are examples of different use cases for better-initramfs and how your <code>/etc/boot.conf</code> should be configured for them.
+
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
{{fancynote| Realize that your <code>enc_root</code>, <code>root</code>, and <code>rootfstype</code> variables may be different from the examples provided below.}}
+
{{file|name=/etc/hosts|body=
 
+
# Auto-generated hostname. Please do not remove this comment.
==== Regular ext4 root ====
+
127.0.0.1      oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
{{file|name=/etc/boot.conf|desc= |body=
+
::1            oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
"Funtoo Linux" {
+
kernel vmlinuz[-v]
+
initrd /initramfs.cpio.gz
+
params += root=/dev/sdaX rootfstype=ext4
+
}
+
 
}}
 
}}
 +
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.
  
==== Encrypted root with lvm ====
+
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:
{{file|name=/etc/boot.conf|desc= |body=
+
<console>
"Funtoo Linux" {
+
oleg-stable ~ # ##i## echo 'aliases="10.1.12 oleg.distant.home"' >> /etc/conf.d/hostname
kernel vmlinuz[-v]
+
oleg-stable ~ # ##i## service hostname restart
initrd /initramfs.cpio.gz
+
params += enc_root=/dev/sdaX lvm luks luks_trim root=/dev/mapper/funtoo--vg-root rootfstype=ext4
+
}
+
}}
+
 
+
==== Encrypted root with lvm and RAID ====
+
{{file|name=/etc/boot.conf|desc= |body=
+
"Funtoo Linux" {
+
kernel vmlinuz[-v]
+
initrd /initramfs.cpio.gz
+
params += enc_root=/dev/md0 lvm luks luks_trim softraid root=/dev/mapper/funtoo--vg-root rootfstype=ext4
+
}
+
}}
+
 
+
== Dracut ==
+
=== Installation ===
+
To install Dracut, simply emerge it:
+
<console>
+
###i## emerge dracut
+
 
</console>
 
</console>
 
+
Examine our changes:
=== Build the initramfs ===
+
To build the initrd with dracut, we just execute:
+
 
<console>
 
<console>
###i## dracut -f --fstab --xz /boot/initramfs-3.2.6-pf.img  3.2.6-pf
+
oleg-stable ~ # ##i## cat /etc/hosts
 
</console>
 
</console>
 
+
{{file|name=/etc/hosts|body=
Generally, this should be enough!
+
# Auto-generated hostname. Please do not remove this comment.
If you experience booting problems like missing modules / drivers then just boot from your livecd and fix Dracut or consider changing to another initramfs. You can look into the man page to tweak the command a bit (e.g. --add-drivers "xz dm_crypt" etc...).
+
10.1.1.2        oleg.distant.home
 
+
127.0.0.1      oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
=== Configuring <code>/etc/boot.conf</code> ===
+
::1            oleg-stable.host.funtoo.org oleg-stable localhost localhost.localdomain
==== Examples ====
+
 
+
==== Encrypted root with lvm ====
+
{{file|name=/etc/boot.conf|desc= |body=
+
boot {
+
        generate grub
+
        default "Funtoo Linux dracut"
+
        timeout 3
+
}
+
 
+
"Funtoo Linux dracut" {
+
        kernel vmlinuz[-v]
+
        initrd initramfs[-v].img
+
        params  = quiet rootfstype=ext4
+
        params += luks enc_root=/dev/sda3
+
        params += lvm root=/dev/mapper/vg-root
+
}
+
 
}}
 
}}
[[Category:Kernel]]
 

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