Difference between pages "Linux Containers" and "I3 Tiling Window Manager"

From Funtoo
(Difference between pages)
Jump to: navigation, search
 
 
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.  
+
== Introduction ==
 +
i3 is a tiling window manager that is based upon experiences the developers shared while attempting to fix/hack wmii.  i3 has the ability for either floating windows, which you can resize and move, and tiling windows.  i3 uses a tree as a data structure to allow for more flexibility.  i3 defaults with home-row key-bindings which are quick and easy to get beginners off the ground.
  
== Status ==
+
'''NOTE:  This wiki is made following the steps produced to get a working i3 using xrandr instead of xinerama, ATI proprietary drivers instead of radeon drivers, a dual-monitor setup, and no login manager.  For Nvidia and Twinview users, a link is supplied in [[#X11 and xrandr|X11 and xrandr]].  Xinerama was initially used and worked in the dual-monitor setup so it possible to substitute xinerama for xrandr with minimal changes.''' 
  
As of Linux kernel 3.1.5, LXC is usable for isolating your own private workloads from one another. It is not yet ready to isolate potentially malicious users from one another or the host system. For a more mature containers solution that is appropriate for hosting environments, see [[OpenVZ]].
+
== Installation ==
  
LXC containers don't yet have their own system uptime, and they see everything that's in the host's <tt>dmesg</tt> output, among other things. But in general, the technology works.
+
=== Portage ===
  
== Basic Info ==
+
The easiest and quickest way:
 +
<console>
 +
###i## emerge -avt x11-wm/i3
 +
</console>
  
 +
=== Manual ===
  
* Linux Containers are based on:
+
==== Tarball ====
** Kernel namespaces for resource isolation
+
** CGroups for resource limitation and accounting
+
  
{{Package|app-emulation/lxc}} is the userspace tool for Linux containers
+
Download the latest version from the i3 website.
 +
