Difference between pages "LXC Fun" and "Install/pt-br/Kernel"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
(feel free to correct the typing errors, thank you)
 
 
Line 1: Line 1:
Linux Containers, or LXC, is a Linux feature that allows Linux to run one or more isolated virtual systems (with their own network interfaces, process namespace, user namespace, and power state) using a single Linux kernel on a single server.  To learn more take a look at the [[LXC]] article.
=== Configurando e instalando o kernel Linux ===


In this Howto you will be shown how to create containers, how to start, stop, freeze and unfreeze them and also some more fun parts like snapshoting and clonig. To have all this working you will have to have your lxc store (/var/lib/lxc/ and /var/lib/lxcsnaps) to be on a '''btrfs filesystem'''.
Agora é hora de construir e instalar um kernel Linux, o qual é o coração de qualquer sistema Funtoo Linux. O kernel é carregado pelo boot loader, e interfaces diretamente com o hardware do seu sistema, e permite programas regulares (userspace) serem executador.


__TOC__
Um kernel deve ser configurado propriamente para o hardware do seu sistema, desse modo ele suporta seus hard drives, file systems, placas de rede, e assim por diante. Usuários de Linux mais experientes pode escolher instalar o kernel sources e configurar e instalar seu próprio kernel. Se você não sabe como fazer isso, nós fornecemos ebuilds que construirão automaticamente um kernel "universal", módulos e initramfs para a inicialização do seu sistema que suporte todo o hardware. Esse é um jeito extremamente simples de construção de um kernel que colocará seu sistema para inicializar.


== Creating containers ==
Qual é o nosso objetivo? Para construir um kernel que reconhecerá todo o hardware em seu sistema necessário para inicialização, você será cumprimentado por um prompt de login amigável depois que a instalação estiver completa. Esses instruções lhe guiarão através do processo de instalação de um kernel no modo "fácil" -- sem exigir configuração do usuário, ao utilizar um kernel "universal".
Creating containers is quite easy using lxc-templates. They are located in the /usr/share/lxc/templates directory. You can find there many distributions like archlinux, centos, debian, fedora, opensuse, ubuntu, gentoo and some more. There is also an inofficial funtoo template that can be found at https://github.com/golodhrim/lxc-funtoo/blob/master/lxc-funtoo. The script creates funtoo container, however I was not able to use it with lxc-create script from the lxc utils. You have to run it as a stand-alone script.


So how do you create other containers? I am going to use a debian container for this howto. You will have to emerge debootstrap.
==== Package Sets ====


<console>
Antes que estalemos um kernel, vamos cobrir um recurso do Portage chamado package sets. Portage, o sistema gerenciador/ports de pacotes para o Funtoo Linux, manterá rastro de pacotes do sistema assim como pacotes que você tem instalado ao invocar <code>emerge</code> diretamente. Esses pacotes que são parte do sistema base são considerados parte do conjunto de pacote do "sistema", enquanto pacotes que você tem instalado ao digitá-los na linha de comando (tal qual "gnome" em <code>emerge gnome</code>) serão adicionados ao conjunto de pacote "world". Isso proporciona um jeito fácil de atualizar o sistema inteiro.
###i## emerge -av debootstrap


* IMPORTANT: 8 news items need reading for repository 'gentoo'.
No entanto, as vezes é bom ser capaz de atualizar o kernel todo por sim só, ou deixar uma atualização do kernel fora da sua regular atualização completa do sistema. Para fazer isso, criaremo uma nova configuração de pacote chamada "kernel".
* Use eselect news to read news items.


==== Configuração de Pacote do Kernel ====


These are the packages that would be merged, in order:
Para criar a configuração de pacote do kernel, realize os seguintes passos:


