Difference between pages "Welcome" and "LXC Fun"

(Difference between pages)
 
 
Line 1: Line 1:
<div class="container" style="font-family: Open Sans; font-size: 14px; line-height: 20px;"><div class="row"><div class="col-xs-12 col-md-8 col-lg-8">
+
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.
{{Slideshow}}
+
Want to submit a screenshot? [http://forums.funtoo.org/index.php?/topic/180-screenshots/ See here.]
+
</div><div class="col-xs-12 col-md-4 col-lg-4">
+
'''Funtoo Linux''' is a Linux-based operating system that is a variant of [http://www.gentoo.org Gentoo Linux], led by [[User:Drobbins|Daniel Robbins]], the creator and former Chief Architect of [http://en.wikipedia.org/wiki/Gentoo_Linux Gentoo Linux], who serves as benevolent dictator for life (BDFL) of the project. You are welcome to assist us in developing Funtoo Linux. Goals include developing production-ready technology, innovating and improving reliability and maintainability of the software, and most importantly, creating a fun, user-centric community for all.
+
  
<div class="bs-callout bs-callout-warning">
+
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'''.
[[Support Funtoo]] to help us grow! '''Donate $15 per month and get a free [[Funtoo Hosting|Funtoo Virtual Container]].'''
+
</div>
+
  
=== News ===
+
__TOC__
{{NewsList|1}}
+
[[News|View More News...]]
+
</div>
+
</div><div class="row">
+
<div class="col-xs-12 col-md-4 col-lg-4">
+
=== Resources ===
+
__NOTOC__
+
'''View the [[Funtoo Linux FAQ]] for answers to common questions.'''
+
  
{{#ask: [[Category:People]] [[Gravatar MD5::+]]
+
== Creating containers ==
| limit=22
+
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.
| order=random
+
| format=template
+
| template=GravatarDisplay
+
| link=none
+
| searchlabel=
+
}}
+
  
Join us - {{CreateAccount}}, and then add yourself to our [[Usermap]]!
+
So how do you create other containers? I am going to use a debian container for this purpose. You will have to emerge debootstrap.
  
'''Our resources:''' -- also see the <code>Go</code> menu:
+
<console>
* '''{{CreateAccount}}''' ([[Funtoo Authentication FAQ|Auth FAQ]])
+
###i## emerge -av debootstrap
* '''[http://forums.funtoo.org forums.funtoo.org]''' - our new forums!
+
* '''[http://bugs.funtoo.org bugs.funtoo.org]''', our bug tracker ([[Reporting Bugs|Instructions]]).
+
* [http://larrythecow.org larrythecow.org], Gentoo blog service.
+
* [http://kernel-seeds.org kernel-seeds.org], kernel build help.
+
* [http://git.funtoo.org git.funtoo.org], our cgit repository browser.
+
* '''[[Support Funtoo]]''' to help our project grow.
+
* '''[[Funtoo Hosting|Get a Funtoo Virtual Container]]'''.
+
  
'''Ebuild pages recently updated:''' {{#ask: [[Category:Ebuilds]]
+
* IMPORTANT: 8 news items need reading for repository 'gentoo'.
| order=descending
+
* Use eselect news to read news items.
| sort=Modification date
+
| format=list
+
| limit=10
+
| searchlabel=more...
+
}}
+
</div><div class="col-sm-12 col-xs-12 col-md-4 col-lg-4">
+
=== Getting Started ===
+
  
We encourage you to '''[[Funtoo Linux Installation|install Funtoo Linux]]''', and get involved in our user community. Get to know fellow Funtoo Linux users on our '''[http://forums.funtoo.org forums]'''. If you have any improvements or find any bugs in Funtoo Linux, you are strongly encouraged to report them on our '''[http://bugs.funtoo.org bug tracker]'''. We take all bugs seriously, and all work performed on Funtoo Linux is tracked on our bug tracker, for purposes of transparency.
 
  
Funtoo Linux has a very active [http://en.wikipedia.org/wiki/IRC IRC] community on Freenode, in the <code>#funtoo</code> channel, and you are encouraged to hang out online with us.
+
These are the packages that would be merged, in order:
  
=== Expand the wiki! ===
+
Calculating dependencies... done!
 +
[ebuild  N    ] dev-perl/TimeDate-2.300.0  31 kB
 +
[ebuild  N    ] app-arch/dpkg-1.17.10  USE="bzip2 lzma nls unicode update-alternatives zlib -dselect {-test}" 4,100 kB
 +
[ebuild  N    ] dev-util/debootstrap-1.0.59  96 kB
  
The [[:Help:Funtoo_Editing_Guidelines | How to 'wiki']] will help get you started on wiki editing. Have a look at [[Requested-Documents]] and [[:Category:Needs_Updates | pages that need to be updated.]]
+
Total: 3 packages (3 new), Size of downloads: 4,226 kB
  
See [[:Category:Ebuilds|Ebuilds]] for a list of all ebuild pages, and [[Adding an Ebuild to the Wiki]] for information on how to add one.
+
Would you like to merge these packages? [Yes/No]
 +
</console>
  
</div><div class="col-sm-12 col-xs-12 col-md-4 col-lg-4">
+
After installing debootstrap, you can create your debian container using:
=== Distinctives ===
+
  
Funtoo Linux packages are installed from source code, automatically, thanks to the [http://en.wikipedia.org/wiki/Portage_(software) Portage ports system], inspired by the FreeBSD ports system, but written in Python and with full advanced package management functionality. Funtoo Linux is a meta-distribution, which means it is built (fully automatically) with the functionality and optimizations that ''you'' want, not what some distro maintainer thought was best for you.
+
<console>
 +
###i## lxc-create -B btrfs -n vm1 -t debian
 +
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>
  
We use [http://en.wikipedia.org/wiki/Git_(software) Git] for all our development, and we also use Git to deliver our ports tree to you.
+
We will see that the lxc-create command created a subvolume on BTRFS backing file system.
 +
<console>
 +
###i## btrfs sub list /
 +
---- snip ----
 +
ID 1143 gen 437 top level 5 path /var/lib/lxc/vm1/rootfs
 +
---- snip ----
 +
</console>
  
In contrast to Gentoo Linux, we offer a number of innovations, including our extensive use of git, [[Funtoo 1.0 Profile|our profile system]], [[Package:Boot-Update|boot-update]] boot management tool, our incredibly flexible [[Funtoo Linux Networking|template-based networking scripts]], [[Metro Quick Start Tutorial|Metro]] distribution build system, support of Debian, RHEL and other kernels, [[Creating_Python-related_Ebuilds|enhanced Python support]], Portage mini-manifests, user-centric distribution model, and a large number of community infrastructure improvements.
+
Now you are ready to do all the fun stuff with your LXCs.
</div></div></div>
+
  
__NOTITLE__
+
== Starting/stoping containers ==
__NOEDITSECTION__
+
To start a previously created container use the lxc utils:
{{#subobject:|slideIndex=0|slideCaption=
+
== [[User:Drobbins|drobbins]] ==
+
  
[[GNOME First Steps|GNOME 3.12]]
+
<console>
([[Funtoo_Linux_FAQ#Do_you_support_systemd.3F|without systemd]], because that's how we roll.)
+
###i## lxc-start -n vm1 -d
 +
###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>
  
Note: Badgers optional.
+
== Freezing/unfreezing containers ==
|slideImage=File:gnome3122.jpg|slideLink=GNOME First Steps}}
+
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:
{{#subobject:|slideIndex=1|slideCaption=
+
== [[User:Anak1n|anak1n]] ==
+
  
flux box
+
<console>
|slideImage=File:fluxbox-09.02.14.jpg}}
+
###i## lxc-freeze -n vm1
{{#subobject:|slideIndex=2|slideCaption=
+
###i## lxc-info -n vm1
== spectromas ==
+
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>
  
[[Package:Awesome_(Window_Manager)|Awesome WM]]
+
== Clones and snapshots  ==
|slideImage=File:awesome.jpg|slideLink=Package:Awesome (Window Manager)}}
+
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:
{{#subobject:|slideIndex=3|slideCaption=
+
== [[User:Anak1n|anak1n]] ==
+
  
KDE
+
<console>
|slideImage=File:anak1n-kde.jpg}}
+
###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. Now you can restore the container to the last good state.
 +
 
 +
<console>
 +
###i## btrfs sub list /
 +
--- 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>
 +
 
 +
Notice the ID change in btrfs subvolume list command. BTRFS took care of the lxc-snapshot call and restored the snapshot contained in the lxcsnaps/vm1/snap0 directory.
 +
 
 +
[[Category:Virtualization]]

Revision as of 13:24, November 15, 2014

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.

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.

Creating containers

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 purpose. You will have to emerge debootstrap.

# emerge -av debootstrap

 * IMPORTANT: 8 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.


These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] dev-perl/TimeDate-2.300.0  31 kB
[ebuild  N     ] app-arch/dpkg-1.17.10  USE="bzip2 lzma nls unicode update-alternatives zlib -dselect {-test}" 4,100 kB
[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]

After installing debootstrap, you can create your debian container using:

# lxc-create -B btrfs -n vm1 -t debian
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 !

We will see that the lxc-create command created a subvolume on BTRFS backing file system.

# btrfs sub list /
---- snip ----
ID 1143 gen 437 top level 5 path /var/lib/lxc/vm1/rootfs
---- snip ----

Now you are ready to do all the fun stuff with your LXCs.

Starting/stoping containers

To start a previously created container use the lxc utils:

# lxc-start -n vm1 -d
# 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
# lxc-attach -n vm1
# root@vm1:~#
# root@vm1:~# exit
# lxc-stop -n vm1
Name:           vm1
State:          STOPPED

Freezing/unfreezing containers

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:

# lxc-freeze -n vm1
# 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
# lxc-unfreeze -n vm1
# 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

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:

# lxc-snapshot -n vm1
# lxc-snapshot -L -n vm1                                                                                                         
snap0 (/var/lib/lxcsnaps/vm1) 2014:11:15 14:01:18
# btrfs sub list /
--- snip ---
ID 1144 gen 448 top level 1136 path var/lib/lxcsnaps/vm1/snap0/rootfs
--- snip ---

You can also add comments (using a comment file and -c switch). Lets pretend something didn't go well after an upgrade. Now you can restore the container to the last good state.

# btrfs sub list /
--- 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 ---
# lxc-snapshot -L -n vm1                                                                                                         
snap0 (/var/lib/lxcsnaps/vm1) 2014:11:15 14:01:18
# lxc-snapshot -n vm1 -r snap0
# lxc-snapshot -L -n vm1                                                                                                         
snap0 (/var/lib/lxcsnaps/vm1) 2014:11:15 14:01:18
# 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 ---

Notice the ID change in btrfs subvolume list command. BTRFS took care of the lxc-snapshot call and restored the snapshot contained in the lxcsnaps/vm1/snap0 directory.