[http://i3wm.org/downloads/i3-4.1.1.tar.bz2 i3-4.1.1]
  
== Control groups ==
+
<console>
 +
###i## cd /PATH/TO/TARBALL
 +
###i## make
 +
###i## sudo make install
 +
</console>
  
* Control groups (cgroups) in kernel since 2.6.24
+
==== Git ====
** Allows aggregation of tasks and their children
+
** Subsystems (cpuset, memory, blkio,...)
+
** accounting - to measure how much resources certain systems use
+
** resource limiting - groups can be set to not exceed a set memory limit
+
** prioritization - some groups may get a larger share of CPU
+
** control - freezing/unfreezing of cgroups, checkpointing and restarting
+
** No disk quota limitation ( -> image file, LVM, XFS, directory tree quota,...)
+
  
== Subsystems ==
 
<br>
 
 
<console>
 
<console>
###i## cat /proc/cgroups
+
###i## git clone git://code.i3wm.org/i3
subsys_name hierarchy num_cgroups enabled
+
###i## cd i3
cpuset
+
###i## make
cpu
+
###i## sudo make install
cpuacct
+
memory
+
devices
+
freezer
+
blkio
+
perf_event
+
hugetlb
+
 
</console>
 
</console>
  
#cpuset    -> limits tasks to specific CPU/CPUs
+
== Setup ==
#cpu        -> CPU shares
+
#cpuacct    -> CPU accounting
+
#memory    -> memory and swap limitation and accounting
+
#devices    -> device allow deny list
+
#freezer    -> suspend/resume tasks
+
#blkio      -> I/O priorization (weight, throttle, ...)
+
#perf_event -> support for per-cpu per-cgroup monitoring [http://lwn.net/Articles/421574/ perf_events]
+
#hugetlb    -> cgroup resource controller for HugeTLB pages  [http://lwn.net/Articles/499255/ hugetlb]
+
  
== Configuring the Funtoo Host System ==
+
=== xinitrc ===
  
=== Install LXC kernel ===
+
Edit <tt>~/.xinitrc</tt>:
Any kernel beyond 3.1.5 will probably work. Personally I prefer {{Package|sys-kernel/gentoo-sources}} as these have support for all the namespaces without sacrificing the xfs, FUSE or NFS support for example. These checks were introduced later starting from kernel 3.5, this could also mean that the user namespace is not working optimally.
+
  
* User namespace (EXPERIMENTAL) depends on EXPERIMENTAL and on UIDGID_CONVERTED
+
<pre>
** config UIDGID_CONVERTED
+
exec i3
*** True if all of the selected software components are known to have uid_t and gid_t converted to kuid_t and kgid_t where appropriate and are otherwise safe to use with the user namespace.
+
</pre>
**** Networking - depends on NET_9P = n
+
**** Filesystems - 9P_FS = n, AFS_FS = n, AUTOFS4_FS = n, CEPH_FS = n, CIFS = n, CODA_FS = n, FUSE_FS = n, GFS2_FS = n, NCP_FS = n, NFSD = n, NFS_FS = n, OCFS2_FS = n, XFS_FS = n
+
**** Security options - Grsecurity - GRKERNSEC = n (if applicable)
+
  
** As of 3.10.xx kernel, all of the above options are safe to use with User namespaces, except for XFS_FS, therefore with kernel >=3.10.xx, you should answer XFS_FS = n, if you want User namespaces support.
 
** in your kernel source directory, you should check init/Kconfig and find out what UIDGID_CONVERTED depends on
 
  
==== Kernel configuration ====
+
For i3 logging, edit <tt>~/.xinitrc</tt>:
These options should be enable in your kernel to be able to take full advantage of LXC.
+
  
* General setup
+
<pre>
** CONFIG_NAMESPACES
+
exec i3 -V -d all >~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1
*** CONFIG_UTS_NS
+
</pre>
*** CONFIG_IPC_NS
+
*** CONFIG_PID_NS
+
*** CONFIG_NET_NS
+
*** CONFIG_USER_NS
+
** CONFIG_CGROUPS
+
*** CONFIG_CGROUP_DEVICE
+
*** CONFIG_CGROUP_SCHED
+
*** CONFIG_CGROUP_CPUACCT
+
*** CONFIG_CGROUP_MEM_RES_CTLR (in 3.6+ kernels it's called CONFIG_MEMCG)
+
*** CONFIG_CGROUP_MEM_RES_CTLR_SWAP (in 3.6+ kernels it's called CONFIG_MEMCG_SWAP)
+
*** CONFIG_CPUSETS (on multiprocessor hosts)
+
* Networking support
+
** Networking options
+
*** CONFIG_VLAN_8021Q
+
* Device Drivers
+
** Character devices
+
*** Unix98 PTY support
+
**** CONFIG_DEVPTS_MULTIPLE_INSTANCES
+
** Network device support
+
*** Network core driver support
+
**** CONFIG_VETH
+
**** CONFIG_MACVLAN
+
  
Once you have lxc installed, you can then check your kernel config with:
+
If you are using Nvidia or for some reason don't use xrandr, edit ~/.xinitrc
<console>
+
<pre style="color:green">exec i3 --force-xinerama</pre>
# ##i##CONFIG=/path/to/config /usr/sbin/lxc-checkconfig
+
and nvidia with logging:
</console>
+
<pre style="color:green">exec i3 --force-xinerama -V -d all >~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1</pre>
 +
Example ~/.xinitrc that uses consolekit and dbus in launch and also logs on exit.
 +
<pre style="color:purple">#!/bin/zsh
 +
xrdb -merge ~/.Xresources
 +
xcompmgr &
  
=== Emerge lxc ===
+
if [[ $1 == "i3" ]]; then
<console>
+
    exec ck-launch-session dbus-launch --sh-syntax --exit-with-session i3 -V -d all > ~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1
# ##i##emerge app-emulation/lxc
+
elif [[ $1 == "razor" ]]; then
</console>
+
    exec ck-launch-session dbus-launch startrazor
 +
elif [[ $1 == "awesome" ]]; then
 +
    exec ck-launch-session dbus-launch awesome
 +
elif [[ $1 == "qtile" ]]; then
 +
    exec ck-launch-session dbus-launch ~/.qtile-session
 +
else
 +
    echo "Choose a window manager"
 +
fi</pre>
  
=== Configure Networking For Container ===
+
<div id="X11 and xrandr"></div>
  
Typically, one uses a bridge to allow containers to connect to the network. This is how to do it under Funtoo Linux:
+
=== X11 and xrandr ===
  
# create a bridge using the Funtoo network configuration scripts. Name the bridge something like <tt>brwan</tt> (using <tt>/etc/init.d/netif.brwan</tt>). Configure your bridge to have an IP address.
+
=== X and RandR ===
# Make your physical interface, such as <tt>eth0</tt>, an interface with no IP address (use the Funtoo <tt>interface-noip</tt> template.)
+
'''NOTE: RandR and Xinerama do not play together. Use one or the other.'''
# Make <tt>netif.eth0</tt> a slave of <tt>netif.brwan</tt> in <tt>/etc/conf.d/netif.brwan</tt>.
+
# Enable your new bridged network and make sure it is functioning properly on the host.
+
  
You will now be able to configure LXC to automatically add your container's virtual ethernet interface to the bridge when it starts, which will connect it to your network.
+
I use an AMD HD 6870 with 3 monitors (2 DVI and 1 with an AMD validated Mini DisplayPort™ to DVI dongle).
  
== Setting up a Funtoo Linux LXC Container ==
+
Install xrandr:
 +
<pre style="color:green"># emerge x11-apps/xrandr</pre>
 +
and if you want a GUI with xrandr:
 +
<pre style="color:green"># emerge x11-misc/arandr</pre>
  
Here are the steps required to get Funtoo Linux running <i>inside</i> a container. The steps below show you how to set up a container using an existing Funtoo Linux OpenVZ template. It is now also possible to use [[Metro]] to build an lxc container tarball directly, which will save you manual configuration steps and will provide an <tt>/etc/fstab.lxc</tt> file that you can use for your host container config. See [[Metro Recipes]] for info on how to use Metro to generate an lxc container.
+
If you do not have X configured yet, follow the link on the [http://en.gentoo-wiki.com/wiki/X.Org Gentoo Wiki]
  
=== Create and Configure Container Filesystem ===
+
My xorg.conf.d folder for example: [https://github.com/akiress/dotfiles/blob/master/etc/X11/xorg.conf.d/30-screen.conf 30-screen.conf]
  
# Start with a Funtoo LXC template, and unpack it to a directory such as <tt>/lxc/funtoo0/rootfs/</tt>
+
Since the names of the monitors are already known in xrandr, I just use those names in my 30-screen.conf configuration. It doesn't matter what you use in your X configuration however.
# Create an empty <tt>/lxc/funtoo0/fstab</tt> file
+
# Ensure <tt>c1</tt> line is uncommented (enabled) and <tt>c2</tt> through <tt>c6</tt> lines are disabled in <tt>/lxc/funtoo0/rootfs/etc/inittab</tt>
+
  
That's almost all you need to get the container filesystem ready to start.
+
Once you have X configured however you like, start qtile with either:
 +
<pre style="color:green"># startx</pre>
 +
or, in a case similar to mine,
 +
<pre style="color:green"># xinit qtile</pre>
  
=== Create Container Configuration Files ===
+
=== i3 config ===
 +
The i3 configuration file can be found in /etc/i3/config, but I suggest that you copy the file into a local ~/.i3 directory.
 +
<pre># mkdir -p ~/.i3 && cp /etc/i3/config ~/.i3/config</pre>
 +
Open up ~/i3/config in your editor of choice.
 +
<code style="color:green">set $mod Mod1</code> assigns the variable $mod to be Mod1.  In i3, Mod1 is the Alt key.  If you wish to use the Windows key then use <code style="color:green">set $mod Mod4</code>  In the keybinding section, $mod is used in place of Mod1 in the case that you do wish to change the modifier.  In the workspace key, the keybindings are set with Mod1 instead of the variable, so remember to change those bindings manually if you are replacing the Mod1 modifier.  Else you can change Mod1 in those sections to $mod and change all the keybindings at the same time by setting the $mod variable.
 +
<pre style="color:green">set $mod Mod1</pre>
 +
To have programs start automatically in i3, use the command <code style="color:green">exec APPLICATION</code>.  This is the section that the xrandr screen layout bash file created earlier will be placed.  The i3bar is a tray and status bar combination.  If you have applications that run in the system tray that you want to autostart, call those applications with exec.
 +
<pre style="color:green">exec /PATH/TO/XRANDR-BASH-FILE
 +
exec NAME OF BROWSER
 +
exec NAME OF EDITOR
 +
exec volumeicon
 +
exec dropbox</pre>
 +
In the workspace section, you have the opportunity to name the workspaces by setting either the number of the workspace, the name of the workspace, or the number and name of the workspace.  <code style="color:green">bindsym KEYBIND workspace NAME/NUMBER OF WORKSPACE</code>.  Remember to use quotes when naming a workspace.
 +
<pre style="color:green">bindsym Mod1+1 workspace 1
 +
bindsym Mod1+1 workspace "my first workspace"
 +
bindsym Mod1+1 workspace "1: my first workspace"</pre>
 +
To assign a workspace to a certain output you will need the output from running xrandr again if you do not remember which connections are being used.  In the example from [#X11 and xrandr|X11 and xrandr], the connected outputs are DFP3 and DFP4.  To assign the workspace, you need to add <code style="color:green">workspace NAME OF WORKSPACE or NUMBER output CONNECTED OUTPUT</code>.  There are several types of outputs so make sure that you are using the connected outputs from xrandr when assigning workspaces, else the workspace will not show up.
 +
<pre style="color:green">workspace 1 output DFP3
 +
workspace "my first workspace" output DFP3
 +
workspace "1: my first workspace" output DFP3
 +
workspace "2: my second workspace" output DFP4</pre>
 +
To assign a program to a certain workspace, you will need to run xprop.  If you do not have xprop, emerge it.
 +
<pre># emerge -avt x11-apps/xprop</pre>
 +
To run xprop, open a terminal and run <pre># xprop</pre>  Your mouse cursor should become a crosshair and you will want to mouse over the window that contains the running application.  Click on that window and xprop will then output the window information.  The easiest way to assign a program is to look for <pre style="color:green">WM_CLASS(STRING) = "INSTANCE", "CLASS"</pre>  Be sure to note that the window INSTANCE is before the window CLASS.  In the config file, add <code style="color:green">assign [class="^INSTANCE$" instance="^CLASS$] NAME OF WORKSPACE</code>.  For aesthetic purposes, you can add → before NAME OF WORKSPACE, but mind that the → is a UTF-8 character and not <code>-></code>.  For the assignments, do not put the workspace name within quotes as you do when naming them and setting their output.
 +
<pre style="color:green">
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] 1
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] web
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] 1: web
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → web
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1: web</pre>
 +
For aesthetic purposes, their are three types of borders for the windows.  This can be set by adding <code style="color:green">new_window <normal|1pixel|none></code>.  There are also keybindings that allow you to switch between the 3 border styles.
 +
<pre style="color:green">new_window 1pixel
 +
bindsym $mod+t border normal
 +
bindsym $mod+y border 1pixel
 +
bindsym $mod+u border none</pre>
 +
The orientation for new workspaces can be set by adding <code style="color:green">default_orientation <horizontal|vertical|auto></code>
 +
<pre style="color:green">default_orientation horizontal</pre>
  
Create the following files:
+
A sample ~/.i3/config:
 +
<div style="height:250px;overflow:scroll;color:green"><pre>
 +
set $mod Mod1
  
==== <tt>/lxc/funtoo0/config</tt> ====
+
########################################################
 +
######## Autostart ########
 +
########################################################
 +
exec ~/.screenlayout/dualdtop.sh
 +
exec chromium-browser
 +
exec gvim
 +
exec volumeicon
 +
exec parcellite
 +
exec dropbox
  
 +
########################################################
 +
######## Workspaces ########
 +
########################################################
 +
# switch to workspace
 +
bindsym Mod1+1 workspace "1: web"
 +
bindsym Mod1+2 workspace "2: irc"
 +
bindsym Mod1+3 workspace "3: gvim"
 +
bindsym Mod1+4 workspace "4: ranger"
 +
bindsym Mod1+5 workspace "5: terms"
 +
bindsym Mod1+6 workspace "6: mplayer"
 +
bindsym Mod1+7 workspace "7: mail"
 +
bindsym Mod1+8 workspace "8: firefox"
 +
bindsym Mod1+9 workspace "9: music"
 +
bindsym Mod1+0 workspace "10: office"
  
and also create symlink from
+
## Output certain workspaces
==== <tt> /lxc/funtoo0/config to /etc/lxc/funtoo0.conf </tt> ====
+
workspace "1: web" output DFP3
<console>
+
workspace "2: irc" output DFP4
###i## ln -s /lxc/funtoo0/config /etc/lxc/funtoo0.conf
+
workspace "3: gvim" output DFP4
</console>
+
workspace "4: ranger" output DFP3
 +
workspace "5: terms" output DFP4
 +
workspace "6: mplayer" output DFP3
 +
workspace "7: mail" output DFP3
 +
workspace "8: firefox" output DFP3
 +
workspace "9: music" output DFP3
 +
workspace "10: office" output DFP4
  
{{Fancynote| Daniel Robbins needs to update this config to be more in line with http://wiki.progress-linux.org/software/lxc/ -- this config appears to have nice, refined device node permissions and other goodies. // note by Havis to Daniel, this config is already superior.}}
+
## Assign workspaces to programs
 +
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1: web
 +
assign [class="^Gvim$" instance="^gvim$"] → 3: gvim
 +
assign [class="^MPlayer$" instance="^gl$"] → 6: mplayer
 +
assign [class="^Firefox$" instance="^Navigator$"] → 8: firefox
 +
assign [class="^Emacs$" instance="^emacs$"] → 9: emacs
 +
assign [class="^libreoffice-startcenter$" instance="^VCLSalFrame.DocumentWindow$"] 10: office
  
 +
# move focused container to workspace
 +
bindsym Mod1+Shift+1 move workspace 1
 +
bindsym Mod1+Shift+2 move workspace 2
 +
bindsym Mod1+Shift+3 move workspace 3
 +
bindsym Mod1+Shift+4 move workspace 4
 +
bindsym Mod1+Shift+5 move workspace 5
 +
bindsym Mod1+Shift+6 move workspace 6
 +
bindsym Mod1+Shift+7 move workspace 7
 +
bindsym Mod1+Shift+8 move workspace 8
 +
bindsym Mod1+Shift+9 move workspace 9
 +
bindsym Mod1+Shift+0 move workspace 10
  
Read "man 5 lxc.conf" , to get more information about linux container configuration file.
+
########################################################
<pre>
+
######## Aesthetics ########
## Container
+
########################################################
lxc.utsname                            = funtoo0
+
# Window border style: normal: border normal, with window title bar;
lxc.rootfs                              = /lxc/funtoo0/rootfs/
+
# none: no border or window title bar; 1pixel: 1 pixel border.
lxc.arch                                = x86_64
+
new_window 1pixel
#lxc.console                            = /var/log/lxc/funtoo0.console  # uncomment if you want to log containers console
+
bindsym $mod+t border normal
lxc.tty                                = 6  # if you plan to use container with physical terminals (eg F1..F6)
+
bindsym $mod+y border 1pixel
#lxc.tty                                = 0  # set to 0 if you dont plan to use the container with physical terminal, also comment out in your containers /etc/inittab  c1 to c6 respawns (e.g. c1:12345:respawn:/sbin/agetty 38400 tty1 linux)
+
bindsym $mod+u border none
lxc.pts                                = 1024
+
  
 +
# font for window titles. ISO 10646 = Unicode
 +
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
  
## Capabilities
+
# Orientation for new workspaces
lxc.cap.drop                            = audit_control
+
# Can be set <horizontal|vertical|auto>
lxc.cap.drop                            = audit_write
+
default_orientation horizontal
lxc.cap.drop                            = mac_admin
+
lxc.cap.drop                            = mac_override
+
lxc.cap.drop                            = mknod
+
lxc.cap.drop                            = setfcap
+
lxc.cap.drop                            = setpcap
+
lxc.cap.drop                            = sys_admin
+
lxc.cap.drop                            = sys_boot
+
#lxc.cap.drop                            = sys_chroot # required by SSH
+
lxc.cap.drop                            = sys_module
+
#lxc.cap.drop                            = sys_nice
+
lxc.cap.drop                            = sys_pacct
+
lxc.cap.drop                            = sys_rawio
+
lxc.cap.drop                            = sys_resource
+
lxc.cap.drop                            = sys_time
+
#lxc.cap.drop                            = sys_tty_config # required by getty
+
  
## Devices
+
# Layout for new containers
#lxc.cgroup.devices.allow              = a # Allow access to all devices
+
# Can be set <default|stacking|tabbed>
lxc.cgroup.devices.deny                = a # Deny access to all devices
+
workspace_layout default
  
# Allow to mknod all devices (but not using them)
+
# Use Mouse+$mod to drag floating windows to their wanted position
lxc.cgroup.devices.allow                = c *:* m
+
floating_modifier $mod
lxc.cgroup.devices.allow                = b *:* m
+
  
lxc.cgroup.devices.allow                = c 1:3 rwm # /dev/null
+
########################################################
lxc.cgroup.devices.allow                = c 1:5 rwm # /dev/zero
+
######## Keybindings ########
lxc.cgroup.devices.allow                = c 1:8 rwm # /dev/random
+
########################################################
lxc.cgroup.devices.allow                = c 1:9 rwm # /dev/urandom
+
#lxc.cgroup.devices.allow                = c 4:0 rwm # /dev/tty0 ttys not required if you have lxc.tty = 0
+
#lxc.cgroup.devices.allow                = c 4:1 rwm # /dev/tty1 devices with major number 4 are "real" tty devices
+
#lxc.cgroup.devices.allow                = c 4:2 rwm # /dev/tty2
+
#lxc.cgroup.devices.allow                = c 4:3 rwm # /dev/tty3
+
lxc.cgroup.devices.allow                = c 5:0 rwm # /dev/tty
+
lxc.cgroup.devices.allow                = c 5:1 rwm # /dev/console
+
lxc.cgroup.devices.allow                = c 5:2 rwm # /dev/ptmx
+
lxc.cgroup.devices.allow                = c 10:229 rwm # /dev/fuse
+
lxc.cgroup.devices.allow                = c 136:* rwm # /dev/pts/* devices with major number 136 are pts
+
lxc.cgroup.devices.allow                = c 254:0 rwm # /dev/rtc0
+
  
## Limits#
+
# start a terminal
lxc.cgroup.cpu.shares                  = 1024
+
bindsym $mod+Return exec i3-sensible-terminal
lxc.cgroup.cpuset.cpus                = 0        # limits container to CPU0
+
lxc.cgroup.memory.limit_in_bytes      = 512M
+
lxc.cgroup.memory.memsw.limit_in_bytes = 1G
+
#lxc.cgroup.blkio.weight                = 500      # requires cfq block scheduler
+
  
## Filesystem
+
# kill focused window
#containers fstab should be outside it's rootfs dir (e.g. /lxc/funtoo0/fstab is ok, but /lxc/funtoo0/rootfs/etc/fstab is wrong!!!)
+
bindsym $mod+Shift+Q kill
#lxc.mount                              = /lxc/funtoo0/fstab     
+
  
#lxc.mount.entry is prefered, because it supports relative paths
+
# start dmenu (a program launcher)
lxc.mount.entry                        = proc proc proc nosuid,nodev,noexec  0 0
+
bindsym $mod+d exec dmenu_run
lxc.mount.entry                        = sysfs sys sysfs nosuid,nodev,noexec,ro 0 0
+
lxc.mount.entry                        = devpts dev/pts devpts nosuid,noexec,mode=0620,ptmxmode=000,newinstance 0 0
+
lxc.mount.entry                        = tmpfs dev/shm tmpfs nosuid,nodev,mode=1777 0 0
+
lxc.mount.entry                        = tmpfs run tmpfs nosuid,nodev,noexec,mode=0755,size=128m 0 0
+
lxc.mount.entry                        = tmpfs tmp tmpfs nosuid,nodev,noexec,mode=1777,size=1g 0 0
+
  
##Example of having /var/tmp/portage as tmpfs in container
+
# change focus
#lxc.mount.entry                        = tmpfs var/tmp/portage tmpfs defaults,size=8g,uid=250,gid=250,mode=0775 0 0
+
bindsym $mod+j focus left
##Example of bind mount
+
bindsym $mod+k focus down
#lxc.mount.entry                        = /srv/funtoo0 /lxc/funtoo0/rootfs/srv/funtoo0 none defaults,bind 0 0
+
bindsym $mod+l focus up
 +
bindsym $mod+semicolon focus right
  
## Network
+
# alternatively, you can use the cursor keys:
lxc.network.type                        = veth
+
bindsym $mod+Left focus left
lxc.network.flags                      = up
+
bindsym $mod+Down focus down
lxc.network.hwaddr                      = #put your MAC address here, otherwise you will get a random one
+
bindsym $mod+Up focus up
lxc.network.link                        = br0
+
bindsym $mod+Right focus right
lxc.network.name                        = eth0
+
#lxc.network.veth.pair                  = veth-example
+
</pre>
+
  
Read "man 7 capabilities" to get more information aboout Linux capabilities.
+
# move focused window
 +
bindsym $mod+Shift+J move left
 +
bindsym $mod+Shift+K move down
 +
bindsym $mod+Shift+L move up
 +
bindsym $mod+Shift+colon move right
  
Above, use the following command to generate a random MAC for <tt>lxc.network.hwaddr</tt>:
+
# alternatively, you can use the cursor keys:
 +
bindsym $mod+Shift+Left move left
 +
bindsym $mod+Shift+Down move down
 +
bindsym $mod+Shift+Up move up
 +
bindsym $mod+Shift+Right move right
  
<console>
+
# split in horizontal orientation
###i## openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//'
+
bindsym $mod+h split h
</console>
+
  
It is a very good idea to assign a static MAC address to your container using <tt>lxc.network.hwaddr</tt>. If you don't, LXC will auto-generate a new random MAC every time your container starts, which may confuse network equipment that expects MAC addresses to remain constant.
+
# split in vertical orientation
 +
bindsym $mod+v split v
  
It might happen from case to case that you aren't able to start your LXC Container with the above generated MAC address so for all these who run into that problem here is a little script that connects your IP for the container with the MAC address. Just save the following code as <tt>/etc/lxc/hwaddr.sh</tt>, make it executable and run it like <tt>/etc/lxc/hwaddr.sh xxx.xxx.xxx.xxx</tt> where xxx.xxx.xxx.xxx represents your Container IP. <br><tt>/etc/lxc/hwaddr.sh</tt>:
+
# enter fullscreen mode for the focused container
 +
bindsym $mod+f fullscreen
  
<pre>
+
# change container layout (stacked, tabbed, default)
#!/bin/sh
+
bindsym $mod+s layout stacking
IP=$*
+
bindsym $mod+w layout tabbed
HA=`printf "02:00:%x:%x:%x:%x" ${IP//./ }`
+
bindsym $mod+e layout default
echo $HA
+
</pre>
+
  
==== <tt>/lxc/funtoo0/fstab</tt> ====
+
# toggle tiling / floating
{{fancynote| It is now preferable to have mount entries directly in config file instead of separate fstab:}}
+
bindsym $mod+Shift+space floating toggle
Edit the file <tt>/lxc/funtoo0/fstab</tt>:
+
<pre>
+
none /lxc/funtoo0/dev/pts devpts defaults 0 0
+
none /lxc/funtoo0/proc proc defaults 0 0
+
none /lxc/funtoo0/sys sysfs defaults 0 0
+
none /lxc/funtoo0/dev/shm tmpfs nodev,nosuid,noexec,mode=1777,rw 0 0
+
</pre>
+
  
== LXC Networking ==
+
# change focus between tiling / floating windows
*veth - Virtual Ethernet (bridge)
+
bindsym $mod+space focus mode_toggle
*vlan - vlan interface (requires device able to do vlan tagging)
+
*macvlan (mac-address based virtual lan tagging) has 3 modes:
+
**private
+
**vepa (Virtual Ethernet Port Aggregator)
+
**bridge
+
*phys - dedicated host NIC
+
[https://blog.flameeyes.eu/2010/09/linux-containers-and-networking Linux Containers and Networking]
+
  
Enable routing on the host:
+
# focus the parent container
By default Linux workstations and servers have IPv4 forwarding disabled.
+
bindsym $mod+a focus parent
<console>
+
###i## echo "1" > /proc/sys/net/ipv4/ip_forward
+
###i## cat /proc/sys/net/ipv4/ip_forward
+
# 1
+
</console>
+
  
== Initializing and Starting the Container ==
+
# focus the child container
 +
#bindcode $mod+d focus child
  
You will probably need to set the root password for the container before you can log in. You can use chroot to do this quickly:
+
# reload the configuration file
 +
bindsym $mod+Shift+C reload
 +
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
 +
bindsym $mod+Shift+R restart
 +
# exit i3 (logs you out of your X session)
 +
bindsym $mod+Shift+E exit
  
<console>
+
# resize window (you can also use the mouse for that)
###i## chroot /lxc/funtoo0/rootfs
+
mode "resize" {
(chroot) ###i## passwd
+
        # These bindings trigger as soon as you enter the resize mode
New password: XXXXXXXX
+
        # They resize the border in the direction you pressed, e.g.
Retype new password: XXXXXXXX
+
        # when pressing left, the window is resized so that it has
passwd: password updated successfully
+
        # more space on its left
(chroot) ###i## exit
+
</console>
+
  
Now that the root password is set, run:
+
bindsym j resize shrink left 10 px or 10 ppt
 +
bindsym Shift+J resize grow left 10 px or 10 ppt
  
<console>
+
bindsym k resize shrink down 10 px or 10 ppt
###i## lxc-start -n funtoo0 -d
+
bindsym Shift+K resize grow down 10 px or 10 ppt
</console>
+
  
The <tt>-d</tt> option will cause it to run in the background.
+
bindsym l resize shrink up 10 px or 10 ppt
 +
bindsym Shift+L resize grow up 10 px or 10 ppt
  
To attach to the console:
+
bindsym semicolon resize shrink right 10 px or 10 ppt
 +
bindsym Shift+colon resize grow right 10 px or 10 ppt
  
<console>
+
        # same bindings, but for the arrow keys
###i## lxc-console -n funtoo0
+
bindsym Left resize shrink left 10 px or 10 ppt
</console>
+
bindsym Shift+Left resize grow left 10 px or 10 ppt
  
You should now be able to log in and use the container. In addition, the container should now be accessible on the network.
+
bindsym Down resize shrink down 10 px or 10 ppt
 +
bindsym Shift+Down resize grow down 10 px or 10 ppt
  
To directly attach to container:
+
bindsym Up resize shrink up 10 px or 10 ppt
 +
bindsym Shift+Up resize grow up 10 px or 10 ppt
  
<console>
+
bindsym Right resize shrink right 10 px or 10 ppt
###i## lxc-attach -n funtoo0
+
bindsym Shift+Right resize grow right 10 px or 10 ppt
</console>
+
  
To stop the container:
+
        # back to normal: Enter or Escape
 +
bindsym Return mode "default"
 +
bindsym Escape mode "default"
 +
}
  
<console>
+
bindsym $mod+r mode "resize"
###i## lxc-stop -n funtoo0
+
</console>
+
  
Ensure that networking is working from within the container while it is running, and you're good to go!
+
########################################################
 +
######## i3bar ########
 +
########################################################
  
== Starting LXC container during host boot ==
+
# Start i3bar to display a workspace bar (plus the system information i3status
 +
# finds out, if available)
 +
bar {
 +
    output            DFP3
 +
    output       DFP4
 +
    status_command    i3status -c ~/.i3status.conf
 +
    position          top
 +
    mode              dock
 +
    workspace_buttons yes
 +
    tray_output      DFP3
 +
   
 +
    font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
  
# You need to create symlink in <tt>/etc/init.d/</tt> to <tt>/etc/init.d/lxc</tt> so that it reflects your container.
+
    colors {
# <tt>ln -s /etc/init.d/lxc /etc/init.d/lxc.funtoo0</tt>
+
        background #000000
# now you can add <tt>lxc.funtoo0</tt> to default runlevel
+
        statusline #FFFFFF
# <tt>rc-update add lxc.funtoo0 default</tt>
+
<console>
+
###i## rc
+
* Starting funtoo0 ...                  [ ok ]
+
</console>
+
  
== LXC Bugs/Missing Features ==
+
        focused_workspace  #ffffff #9932CC
 +
        active_workspace  #ffffff #DA70D6
 +
        inactive_workspace #888888 #242424
 +
        urgent_workspace  #ffffff #32CD32
 +
    }
 +
} </pre></div>
  
This section is devoted to documenting issues with the current implementation of LXC and its associated tools. We will be gradually expanding this section with detailed descriptions of problems, their status, and proposed solutions.
+
These scripts can be found in /usr/bin/
  
=== reboot ===
+
=== i3nagbar ===
  
By default, lxc does not support rebooting a container from within. It will simply stop and the host will not know to start it.
+
The i3nagbar is the error bar that pops up on top of the screen when there is an error in the i3 configuration.
  
=== PID namespaces ===
+
=== i3-sensible-editor ===
  
Process ID namespaces are functional, but the container can still see the CPU utilization of the host via the system load (ie. in <tt>top</tt>).
+
i3-sensible-editor is callen when the user presses the edit button on the i3nagbar. If $EDITOR is set, that editor will be used, else i3-sensible-editor will open the first editor that is installed according to the order in i3-sensible-editor.  If the user has a preference, he will set $EDITOR.
  
=== /dev/pts newinstance ===
+
=== i3-sensible-terminal ===
  
* Some changes may be required to the host to properly implement "newinstance" <tt>/dev/pts</tt>. See [https://bugzilla.redhat.com/show_bug.cgi?id=501718 This Red Hat bug].
+
i3-sensible-terminal is called when the user opens a terminal.  If $TERMINAL is set, that terminal will be used, else i3-sensible-terminal will open the first terminal that is installed according to the order in i3-sensible-terminal. If the user has a preference, he will set $TERMINAL.
  
=== lxc-create and lxc-destroy ===
+
=== i3-sensible-pager ===
  
* LXC's shell scripts are badly designed and are sure way to destruction, avoid using lxc-create and lxc-destroy.
+
i3-sensible-pager is called when the user presses the view button on the i3nagbar.  If $PAGER is set, that pager will be used, else i3-sensible-pager will open the first pager that is installed accordding to the order in i3-sensible-pager.  If the user has a preference, he will set $PAGER.
  
=== network initialization and cleanup ===
+
=== i3status ===
  
* If used network.type = phys after lxc-stop the interface will be renamed to value from lxc.network.link. It supposed to be fixed in 0.7.4, happens still on 0.7.5 - http://www.mail-archive.com/lxc-users@lists.sourceforge.net/msg01760.html
+
i3status generates a status bar similar to conky in i3. i3status replaces dzen2, xmobar, and other similar applications used in older versions of i3. It is suggested to create an <tt>~/.i3status.conf</tt> file to configure the i3status bar locally.
 +
A sample <tt>~/.i3status.conf</tt>:
  
* Re-starting a container can result in a failure as network resource are tied up from the already-defunct instance: [http://www.mail-archive.com/lxc-devel@lists.sourceforge.net/msg00824.html]
+
<pre>
 +
general {
 +
        colors = true
 +
        interval = 5
 +
}
  
=== lxc-halt ===
+
order = "disk /"
 +
order += "disk /home"
 +
order += "ethernet eth0"
 +
order += "cpu_temperature 0"
 +
order += "cpu_temperature 1"
 +
order += "cpu_temperature 2"
 +
order += "cpu_temperature 3"
 +
order += "load"
 +
order += "time"
  
* Missing tool to graceful shutdown container. 'lxc-halt' should be written and be posix sh-compatible, using lxc-execute to run halt in container.
+
ethernet eth0 {
 +
        # if you use %speed, i3status requires the cap_net_admin capability
 +
        format_up = "Eth0: %ip (%speed)"
 +
        format_down = "Eth0: down"
 +
}
  
=== funtoo ===
+
time {
 +
        format = "%a:%d-%b-%Y %I:%M:%S %p"
 +
}
 +
 
 +
load {
 +
        format = "Load: %5min"
 +
}
 +
 
 +
cpu_temperature 0 {
 +
format = "T1: %degrees °C"
 +
path = "/sys/devices/platform/coretemp.0/temp2_input"
 +
}
 +
 
 +
cpu_temperature 1 {
 +
format = "T2: %degrees °C"
 +
path = "/sys/devices/platform/coretemp.0/temp3_input"
 +
}
 +
 
 +
cpu_temperature 2 {
 +
format = "T3: %degrees °C"
 +
path = "/sys/devices/platform/coretemp.0/temp4_input"
 +
}
 +
 
 +
cpu_temperature 3 {
 +
format = "T4: %degrees °C"
 +
path = "/sys/devices/platform/coretemp.0/temp5_input"
 +
}
 +
 
 +
disk "/" {
 +
        format = "/: %free"
 +
}
 +
 
 +
disk "/home" {
 +
format = "/home: %free"
 +
}
 +
</pre>
 +
 
 +
== dmenu ==
 +
 
 +
i3 uses {{Package|x11-misc/dmenu}} as the application launcher. To install it, run the following:
 +
 
 +
<console>
 +
###i## emerge dmenu
 +
</console>
 +
 
 +
{{fancynote| The default key-binding for dmenu is Mod1+d.}}
 +
 
 +
== Default Keybindings ==
 +
 
 +
{| class="wikitable" border="2" style="text-align:center;"
 +
|Alt + Enter
 +
|Open terminal
 +
|-
 +
|Alt + A
 +
|Focus Parent
 +
|-
 +
|Alt + S
 +
|Stacked Layout
 +
|-Advanced SearchSearch…
 +
|Alt + W
 +
|Tabbed Layout
 +
|-
 +
|Alt + E
 +
|Default Layout
 +
|-
 +
|Alt + SpaceBar
 +
|Focus tiling/floating
 +
|-
 +
|Alt + D
 +
|dmenu
 +
|-
 +
|Alt + H
 +
|Split Horizontal
 +
|-
 +
|Alt + V
 +
|Split Vertically
 +
|-
 +
|Alt + J
 +
|Left
 +
|-
 +
|Alt + K
 +
|Down
 +
|-
 +
|Alt + J
 +
|Up
 +
|-
 +
|Alt + ;
 +
|Right
 +
|-
 +
|Alt + Shift + Q
 +
|Kill window
 +
|-
 +
|Alt + Shift + E
 +
|Exit i3
 +
|-
 +
|Alt + Shift + C
 +
|Reload i3config without restarting
 +
|-
 +
|Alt + Shift + R
 +
|Restart i3 (reloads i3config without exiting i3)
 +
|-
 +
|Alt + Shift + J
 +
|Move left
 +
|-
 +
|Alt + Shift + K
 +
|Move down
 +
|-
 +
|Alt + Shift + L
 +
|Move up
 +
|-
 +
|Alt + Shift + :
 +
|Move right
 +
|-
 +
|Alt + Shift + SpaceBar
 +
|Toggle tiling/floating
 +
|}
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== i3status ===
 +
 
 +
{{fancynote| i3status may not work out of box}} The permissions may be set to: <tt>-r-xr-x---</tt>: when run as non-root, sh would return with "permission denied".
 +
If i3status does not work for you, this can be easily corrected by changing the permissions.
 +
<console>
 +
###i## sudo chmod 755 /usr/bin/i3status
 +
</console>
  
* Our udev should be updated to contain <tt>-lxc</tt> in scripts. (This has been done as of 02-Nov-2011, so should be resolved. But not fixed in our openvz templates, so need to regen them in a few days.)
+
=== Documentation ===
* Our openrc should be patched to handle the case where it cannot mount tmpfs, and gracefully handle this situation somehow. (Work-around in our docs above, which is to mount tmpfs to <tt>/libexec/rc/init.d</tt> using the container-specific <tt>fstab</tt> file (on the host.)
+
* Emerging udev within a container can/will fail when realdev is run, if a device node cannot be created (such as /dev/console) if there are no mknod capabilities within the container. This should be fixed.
+
  
== References ==
+
==== Websites ====
  
* <tt>man 7 capabilities</tt>
+
[http://i3wm.org/ i3]
* <tt>man 5 lxc.conf</tt>
+
  
== Links ==
+
[http://i3wm.org/docs/userguide.html User Guide]
  
* There are a number of additional lxc features that can be enabled via patches: [http://lxc.sourceforge.net/patches/linux/3.0.0/3.0.0-lxc1/]
+
[http://i3wm.org/docs/ More Documentation]
* [https://wiki.ubuntu.com/UserNamespace Ubuntu User Namespaces page]
+
* lxc-gentoo setup script [https://github.com/globalcitizen/lxc-gentoo on GitHub]
+
  
* '''IBM developerWorks'''
+
==== Man pages ====
** [http://www.ibm.com/developerworks/linux/library/l-lxc-containers/index.html LXC: Linux Container Tools]
+
** [http://www.ibm.com/developerworks/linux/library/l-lxc-security/ Secure Linux Containers Cookbook]
+
  
* '''Linux Weekly News'''
+
* i3
** [http://lwn.net/Articles/244531/ Smack for simplified access control]
+
* i3-config-wizard
 +
* i3-input
 +
* i3-migrate-config-to-v4
 +
* i3-msg
 +
* i3-nagbar
 +
* i3-sensible-editor
 +
* i3-sensible-pager
 +
* i3-sensible-terminal
 +
* i3-wsbar
 +
* i3bar
 +
* i3lock
 +
* i3status
  
[[Category:Labs]]
+
[[Category:Desktop]]
[[Category:HOWTO]]
+
[[Category:Virtualization]]
+

Revision as of 00:48, 19 February 2014

Contents

Introduction

i3 is a tiling window manager that is based upon experiences the developers shared while attempting to fix/hack wmii. i3 has the ability for either floating windows, which you can resize and move, and tiling windows. i3 uses a tree as a data structure to allow for more flexibility. i3 defaults with home-row key-bindings which are quick and easy to get beginners off the ground.

NOTE: This wiki is made following the steps produced to get a working i3 using xrandr instead of xinerama, ATI proprietary drivers instead of radeon drivers, a dual-monitor setup, and no login manager. For Nvidia and Twinview users, a link is supplied in X11 and xrandr. Xinerama was initially used and worked in the dual-monitor setup so it possible to substitute xinerama for xrandr with minimal changes.

Installation

Portage

The easiest and quickest way:

# emerge -avt x11-wm/i3

Manual

Tarball

Download the latest version from the i3 website. i3-4.1.1

# cd /PATH/TO/TARBALL
# make
# sudo make install

Git

# git clone git://code.i3wm.org/i3
# cd i3
# make
# sudo make install

Setup

xinitrc

Edit ~/.xinitrc:

exec i3


For i3 logging, edit ~/.xinitrc:

exec i3 -V -d all >~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1

If you are using Nvidia or for some reason don't use xrandr, edit ~/.xinitrc

exec i3 --force-xinerama

and nvidia with logging:

exec i3 --force-xinerama -V -d all >~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1

Example ~/.xinitrc that uses consolekit and dbus in launch and also logs on exit.

#!/bin/zsh
xrdb -merge ~/.Xresources
xcompmgr &

if [[ $1 == "i3" ]]; then
    exec ck-launch-session dbus-launch --sh-syntax --exit-with-session i3 -V -d all > ~/.i3/i3log-$(date +'%F-%k-%M-%S') 2>&1
elif [[ $1 == "razor" ]]; then
    exec ck-launch-session dbus-launch startrazor
elif [[ $1 == "awesome" ]]; then
    exec ck-launch-session dbus-launch awesome
elif [[ $1 == "qtile" ]]; then
    exec ck-launch-session dbus-launch ~/.qtile-session
else
    echo "Choose a window manager"
fi

X11 and xrandr

X and RandR

NOTE: RandR and Xinerama do not play together. Use one or the other.

I use an AMD HD 6870 with 3 monitors (2 DVI and 1 with an AMD validated Mini DisplayPort™ to DVI dongle).

Install xrandr:

# emerge x11-apps/xrandr

and if you want a GUI with xrandr:

# emerge x11-misc/arandr

If you do not have X configured yet, follow the link on the Gentoo Wiki

My xorg.conf.d folder for example: 30-screen.conf

Since the names of the monitors are already known in xrandr, I just use those names in my 30-screen.conf configuration. It doesn't matter what you use in your X configuration however.

Once you have X configured however you like, start qtile with either:

# startx

or, in a case similar to mine,

# xinit qtile

i3 config

The i3 configuration file can be found in /etc/i3/config, but I suggest that you copy the file into a local ~/.i3 directory.

# mkdir -p ~/.i3 && cp /etc/i3/config ~/.i3/config

Open up ~/i3/config in your editor of choice. set $mod Mod1 assigns the variable $mod to be Mod1. In i3, Mod1 is the Alt key. If you wish to use the Windows key then use set $mod Mod4 In the keybinding section, $mod is used in place of Mod1 in the case that you do wish to change the modifier. In the workspace key, the keybindings are set with Mod1 instead of the variable, so remember to change those bindings manually if you are replacing the Mod1 modifier. Else you can change Mod1 in those sections to $mod and change all the keybindings at the same time by setting the $mod variable.

set $mod Mod1

To have programs start automatically in i3, use the command exec APPLICATION. This is the section that the xrandr screen layout bash file created earlier will be placed. The i3bar is a tray and status bar combination. If you have applications that run in the system tray that you want to autostart, call those applications with exec.

exec /PATH/TO/XRANDR-BASH-FILE
exec NAME OF BROWSER
exec NAME OF EDITOR
exec volumeicon
exec dropbox

In the workspace section, you have the opportunity to name the workspaces by setting either the number of the workspace, the name of the workspace, or the number and name of the workspace. bindsym KEYBIND workspace NAME/NUMBER OF WORKSPACE. Remember to use quotes when naming a workspace.

bindsym Mod1+1 workspace 1
bindsym Mod1+1 workspace "my first workspace"
bindsym Mod1+1 workspace "1: my first workspace"

To assign a workspace to a certain output you will need the output from running xrandr again if you do not remember which connections are being used. In the example from [#X11 and xrandr|X11 and xrandr], the connected outputs are DFP3 and DFP4. To assign the workspace, you need to add workspace NAME OF WORKSPACE or NUMBER output CONNECTED OUTPUT. There are several types of outputs so make sure that you are using the connected outputs from xrandr when assigning workspaces, else the workspace will not show up.

workspace 1 output DFP3
workspace "my first workspace" output DFP3
workspace "1: my first workspace" output DFP3
workspace "2: my second workspace" output DFP4

To assign a program to a certain workspace, you will need to run xprop. If you do not have xprop, emerge it.

# emerge -avt x11-apps/xprop
To run xprop, open a terminal and run
# xprop
Your mouse cursor should become a crosshair and you will want to mouse over the window that contains the running application. Click on that window and xprop will then output the window information. The easiest way to assign a program is to look for
WM_CLASS(STRING) = "INSTANCE", "CLASS"
Be sure to note that the window INSTANCE is before the window CLASS. In the config file, add assign [class="^INSTANCE$" instance="^CLASS$] NAME OF WORKSPACE. For aesthetic purposes, you can add → before NAME OF WORKSPACE, but mind that the → is a UTF-8 character and not ->. For the assignments, do not put the workspace name within quotes as you do when naming them and setting their output.
assign [class="^Chromium-browser$" instance="^chromium-browser$"] 1
assign [class="^Chromium-browser$" instance="^chromium-browser$"] web
assign [class="^Chromium-browser$" instance="^chromium-browser$"] 1: web
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → web
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1: web

For aesthetic purposes, their are three types of borders for the windows. This can be set by adding new_window <normal|1pixel|none>. There are also keybindings that allow you to switch between the 3 border styles.

new_window 1pixel
bindsym $mod+t border normal
bindsym $mod+y border 1pixel
bindsym $mod+u border none

The orientation for new workspaces can be set by adding default_orientation <horizontal|vertical|auto>

default_orientation horizontal

A sample ~/.i3/config:

set $mod Mod1

########################################################
########		Autostart		########
########################################################
exec ~/.screenlayout/dualdtop.sh			
exec chromium-browser					
exec gvim						
exec volumeicon							
exec parcellite
exec dropbox

########################################################
########		Workspaces		########
########################################################
# switch to workspace
bindsym Mod1+1 workspace "1: web"
bindsym Mod1+2 workspace "2: irc"
bindsym Mod1+3 workspace "3: gvim"
bindsym Mod1+4 workspace "4: ranger"
bindsym Mod1+5 workspace "5: terms"
bindsym Mod1+6 workspace "6: mplayer"
bindsym Mod1+7 workspace "7: mail"
bindsym Mod1+8 workspace "8: firefox"
bindsym Mod1+9 workspace "9: music"
bindsym Mod1+0 workspace "10: office"

## Output certain workspaces
workspace "1: web" output DFP3
workspace "2: irc" output DFP4
workspace "3: gvim" output DFP4
workspace "4: ranger" output DFP3
workspace "5: terms" output DFP4
workspace "6: mplayer" output DFP3
workspace "7: mail" output DFP3
workspace "8: firefox" output DFP3
workspace "9: music" output DFP3
workspace "10: office" output DFP4

## Assign workspaces to programs
assign [class="^Chromium-browser$" instance="^chromium-browser$"] → 1: web
assign [class="^Gvim$" instance="^gvim$"] → 3: gvim
assign [class="^MPlayer$" instance="^gl$"] → 6: mplayer
assign [class="^Firefox$" instance="^Navigator$"] → 8: firefox
assign [class="^Emacs$" instance="^emacs$"] → 9: emacs
assign [class="^libreoffice-startcenter$" instance="^VCLSalFrame.DocumentWindow$"] 10: office

# move focused container to workspace
bindsym Mod1+Shift+1 move workspace 1
bindsym Mod1+Shift+2 move workspace 2
bindsym Mod1+Shift+3 move workspace 3
bindsym Mod1+Shift+4 move workspace 4
bindsym Mod1+Shift+5 move workspace 5
bindsym Mod1+Shift+6 move workspace 6
bindsym Mod1+Shift+7 move workspace 7
bindsym Mod1+Shift+8 move workspace 8
bindsym Mod1+Shift+9 move workspace 9
bindsym Mod1+Shift+0 move workspace 10

########################################################
########		Aesthetics		########
########################################################
# Window border style: normal: border normal, with window title bar;
# none: no border or window title bar; 1pixel: 1 pixel border.
new_window 1pixel
bindsym $mod+t border normal
bindsym $mod+y border 1pixel
bindsym $mod+u border none

# font for window titles. ISO 10646 = Unicode
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

# Orientation for new workspaces
# Can be set <horizontal|vertical|auto>
default_orientation horizontal

# Layout for new containers
# Can be set <default|stacking|tabbed>
workspace_layout default

# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod

########################################################
########		Keybindings		########
########################################################

# start a terminal
bindsym $mod+Return exec i3-sensible-terminal

# kill focused window
bindsym $mod+Shift+Q kill

# start dmenu (a program launcher)
bindsym $mod+d exec dmenu_run

# change focus
bindsym $mod+j focus left
bindsym $mod+k focus down
bindsym $mod+l focus up
bindsym $mod+semicolon focus right

# alternatively, you can use the cursor keys:
bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

# move focused window
bindsym $mod+Shift+J move left
bindsym $mod+Shift+K move down
bindsym $mod+Shift+L move up
bindsym $mod+Shift+colon move right

# alternatively, you can use the cursor keys:
bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

# split in horizontal orientation
bindsym $mod+h split h

# split in vertical orientation
bindsym $mod+v split v

# enter fullscreen mode for the focused container
bindsym $mod+f fullscreen

# change container layout (stacked, tabbed, default)
bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout default

# toggle tiling / floating
bindsym $mod+Shift+space floating toggle

# change focus between tiling / floating windows
bindsym $mod+space focus mode_toggle

# focus the parent container
bindsym $mod+a focus parent

# focus the child container
#bindcode $mod+d focus child

# reload the configuration file
bindsym $mod+Shift+C reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod+Shift+R restart
# exit i3 (logs you out of your X session)
bindsym $mod+Shift+E exit

# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode
        # They resize the border in the direction you pressed, e.g.
        # when pressing left, the window is resized so that it has
        # more space on its left

bindsym j resize shrink left 10 px or 10 ppt
bindsym Shift+J resize grow left 10 px or 10 ppt

bindsym k resize shrink down 10 px or 10 ppt
bindsym Shift+K resize grow down 10 px or 10 ppt

bindsym l resize shrink up 10 px or 10 ppt
bindsym Shift+L resize grow up 10 px or 10 ppt

bindsym semicolon resize shrink right 10 px or 10 ppt
bindsym Shift+colon resize grow right 10 px or 10 ppt

        # same bindings, but for the arrow keys
bindsym Left resize shrink left 10 px or 10 ppt
bindsym Shift+Left resize grow left 10 px or 10 ppt

bindsym Down resize shrink down 10 px or 10 ppt
bindsym Shift+Down resize grow down 10 px or 10 ppt

bindsym Up resize shrink up 10 px or 10 ppt
bindsym Shift+Up resize grow up 10 px or 10 ppt

bindsym Right resize shrink right 10 px or 10 ppt
bindsym Shift+Right resize grow right 10 px or 10 ppt

        # back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}

bindsym $mod+r mode "resize"

########################################################
########		i3bar			########
########################################################

# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
    output            DFP3
    output	      DFP4
    status_command    i3status -c ~/.i3status.conf
    position          top
    mode              dock
    workspace_buttons yes
    tray_output       DFP3
    
    font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

    colors {
        background #000000
        statusline #FFFFFF

        focused_workspace  #ffffff #9932CC
        active_workspace   #ffffff #DA70D6
        inactive_workspace #888888 #242424
        urgent_workspace   #ffffff #32CD32
    }
} 

These scripts can be found in /usr/bin/

i3nagbar

The i3nagbar is the error bar that pops up on top of the screen when there is an error in the i3 configuration.

i3-sensible-editor

i3-sensible-editor is callen when the user presses the edit button on the i3nagbar. If $EDITOR is set, that editor will be used, else i3-sensible-editor will open the first editor that is installed according to the order in i3-sensible-editor. If the user has a preference, he will set $EDITOR.

i3-sensible-terminal

i3-sensible-terminal is called when the user opens a terminal. If $TERMINAL is set, that terminal will be used, else i3-sensible-terminal will open the first terminal that is installed according to the order in i3-sensible-terminal. If the user has a preference, he will set $TERMINAL.

i3-sensible-pager

i3-sensible-pager is called when the user presses the view button on the i3nagbar. If $PAGER is set, that pager will be used, else i3-sensible-pager will open the first pager that is installed accordding to the order in i3-sensible-pager. If the user has a preference, he will set $PAGER.

i3status

i3status generates a status bar similar to conky in i3. i3status replaces dzen2, xmobar, and other similar applications used in older versions of i3. It is suggested to create an ~/.i3status.conf file to configure the i3status bar locally. A sample ~/.i3status.conf:

general {
        colors = true
        interval = 5
}

order = "disk /"
order += "disk /home"
order += "ethernet eth0"
order += "cpu_temperature 0"
order += "cpu_temperature 1"
order += "cpu_temperature 2"
order += "cpu_temperature 3"
order += "load"
order += "time"

ethernet eth0 {
        # if you use %speed, i3status requires the cap_net_admin capability
        format_up = "Eth0: %ip (%speed)"
        format_down = "Eth0: down"
}

time {
        format = "%a:%d-%b-%Y %I:%M:%S %p"
}

load {
        format = "Load: %5min"
}

cpu_temperature 0 {
	format = "T1: %degrees °C"
	path = "/sys/devices/platform/coretemp.0/temp2_input"
}

cpu_temperature 1 {
	format = "T2: %degrees °C"
	path = "/sys/devices/platform/coretemp.0/temp3_input"
}

cpu_temperature 2 {
	format = "T3: %degrees °C"
	path = "/sys/devices/platform/coretemp.0/temp4_input"
}

cpu_temperature 3 {
	format = "T4: %degrees °C"
	path = "/sys/devices/platform/coretemp.0/temp5_input"
}

disk "/" {
        format = "/: %free"
}

disk "/home" {
	format = "/home: %free"
} 

dmenu

i3 uses x11-misc/dmenu as the application launcher. To install it, run the following:

# emerge dmenu
Note: The default key-binding for dmenu is Mod1+d.

Default Keybindings

Alt + Enter Open terminal
Alt + A Focus Parent
Alt + S Stacked Layout
Alt + W Tabbed Layout
Alt + E Default Layout
Alt + SpaceBar Focus tiling/floating
Alt + D dmenu
Alt + H Split Horizontal
Alt + V Split Vertically
Alt + J Left
Alt + K Down
Alt + J Up
Alt + ; Right
Alt + Shift + Q Kill window
Alt + Shift + E Exit i3
Alt + Shift + C Reload i3config without restarting
Alt + Shift + R Restart i3 (reloads i3config without exiting i3)
Alt + Shift + J Move left
Alt + Shift + K Move down
Alt + Shift + L Move up
Alt + Shift + : Move right
Alt + Shift + SpaceBar Toggle tiling/floating

Troubleshooting

i3status

Note: i3status may not work out of box
The permissions may be set to: -r-xr-x---: when run as non-root, sh would return with "permission denied".

If i3status does not work for you, this can be easily corrected by changing the permissions.

# sudo chmod 755 /usr/bin/i3status

Documentation

Websites

i3

User Guide

More Documentation

Man pages

  • i3
  • i3-config-wizard
  • i3-input
  • i3-migrate-config-to-v4
  • i3-msg
  • i3-nagbar
  • i3-sensible-editor
  • i3-sensible-pager
  • i3-sensible-terminal
  • i3-wsbar
  • i3bar
  • i3lock
  • i3status