Calculating dependencies... done!
<console>
[ebuild  N    ] dev-perl/TimeDate-2.300.0  31 kB
(chroot) # ##i##mkdir /etc/portage/sets
[ebuild  N    ] app-arch/dpkg-1.17.10  USE="bzip2 lzma nls unicode update-alternatives zlib -dselect {-test}" 4,100 kB
(chroot) # ##i##echo sys-kernel/debian-sources > /etc/portage/sets/kernel
[ebuild  N    ] dev-util/debootstrap-1.0.59  96 kB
 
Total: 3 packages (3 new), Size of downloads: 4,226 kB
 
Would you like to merge these packages? [Yes/No]
</console>
</console>


After installing debootstrap, you can create your debian container using:
Agora, vamos querer definir uma variável USE para dizer ao <code>debian-sources</code> que construa um kernel "universal" e o initramfs para nós, para levar Funtoo Linux a funcionamento na inicialização. Para fazer isso, vamos configurar a variável <code>binary</code> USE para <code>debian-sources</code>, como a seguir:


<console>
<console>
###i## lxc-create -B btrfs -n vm1 -t debian
(chroot) # ##i##echo "sys-kernel/debian-sources binary" >> /etc/portage/package.use
debootstrap is /usr/bin/debootstrap
Checking cache download in /var/cache/lxc/debian/rootfs-wheezy-armhf ...
Copying rootfs to /var/lib/lxc/vm1/rootfs...Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
update-rc.d: using dependency based boot sequencing
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
invoke-rc.d: policy-rc.d denied execution of restart.
Timezone in container is not configured. Adjust it manually.
Root password is 'root', please change !
</console>
</console>


We will see that the lxc-create command created a subvolume on BTRFS backing file system (-B switch took care of this).
Se as varáveis USE forem novas para você, você estará se familiarizando com elas um pouco mais enquanto utiliza o Funtoo Linux. At their essence, ela são "switches" que você pode definir para configurar opções que podem ser construídas em vários pacotes. Elas são utilizadas para assim personalizar seu Funtoo Linux system para que conheça as suas exatas necessidades. We added support for a <code>binary</code> USE flag to the <code>debian-sources</code> ebuilds, as well as a few other of our kernel ebuilds, to make it easier for new users to get Funtoo Linux up and running.
<console>
###i## btrfs sub list /
---- snip ----
ID 1143 gen 437 top level 5 path var/lib/lxc/vm1/rootfs
---- snip ----
</console>


Now you are ready to do all the fun stuff with your LXCs.
Now, when we just want to update our system's packages, we'll type <code>emerge -auDN @world</code>, and it will update our world set, leaving out the kernel. Likewise, when we just want to update our kernel, we'll type <code>emerge -au @kernel</code>, and it will update our kernel, leaving out the world set.


== Starting/stoping containers ==
==== Building the Kernel ====
To start a previously created container use the lxc utils:


<console>
{{Fancynote|1=
###i## lxc-start -n vm1 -d
See [[Funtoo Linux Kernels]] for a full list of kernels supported in Funtoo Linux. We recommend <code>debian-sources</code> for new users.}}
###i## lxc-info -n vm1
Name:          vm1
State:          RUNNING
PID:            29742
IP:            172.16.65.234
CPU use:        2.92 seconds
BlkIO use:      260.00 KiB
Memory use:    2.99 MiB
KMem use:      0 bytes
Link:          vethTN4NGU
TX bytes:      2.33 KiB
RX bytes:      39.54 KiB
Total bytes:  41.87 KiB
###i## lxc-attach -n vm1
###r## root@vm1:~#
###r## root@vm1:~# exit
###i## lxc-stop -n vm1
Name:          vm1
State:          STOPPED
</console>


== Freezing/unfreezing containers ==
{{fancyimportant|1=
The command lxc-freeze freezes all the processes running inside the container.  The processes will be blocked until they are explicitly thawed by the lxc-unfreeze command. To freeze a previously started container use the lxc utils:
<code>debian-sources</code> with <code>binary</code> USE flag requires at least 14GB free in <code>/var/tmp</code> and takes around 1 hour to build on a Intel Core i7 Processor.}}


<console>
Let's emerge our kernel:
###i## lxc-freeze -n vm1
###i## lxc-info -n vm1
Name:          vm1
State:          FROZEN
PID:            6817
IP:            172.16.65.234
CPU use:        2.78 seconds
BlkIO use:      0 bytes
Memory use:    2.47 MiB
KMem use:      0 bytes
Link:          veth7E1J8R
TX bytes:      1.45 KiB
RX bytes:      3.85 KiB
Total bytes:  5.31 KiB
###i## lxc-unfreeze -n vm1
###i## lxc-info -n vm1
Name:          vm1
State:          RUNNING
PID:            6817
IP:            172.16.65.234
CPU use:        2.78 seconds
BlkIO use:      0 bytes
Memory use:    2.47 MiB
KMem use:      0 bytes
Link:          veth7E1J8R
TX bytes:     1.58 KiB
RX bytes:      11.13 KiB
Total bytes:  12.71 KiB
</console>
 
== Clones and snapshots  ==
Now the really nice features of LXC are snapshots of containers and also creating clones of containers. The command lxc-snapshot creates snapshot under /var/lib/lxcsnaps/ directory, this directory must also reside on a BTRFS filesystem. To snapshot a previously created container use the lxc utils:
 
<console>
###i## lxc-snapshot -n vm1
###i## lxc-snapshot -L -n vm1                                                                                                       
snap0 (/var/lib/lxcsnaps/vm1) 2014:11:15 14:01:18
###i## btrfs sub list /
--- snip ---
ID 1144 gen 448 top level 1136 path var/lib/lxcsnaps/vm1/snap0/rootfs
--- snip ---
</console>
 
You can also add comments (using a comment file and -c switch). Lets pretend something didn't go well after an upgrade. No big deal if you remembered to create a snapshot before the upgrade. Now you can restore the container to the last good state.


<console>
<console>
###i## btrfs sub list /
(chroot) # ##i##emerge -1 @kernel
--- snip ---
ID ''1143'' gen 437 top level 5 path var/lib/lxc/vm1/rootfs
ID 1144 gen 448 top level 1136 path var/lib/lxcsnaps/vm1/snap0/rootfs
--- snip ---
###i## lxc-snapshot -L -n vm1                                                                                                       
snap0 (/var/lib/lxcsnaps/vm1) 2014:11:15 14:01:18
###i## lxc-snapshot -n vm1 -r snap0
###i## lxc-snapshot -L -n vm1                                                                                                       
snap0 (/var/lib/lxcsnaps/vm1) 2014:11:15 14:01:18
###i## btrfs sub list /
--- snip ---
ID 1144 gen 448 top level 1136 path var/lib/lxcsnaps/vm1/snap0/rootfs
ID ''1147'' gen 453 top level 5 path var/lib/lxc/vm1/rootfs
--- snip ---
</console>
</console>


Notice the ID change in btrfs subvolume list command (ID in italics). BTRFS took care of the lxc-snapshot call and restored the snapshot contained in the lxcsnaps/vm1/snap0 directory.
{{Important|Right now, the <code>-1</code> option is required to not add our <code>@kernel</code> set to <code>world-sets</code>. This allows you to emerge it independently from @world. If you forget to use this option, edit <code>/var/lib/portage/world-sets</code> and remove the <code>@kernel</code> line. This will prevent kernel updates from being included in @world updates.}}


Now clones are containers that are exactly the same as the originating container. So for example you will configure a basic LAMP stack (LXC Apache Mariadb PHP) in one container and want to use different container for different websites. So after doing all the hard work of setting up LAMP you just clone the container using lxc tools.
Note that while use of the <code>binary</code> USE flag makes installing a working kernel extremely simple, it is one part of Funtoo Linux that takes a ''very'' long time to build from source, because it is building a kernel that supports ''all'' hardware that Linux supports! So, get the build started, and then let your machine compile. Slower machines can take up to several hours to build the kernel, and you'll want to make sure that you've set <code>MAKEOPTS</code> in <code>/etc/portage/make.conf</code> to the number of processing cores/threads (plus one) in your system before starting to build it as quickly as possible -- see the [[#/etc/portage/make.conf|/etc/portage/make.conf section]] if you forgot to do this.


<console>
{{fancynote|NVIDIA card users: the <code>binary</code> USE flag installs the Nouveau drivers which cannot be loaded at the same time as the proprietary drivers, and cannot be unloaded at runtime because of KMS. You need to blacklist it under <code>/etc/modprobe.d/</code>.}}
###i## btrfs sub list /
--- snip ---
ID 1144 gen 448 top level 1136 path var/lib/lxcsnaps/vm1/snap0/rootfs
ID 1147 gen 453 top level 5 path var/lib/lxc/vm1/rootfs
--- snip ---
###i## lxc-clone -B btrfs -s vm1 vm2
Created container vm2 as snapshot of vm1
###i## btrfs sub list /
--- snip ---
ID 1144 gen 448 top level 1136 path var/lib/lxcsnaps/vm1/snap0/rootfs
ID 1147 gen 455 top level 5 path var/lib/lxc/vm1/rootfs
ID 1148 gen 455 top level 5 path var/lib/lxc/vm2/rootfs
--- snip ---
</console>


== Summary ==
{{fancynote|For an overview of other kernel options for Funtoo Linux, see [[Funtoo Linux Kernels]]. There may be modules that the Debian kernel doesn't include, a situation where [http://www.funtoo.org/wiki/Funtoo_Linux_Kernels#Using_Debian-Sources_with_Genkernel genkernel] would be useful. Also be sure to see [[:Category:Hardware Compatibility|hardware compatibility]] information.}}
LXC is a very powerful virtualization technology, in Linux it is one one many to choose from and that is nice. LXC works off the host's existing vanilla kernel, thanks to functionality called cgroups that was merged into the Linux kernel v2.6.24. This allows operating system-level virtualization, and the ability to run multiple isolated Linux systems in "containers" -- a lightweight version of virtual machines (VM).


[[Category:Virtualization]]
Once <code>emerge</code> completes, you'll have a brand new kernel and initramfs installed to <code>/boot</code>, plus kernel headers installed in <code>/usr/src/linux</code>, and you'll be ready to configure the boot loader to load these to boot your Funtoo Linux system.

Revision as of 18:39, February 25, 2015

Configurando e instalando o kernel Linux

Agora é hora de construir e instalar um kernel Linux, o qual é o coração de qualquer sistema Funtoo Linux. O kernel é carregado pelo boot loader, e interfaces diretamente com o hardware do seu sistema, e permite programas regulares (userspace) serem executador.

Um kernel deve ser configurado propriamente para o hardware do seu sistema, desse modo ele suporta seus hard drives, file systems, placas de rede, e assim por diante. Usuários de Linux mais experientes pode escolher instalar o kernel sources e configurar e instalar seu próprio kernel. Se você não sabe como fazer isso, nós fornecemos ebuilds que construirão automaticamente um kernel "universal", módulos e initramfs para a inicialização do seu sistema que suporte todo o hardware. Esse é um jeito extremamente simples de construção de um kernel que colocará seu sistema para inicializar.

Qual é o nosso objetivo? Para construir um kernel que reconhecerá todo o hardware em seu sistema necessário para inicialização, você será cumprimentado por um prompt de login amigável depois que a instalação estiver completa. Esses instruções lhe guiarão através do processo de instalação de um kernel no modo "fácil" -- sem exigir configuração do usuário, ao utilizar um kernel "universal".

Package Sets

Antes que estalemos um kernel, vamos cobrir um recurso do Portage chamado package sets. Portage, o sistema gerenciador/ports de pacotes para o Funtoo Linux, manterá rastro de pacotes do sistema assim como pacotes que você tem instalado ao invocar emerge diretamente. Esses pacotes que são parte do sistema base são considerados parte do conjunto de pacote do "sistema", enquanto pacotes que você tem instalado ao digitá-los na linha de comando (tal qual "gnome" em emerge gnome) serão adicionados ao conjunto de pacote "world". Isso proporciona um jeito fácil de atualizar o sistema inteiro.

No entanto, as vezes é bom ser capaz de atualizar o kernel todo por sim só, ou deixar uma atualização do kernel fora da sua regular atualização completa do sistema. Para fazer isso, criaremo uma nova configuração de pacote chamada "kernel".

Configuração de Pacote do Kernel

Para criar a configuração de pacote do kernel, realize os seguintes passos:

(chroot) # mkdir /etc/portage/sets
(chroot) # echo sys-kernel/debian-sources > /etc/portage/sets/kernel

Agora, vamos querer definir uma variável USE para dizer ao debian-sources que construa um kernel "universal" e o initramfs para nós, para levar Funtoo Linux a funcionamento na inicialização. Para fazer isso, vamos configurar a variável binary USE para debian-sources, como a seguir:

(chroot) # echo "sys-kernel/debian-sources binary" >> /etc/portage/package.use

Se as varáveis USE forem novas para você, você estará se familiarizando com elas um pouco mais enquanto utiliza o Funtoo Linux. At their essence, ela são "switches" que você pode definir para configurar opções que podem ser construídas em vários pacotes. Elas são utilizadas para assim personalizar seu Funtoo Linux system para que conheça as suas exatas necessidades. We added support for a binary USE flag to the debian-sources ebuilds, as well as a few other of our kernel ebuilds, to make it easier for new users to get Funtoo Linux up and running.

Now, when we just want to update our system's packages, we'll type emerge -auDN @world, and it will update our world set, leaving out the kernel. Likewise, when we just want to update our kernel, we'll type emerge -au @kernel, and it will update our kernel, leaving out the world set.

Building the Kernel

   Note

See Funtoo Linux Kernels for a full list of kernels supported in Funtoo Linux. We recommend debian-sources for new users.

   Important

debian-sources with binary USE flag requires at least 14GB free in /var/tmp and takes around 1 hour to build on a Intel Core i7 Processor.

Let's emerge our kernel:

(chroot) # emerge -1 @kernel
   Important

Right now, the -1 option is required to not add our @kernel set to world-sets. This allows you to emerge it independently from @world. If you forget to use this option, edit /var/lib/portage/world-sets and remove the @kernel line. This will prevent kernel updates from being included in @world updates.

Note that while use of the binary USE flag makes installing a working kernel extremely simple, it is one part of Funtoo Linux that takes a very long time to build from source, because it is building a kernel that supports all hardware that Linux supports! So, get the build started, and then let your machine compile. Slower machines can take up to several hours to build the kernel, and you'll want to make sure that you've set MAKEOPTS in /etc/portage/make.conf to the number of processing cores/threads (plus one) in your system before starting to build it as quickly as possible -- see the /etc/portage/make.conf section if you forgot to do this.

   Note

NVIDIA card users: the binary USE flag installs the Nouveau drivers which cannot be loaded at the same time as the proprietary drivers, and cannot be unloaded at runtime because of KMS. You need to blacklist it under /etc/modprobe.d/.

   Note

For an overview of other kernel options for Funtoo Linux, see Funtoo Linux Kernels. There may be modules that the Debian kernel doesn't include, a situation where genkernel would be useful. Also be sure to see hardware compatibility information.

Once emerge completes, you'll have a brand new kernel and initramfs installed to /boot, plus kernel headers installed in /usr/src/linux, and you'll be ready to configure the boot loader to load these to boot your Funtoo Linux system.