runit openrc gentoo

I decided to have another go at runit, this time on my gentoo.

I had been thinking about this, since I noticed this in the Gentoo Wiki article on OpenRC:
It does not function as a replacement for the /sbin/init

I keep wanting to trim everything down, and have been integrating busybox to replace userspace utilities. The gentoo wiki says:
Busybox can be used to replace most of the userspace utilities needed by OpenRC (init, shell, awk and other POSIX tools), by using a complete Busybox as shell for OpenRC all the calls that normally would cause a fork/exec would be spared, improving the overall speed. This process is not yet streamlined.
Please note that there are currently many Busybox applets that are incompatible with OpenRC.

It was that last bit which concerned me, and I didn't want to risk hacking it too much.

But I could hack /bin/init provided by sys-apps/sysvinit. I do like runit, and decided to install sys-process/runit which provides /sbin/runit-init.

The install was pretty simple:
# emerge --ask sys-process/runit

I was very surprised when my regular clean up routine asked to unmerge sys-apps/sysvinit.

# emerge --depclean --ask 
... 
... 
>>> Calculating removal order... 

>>> These are the packages that would be unmerged: 

 sys-apps/sysvinit 
    selected: 2.88-r9 
   protected: none 
     omitted: none 

All selected packages: =sys-apps/sysvinit-2.88-r9 

>>> 'Selected' packages are slated for removal. 
>>> 'Protected' and 'omitted' packages will not be removed. 

Would you like to unmerge these packages? [Yes/No] n

Was it not needed anymore?

Wanting to see what gentoo does out of the box, I rebooted, and appended init=/sbin/runit-init to the kernel cmdline boot prompt.

My system booted up cleanly, and I could login and startx.

However, I had no network. But I could manually start my network, and all was fine.

# /etc/init.d/net.wlp3s0 start

Subsequently, I realised that none of my other services had started. I narrowed them all down to the default runlevel.

It seems that all the services in sysinit and boot runlevels had started, but the default runlevel had not been triggered.

So this was the only thing to do, in order to have runit instead of sysvinit on gentoo out of the box. Impressive!

I had a look at runit's runlevel 1.

$ cat /etc/runit/1                                                                                                                                                                                   
#!/bin/sh
# system one time tasks

PATH=/sbin:/usr/sbin:/bin:/usr/bin

RUNLEVEL=S /sbin/rc sysinit
RUNLEVEL=S /sbin/rc boot

touch /etc/runit/stopit
chmod 0 /etc/runit/stopit

It looks like runit runlevel 1 is triggering the openrc runlevels sysinit and boot, but default is not listed there. So I just added it in there.

$ cat /etc/runit/1                                                                                                                                                                                   
#!/bin/sh
# system one time tasks

PATH=/sbin:/usr/sbin:/bin:/usr/bin

RUNLEVEL=S /sbin/rc sysinit
RUNLEVEL=S /sbin/rc boot
RUNLEVEL=S /sbin/rc default

touch /etc/runit/stopit
chmod 0 /etc/runit/stopit

I rebooted again to test. All my services were working, and I had no errors or warnings.

I decided to go for broke, and remove sysvinit with a bit of trepidation, but knowing that I could put it back as it was.

# emerge --ask --depclean sys-apps/sysvinit

With a clean slate, I rebooted again and was pleasantly surprised. Everything seems to be well on my system.. Well, almost!

sysvinit had disappeared along with shutdown, reboot, halt, poweroff, etc. So I had created them.

# vi /usr/local/sbin/runit-shutdown
#!/bin/sh
case "$(basename $0)" in
  reboot) /sbin/runit-init 6 ;;
  shutdown|poweroff|halt)
    /sbin/runit-init 0 ;;
esac
# cd /sbin
# ln -s /usr/local/runit-shutdown shutdown
# ln -s /usr/local/runit-shutdown poweroff
# ln -s /usr/local/runit-shutdown halt
# ln -s /usr/local/runit-shutdown reboot

And all is well again. Powerbutton is working, as are my other i3 keybindings.

As the runit article on gentoo wiki says:
It can be used in conjunction with OpenRC as an alternative to sysvinit or even replacing OpenRC as service manager.
Runit can also replace OpenRC as the service manager.
which means runit can do everything on it's own. I have seen it being very dependable & stable in voidlinux.

Now why didn't the linux lords consider lean, clean & simple runit, when deciding about systemd?

I am usually very critical of systemd. But kudos where it is due, for systemd removing much accumulated garbage/cruft like *bus *kit etc.

For now, I will keep openrc as service manager, and runit as system init. Too much hacking at the gentoo core might take me too far away.

$ pidof runit
1

tmux mouse scroll

I keep running into this issue, as tmux changed it's mouse behaviour. To make it work again, add the following code snippet into your ~/.tmux.conf

set -g mouse on
bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'select-pane -t=; copy-mode -e; send-keys -M'"
bind -n WheelDownPane select-pane -t= \; send-keys -M

and reload the changed tmux configuration
$ tmux source ~/.tmux.conf

git Gentoo repos on GitHub

git me! The gentoo repos are on github, and I've just discovered them.. mysteriously hidden in the World Wide Web ;)

There is a post on the gentoo forums from 2015, re git/github saying:
Although some developers wrongly still recommend plain rsync-update method, you should never do that, since it is fundamentally insecure (emerge-webrsync is signed by a machine key, but still better). 

You should instead start to sync via git (best do that from github, unless you want to break our infra server).

Essentially, rsync update method is outdated and insecure. The recommendation is to sync update via git, and more specifically github, rather than the gentoo infra servers.

GitHub gentoo (without metadata cache, for developers) repo:
http://github.com/gentoo/gentoo

This seems to be a mirror of the gentoo git infra server:
http:://anongit.gentoo.org/repo/gentoo

I found a github mirror, which I now use. For anonymous portage sync updates, I am hoping this secondary mirror may be more stable and less noisy.

GitHub gentoo-mirror (with metadata cache, for users) repo:
http://github.com/gentoo-mirror/gentoo

Before we change our sync method to git, we need to prepare/clean the portage location. Delete existing files, or move them elsewhere, in case you might have second thoughts ;) If you are not happy with git, you can move them back, and continue with rsync updates.

# mv /usr/portage /tmp

If you don't have enough freespace in /tmp, or don't want to use it, move it elsewhere and remember the location.

My /tmp is on tmpfs, and I have enough free space there for now. If you have a similar setup, note that tmpfs will not survive a reboot.

Now we can change our sync method to git.

# vi /etc/portage/repos.conf/gentoo.conf
[DEFAULT]
main-repo = gentoo

[gentoo]
location = /usr/portage
sync-type = git
sync-uri = git://github.com/gentoo-mirror/gentoo.git
auto-sync = yes

Make sure there are no other files in that folder. I had trouble when I renamed my gentoo.conf file to another name in that same folder as backup. I changed auto-sync = no to be safer. Sync wouldn't give me any errors, or updates!

I previously used the gentoo infra server, before changing over to github, and then to the mirror. Apparently, the gentoo infra servers are not ready to take the weight of the whole world. Apparently, GitHub is safer and more reliable. I was pleasantly surprised that my git was in sync after the changeover.

We have prepared, cleaned and emptied our portage for a git sync. Now we can sync.
# emerge --sync

And move the distfiles back where they belonged.
# mv /tmp/portage/distfiles /usr/portage/

Now you can sync again and again.. to your heart's content :) No more worrying about overloaded rsync servers warning, or ending up on the ban list for syncing too much.

It is now a pleasure to sync, and see exactly what has changed where. Such a difference from watching that cruft fly past like a matrix on your screen. You might miss the filed Change Logs, if you used them. They are no longer needed. Git has much better, automated and less error prone methods.

Note the efficiency of git sync, and github :) This is what Linus alluded to, when he wanted to have an efficient kernel repository, accessible to the whole world.

If you are happy with git sync, you can delete that portage backup.
# rm -rf /tmp/portage

Another more important aspect is about making open source truly open! Anyone, even without github logins, can view the sources and changes. With a free github account, anyone could make suggestions via a simple pull request. You don't even need to be a developer.

The Monolithic Cabals

A few decades ago, there was a great big flame war called the Monolithic vs Microkernel debate. It is said that the debate was won by Linus. And that is why Linux became so popular.

Personally, I am a fan of Microkernels. But I am more a fan of Open Source. I believe that is the sole reason Linux became so popular. Linux didn't become so popular because people loved a monolithic architecture. Folks embraced it because it was open source.

More recently, there have been similar flames wars, but on a much larger scale, likes of which had never been seen before, spreading out from the low-level Kernel layers to the higher layers above. Apparently, some years ago, Gnome won the battle for the top layer Desktop, or rather the Desktop Environment. What was left was the middle layers between the Kernel and the GUI. And that battle apparently ended with many distributions bowing down to systemd. This was more a victory for the Gnome camp, who had lent them more than a covert hand in that battle. RedHat won the battle this time.

These monolithic cabals want to do everything. They don't seem to understand The Unix Philosophy. Taking over everything just makes them Too Big To Fail. We should never put all our eggs in one basket.

Is the war seemingly over now? The powerful feudal lords have divided the spoils between who owns which layer of the empire. Each of them, in their wisdom, have decided that they shall be the sole decision makers over what everyone else is or not allowed to do.

The one saving grace that stops them being completely becoming evil is the fact that each of them are completely dependant on Open Source. Any change they attempt is open to the rest of the world. Even that fact didn't stop The Mad Hatters from attempting to take over the lower layer kernel, with their dubious code pushes.

If I didn't know any better, I might suspect this as a culmination or coming together of a series of covert Microsoft Strategies. If you have not read The Halloween Documents, it is worth having a quick look. The FUD has come full circle, and many camps within Linux got embroiled in major flame wars over the systemd middleware between desktop and kernel.

This also reminds me of a paper called The Cathedral and The Bazaar. Slaves never had a choice. Freemen could make their own choices, unencumbered by anyone telling them what to do or not. There must be a reason that the exalted cathedrals of yore are empty now, while the bazaars have flourished.

It all depends on which side of the fence you are. If you are among the ruling class, obviously you will want to remain in the cathedral, lording over others. But if you are not among the ones inside enjoying luxuries, you would rather be outside free to decide your lifestyle and how best to flourish yourself, than be a slave in the cathedral.

In the end, it all depends on what is best for the world. Is it better that a few rule over everyone? Or would the world be a better place, if everyone had equality of choice and rights? No one should be too poor or too rich!

There is a reason that Open Source has flourished with contributions from volunteers who gave back their skills and time, in order to make things better for everyone. In stark contrast, the extremely wealthy proprietary software companies are all sitting on great big piles of accumulated cash twiddling their thumbs, deciding what to do.

I think my thoughts are running amok now..

I just wanted to pen down some thoughts before I lost them. I will flush this a bit more later.. Keep an eye!

A Digital Beep

When you don't have a Speaker/Bell, or you can't make quite make it work, and you want a beep!

It seems some devs have been a bit over zealous in trying to get rid of the system beep. Apparently, some users have been loudly complaining about their systems playing loud beeps. So they have thrown the baby out with the bath water. And now users who need the system beep do not seem to have it anymore.

The traditional method, to trigger the bell sound on a system beep event, was using pcspkr or snd-pcsp kernel modules. It seems quite a lot of users have lost this functionality during system updates. There seem to be multiple workarounds of workarounds floating around to resolve this issue. They seem to work for some, but not for many.

If you can, it is best to try get either pcspkr or snd-pcsp to work, as the system beep is an integrated event. You can hear the beep anywhere you want, including the console and terminals. The beep volume can be controlled from your audio mixer. You can increase, decrease, or mute the beep volume. That is how it used to be, and that is how it should have been.

Unfortunately, we seem to have quite a lot of trigger happy devs lately. In their eternal quest to keep adding yet more features and bumping up versions, they lose sight of core functionality and stability. Personally, I would rather have stable (even if old) reliable systems, than use bleeding edge new systems filled with tons of new features and even more bugs. In this process, they seem to be cannibalising what they have been handed over from previous generations to maintain.

But I guess, we are where we are.. and we try to make the best of what we have.

A digital beep could be a useful alternative. In this case, an audio file sounding like a bell masquerades as the pc-speaker bell at each system beep. In a nutshell, an audio player plays an audio file, at every system beep event.

The caveat is that depending on the method used, a digital beep is restricted to certain environments only. The method used below will only work within X, not on the console or any tty or anywhere outside X.

Read on for what is required. You can customise, or replace most of the bits with something else.

Kernel config:

Since we will not use pcspkr or snd-pcsp, we might as well remove them from the kernel, or atleast mask them. No need to carry excess baggage. No point in having things we can't/won't use.

# vi /etc/modprobe.d/blacklist.conf
blacklist pcspkr
black snd-pcsp

Check your kernel config for INPUT_BEEP. If not, add them and recompile your kernel. You will need to reboot for the new kernel to take effect.
$ grep BEEP /boot/config-`uname -r`
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1

This is enabled in the default kernel configs of gentoo, debian, ubuntu, and arch linux.

Packages required:
1. sound-theme-freedesktop
2. vorbis-tools
3. xkbevd

sound-theme-freedesktop: A standard minimal freedesktop.org sound theme.
This package installs a set of sound files in /usr/share/sounds/freedesktop directory. One of those audio files called bell.oga simulates a digital beep.

vorbis-tools
This package contains the ogg123 audio decoder/player, which can play .oga sound files from a sound-theme.

$ man ogg123
ogg123 reads Ogg Vorbis audio files and decodes them to the devices specified on the command line. By default, ogg123 writes to the standard sound device, but output can be sent to any number of devices. Files can be read from the file system, or URLs can be streamed via HTTP.

xkbevd: XKB event daemon
We run this as a background service to check for bell events, and trigger ogg123 to play bell.oga.

$ man xkbevd
The xkbevd event daemon listens for specified XKB events and executes requested commands if they occur. The configuration file consists of a list of event specification/action pairs and/or variable definitions.

The default configuration file is ~/.xkb/xkbevd.cf, which needs to be created.

$ vi ~/.xkb/xkbevd.cf
soundDirectory="/usr/share/sounds/"
soundCmd="ogg123 -q"

Bell() "freedesktop/stereo/bell.oga"

This is pretty much the standard configuration.

We could open this up, and use any other audio file and any other media player. One thing to consider would be the impact of using large audio files and/or large audio players. We don't really want our system to freeze at every single bell event, while bloatwares load.

Identify your environment, to auto-start the XKB event daemon, according to your DE (Desktop Environment) or WM (Window Manager).

In my case, I login at the console and startx. I added the following line to my startup file.

$ vi ~/.xinitrc
xkbevd -bg
exec i3

There are a few more lines in that file. But those are the last two lines.

Ok, we have pretty much finished up. Now, we need to check whether these settings take effect.

If you had to recompile your kernel, you need to reboot. If you didn't, you need to logout and login, to verify the daemon auto-start.

May the beep be with you!

i3 wm

I've been hearing about i3 Window Manager for a while now, and had been waiting to have a go. I finally did.

i3wm.org
i3 User Guide

All the major advantages are listed on the homepage itself. What I particularly like:
"Don’t be bloated, don’t be fancy (simple borders are the most decoration we want to have)."

For now I am making it my home. I don't need any fancy distracting frills. The only thing I seem to be missing is Alt+Tab, as I keep hitting it. [Update: I got that working. See config below.]

You can have a really beautiful desktop, but how long are you going to look at it, before you open some windows which cover most of your desktop? As for me, I usually have all windows maximised on my smallish screen.

i3 has three layouts - split ($mod+e), stacking ($mod+s), and tabbed ($mod+w). I particularly like the tabbed layout maximising screen estate use on small laptop screen. (Auto)Hide the statusbar, and or full-screen ($mod+f) your windows.

$mod+Enter will open a new terminal window in your chosen layout. You can change layouts anytime.
$mod+Shift+q will close your active window.
$mod+Shift+e will exit i3.

Armed with this basic knowledge, we can start exploring i3.

It is a very simple install - three packages - i3 + i3status and dmenu.

On first run, i3 will prompt you and create it's config in ~/.config/i3/config.

Below are my config files.

$ cat ~/.xinitrc
#!/bin/sh
setxkbmap -option terminate:ctrl_alt_bksp
exec i3

$ cat ~/.config/i3/config
set $mod Mod4

#font pango:monospace 8
#font pango:DejaVu Sans Mono 8
font pango:DejaVu Sans, FontAwesome 8

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

bindsym $mod+Shift+c reload
bindsym $mod+Shift+r restart
bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"

bindsym $mod+Shift+q kill
bindsym $mod+Return exec i3-sensible-terminal

#bindsym $mod+d exec dmenu_run
bindsym $mod+d exec --no-startup-id i3-dmenu-desktop

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

bindsym $mod+Left focus left
bindsym $mod+Down focus down
bindsym $mod+Up focus up
bindsym $mod+Right focus right

bindsym $mod+Shift+j move left
bindsym $mod+Shift+k move down
bindsym $mod+Shift+l move up
bindsym $mod+Shift+semicolon move right

bindsym $mod+Shift+Left move left
bindsym $mod+Shift+Down move down
bindsym $mod+Shift+Up move up
bindsym $mod+Shift+Right move right

bindsym $mod+h split h
bindsym $mod+v split v

bindsym $mod+f fullscreen toggle

bindsym $mod+s layout stacking
bindsym $mod+w layout tabbed
bindsym $mod+e layout toggle split

# 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
#bindsym $mod+d focus child

set $workspace1 "1  "
set $workspace2 "2  "
set $workspace3 "3  "
set $workspace4 "4  "
set $workspace5 "5  "
set $workspace6 "6  "
set $workspace7 "7  "
set $workspace8 "8  "
set $workspace9 "9  "
set $workspace10 "10  "

assign [class="Geany"]  $workspace1
assign [class="Sylpheed"] $workspace2
assign [class="Opera"]  $workspace3
assign [class="QupZilla"] $workspace4
assign [class="Firefox"]  $workspace4
assign [class="mpv"]  $workspace9
assign [class="Spotify"] $workspace10

new_window none  #borders none
workspace_layout default #default|tabbed|stacking|splitv|splith
#force_display_urgency_hint 2000

for_window [class="mpv"] workspace $workspace9, floating enable, focus
#for_window [class="Spotify"] workspace $workspace10
for_window [class="Gimp"] floating enable
for_window [class="Uzbl-core"] focus child, layout tabbed, focus

bindsym $mod+1 workspace $workspace1, layout splith;
bindsym $mod+2 workspace $workspace2
bindsym $mod+3 workspace $workspace3
bindsym $mod+4 workspace $workspace4, layout tabbed;
bindsym $mod+5 workspace $workspace5
bindsym $mod+6 workspace $workspace6
bindsym $mod+7 workspace $workspace7
bindsym $mod+8 workspace $workspace8
bindsym $mod+9 workspace $workspace9, layout floating;
bindsym $mod+0 workspace $workspace10

bindsym $mod+Shift+1 move container to workspace $workspace1
bindsym $mod+Shift+2 move container to workspace $workspace2
bindsym $mod+Shift+3 move container to workspace $workspace3
bindsym $mod+Shift+4 move container to workspace $workspace4
bindsym $mod+Shift+5 move container to workspace $workspace5
bindsym $mod+Shift+6 move container to workspace $workspace6
bindsym $mod+Shift+7 move container to workspace $workspace7
bindsym $mod+Shift+8 move container to workspace $workspace8
bindsym $mod+Shift+9 move container to workspace $workspace9
bindsym $mod+Shift+0 move container to workspace $workspace10

# resize window (you can also use the mouse for that)
mode "resize" {
        # These bindings trigger as soon as you enter the resize mode

        # Pressing left will shrink the window’s width.
        # Pressing right will grow the window’s width.
        # Pressing up will shrink the window’s height.
        # Pressing down will grow the window’s height.
        bindsym j resize shrink width 10 px or 10 ppt
        bindsym k resize grow height 10 px or 10 ppt
        bindsym l resize shrink height 10 px or 10 ppt
        bindsym semicolon resize grow width 10 px or 10 ppt

        # same bindings, but for the arrow keys
        bindsym Left resize shrink width 10 px or 10 ppt
        bindsym Down resize grow height 10 px or 10 ppt
        bindsym Up resize shrink height 10 px or 10 ppt
        bindsym Right resize grow width 10 px or 10 ppt

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

bindsym $mod+r mode "resize"

bar {
 status_command nice -n19 i3status -c ~/.config/i3/i3status.conf
 position top
 colors {
  statusline #55BB55
 }
}

hide_edge_borders both
workspace_auto_back_and_forth yes

## http://slackword.net/?p=657
#bindsym $mod+z workspace back_and_forth
#bindsym $mod+Shift+z move container to workspace back_and_forth
#bindsym $mod+Shift+z move container to workspace back_and_forth; workspace back_and_forth

bindsym $mod+Tab workspace back_and_forth
bindsym $mod+Shift+Tab move container to workspace back_and_forth

bindsym Mod1+Tab workspace back_and_forth
bindsym Mod1+Shift+Tab move container to workspace back_and_forth

bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -q set Master 2+
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -q set Master 2-
bindsym XF86AudioMute exec --no-startup-id amixer -q set Master toggle

bindsym XF86MonBrightnessUp exec xbacklight -inc 20
bindsym XF86MonBrightnessDown exec xbacklight -dec 20

bindsym $mod+b exec --no-startup-id i3-msg border toggle

bindsym $mod+t exec urxvt -e tmuxj
bindsym $mod+g exec geany, workspace $workspace1;
bindsym $mod+m exec sylpheed, workspace $workspace2;
bindsym $mod+o exec opera
#bindsym $mod+o exec opera, workspace $workspace3;
bindsym $mod+q exec qupzilla, workspace $workspace4;
bindsym $mod+Shift+s exec spotify, workspace $workspace10;

## http://faq.i3wm.org/question/1262/exiting-i3-without-mouse-click.1.html
#bindsym $mod+Shift+e exec sh -c '[ $(echo "NO\nYES" | dmenu -sb "#ff6600" -i -p "Really exit i3 X session?") = "YES" ] && i3-msg exit'

exec --no-startup-id "nice -n19 volumeicon"
exec --no-startup-id "nice -n19 wpa_gui -t"
exec --no-startup-id "nice -n19 dunst"
exec urxvt -e tmux

The default i3status config is ~/.config/i3status/config, but I wanted to keep all my i3 stuff together. There's not much there.. just two files.

$ cat ~/.config/i3/i3status
# i3status configuration file.
# see "man i3status" for documentation.

# It is important that this file is edited as UTF-8.
# The following line should contain a sharp s:
# ß
# If the above line is not correctly displayed, fix your editor first!

general {
 output_format = "i3bar"
 colors = true
 interval = 5
 separator = ""
 color_good = "#55bb55"
 color_bad = "#ff0000"
 color_degraded = "#bbbb00"
}

order += "wireless _first_"
#order += "ethernet _first_"
order += "disk /"
#order += "cpu_temperature 0"
order += "cpu_usage"
order += "load"
order += "volume master"
order += "battery 0"
order += "time"

wireless _first_ {
 format_up = " %bitrate %quality  %essid %frequency"
 format_down = ""
}

ethernet _first_ {
 ## %speed requires root privileges
 format_up = "E %ip %speed"
 format_down = "E"
}

disk "/" {
 format = " %avail"
 prefix_type = "custom"
 low_threshold = "1"
 threshold_type = "gbytes_avail"
}

cpu_usage {
 format = " %usage"
}

load {
 format = " %1min"
}

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

volume master {
 format = " %volume"
 format_muted = " %volume"
 device = "default"
 mixer = "Master"
 mixer_idx = 0
}

battery 0 {
 #format = " %status %percentage %remaining %emptytime %consumption"
 format = " %status %percentage %consumption %remaining"
 format_down = ""
 integer_battery_capacity = "true"
 hide_seconds = true
 status_chr = ""
 status_bat = ""
 status_full = "☻"
 path = "/sys/class/power_supply/BAT%d/uevent"
 low_threshold = 10
 threshold_type = percentage
}

time {
 format = " %b %d %a %R"
}

ref: i3wm Jump Start, by Alex Booker

softvol boost increase alsa volume

One thing I liked with pulseaudio was increasing the volume to more than 100%. Although audiophiles may disagree, I need to increase the volume beyond 100% so I could hear some movies with low sound particularly voice dialogues.

I missed that feature in alsa. It turns out that this is built-in. Not many know about this, and those who do have issues configuring alsa softvol.

After trawling through much www research, this is what works for me. All one needs is a properly configured ~/.asoundrc file.

$ cat ~/.asoundrc
defaults.pcm.!card 0
defaults.pcm.!device 0
defaults.pcm.!ctl 0

pcm.!default {
    type asym
    playback.pcm "plug:softvol"
    capture.pcm "plug:dsnoop"
}
pcm.softvol {
    type softvol
    slave.pcm "dmix"
    control { name "PCM"; card 0; }
    #max_dB 32.0
    max_dB 20.0
    min_dB -5.0
}

Note that this uses PCM as your volume slider. So config your volume hotkeys (or triggers) to manipulate PCM, rather than Master. Set your Master level to 100% or whatever max suitable, and increase/decrease PCM for audio volume.

gentoo portage

ref: http://wiki.gentoo.org/wiki/portage

Gentoo is Portage. Portage is Gentoo.

Getting the portage settings right is vitally important. It's not the end of the world, if you don't. But you sure will expend a lot of your time staring at the matrix flowing past, as you compile everything yet again one more time.. just to get it right.

I have learnt it the hard way.. Each time I learn what not to do, as opposed to in other systems before. Thankfully, the folks at the gentoo forums have been very helpful each time. If not for them, the gentoo journey would probably not have been worthwhile.

Now that I understand a little bit more, I recompile the whole system, during the installation phase itself, right after I extract stage3 and set my environment. Only then do I install those packages required during/post installation.

Starting with a clean slate lessens any starting troubles. The foundation is probably the most important thing to building the rest of our skyscraper.

During installation, I tweak /etc/portage files to my requirements, and run the following command,
# emerge --e @system
# emerge -c

$ man emerge

--emptytree (-e)
Reinstalls target atoms and their entire deep dependency tree, as though no packages are currently installed. You should run this with --pretend first to make sure the result is what you expect.

--depclean (-c)
Cleans the system by removing packages that are not associated with explicitly merged packages. Depclean works by creating the full dependency tree from the @world set, then comparing it to installed packages. Packages installed, but not part of the dependency tree, will be uninstalled by depclean.
See --with-bdeps for behavior with respect to build time dependencies that are not strictly required.

--with-bdeps < y | n >
In dependency calculations, pull in build time dependencies that are not strictly required. This defaults to ´n´ for installation actions, meaning they will not be installed, and ´y´ for the --depclean action, meaning they will not be removed.

For reference, these are my portage files.

$ cat /etc/portage/make.conf
## http://wiki.gentoo.org/wiki/Distcc#With_Portage
## gcc -v -E -x c -march=native -mtune=native - < /dev/null 2>&1 | grep cc1 | perl -pe 's/ -mno-\S+//g; s/^.* - //g;'
CFLAGS="-march=native -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"
CHOST="i686-pc-linux-gnu"
CPU_FLAGS_X86="mmx mmxext sse sse2 sse3 ssse3"

VIDEO_CARDS="i965"
INPUT_DEVICES="evdev synaptics"
#INPUT_DEVICES="libinput"
ALSA_CARDS="hda-intel"
LCD_DEVICES=""

LINGUAS="en_GB en"
L10N="en-GB en"
#PYTHON_SINGLE_TARGET="python2_7"
#PYTHON_TARGETS="python2_7"
RUBY_TARGETS="ruby22"
FFTOOLS=""

PORTDIR="/media/portage"
DISTDIR="/media/distfiles"
#PORTDIR="/usr/portage"
#DISTDIR=${PORTDIR}/distfiles
PKGDIR=${PORTDIR}/packages

#MAKEOPTS="-s -j4 -l2"
MAKEOPTS="--jobs=3 --load-average=2 --silent"
EMERGE_DEFAULT_OPTS="--alert --ask y --ask-enter-invalid --jobs=2 --keep-going y --load-average 2 --quiet n --tree --unordered-display --verbose y --verbose-conflicts --with-bdeps=y"
PORTAGE_NICENESS="19"
PORTAGE_IONICE_COMMAND="ionice -c2 -n7 -p\${PID}"
#PORTAGE_RSYNC_EXTRA_OPTS="--exclude-from=/etc/portage/rsync_excludes"

USE="acpi alsa btrfs drm evdev ffmpeg glamor gstreamer jpeg libnotify minimal opengl png startup-notification threads udev vaapi xcb -X -acl -accessibility -crypt -dbus -debug -deprecated -egl -fortran -gdbm -gnome -gtk3 -introspection -ipv6 -joystick -ncurses -nls -pulseaudio -systemd -xinerama -xv"

$ cat /etc/portage/package.mask
sys-apps/systemd
sys-fs/udev
dev-lang/python:3.4
dev-lang/python:3.5

$ /etc/portage/rsync_excludes
games-*/
sci-*/
dev-ruby/
dev-java/
dev-haskell/

$ cat /etc/portage/profile/use.mask
#-input_devices_libinput

I also replace the package.* directories with files of the same name. For eg,

# cd /etc/portage/
# mv -vi package.use{,.gentoo}
# cat package.use.gentoo/* >>package.use

The currently active USE flags, are the sum of all profiles.
# emerge --info | grep ^USE=

View all portage settings.
# emerge --info

Double check portage settings before starting compile, or it will be recompile everything all over again for each change. Nevertheless and frustratingly, this shall probably happen many times over ;-)
ref: http://wiki.gentoo.org/wiki/handbook:x86/Working/Portage#Updating_the_system

So, we have our settings right, and have rebooted into our gentoo. We probably should update our system.
# emerge --sync
# emerge --update --deep @world

The handbook recommends that we update the build dependencies (packages needed during compile/build process, but no longer required after install), once in a while. I try do this often.
# emerge --update --deep --with-bdeps=y @world

If you have changed any USE settings, portage needs to be told.
# emerge --update --deep --with-bdeps=y --newuse @world

Portage can remove orphaned dependencies, but only after a full update.
# emerge --update --deep --newuse @world
# emerge --depclean
# revdep-rebuild

That last command is from gentoolkit, not part of core gentoo. Another useful tool is eix. Install them like so.
# emerge --ask app-portage/{gentoolkit,eix}

And to remove packages safely:
# emerge --ask --depclean app-portage/eix

ref: http://wiki.gentoo.org/wiki/world_set_(Portage)
emerge -auvND world does not upgrade everything.
emerge -auvND --with-bdeps=yes world will attempt to upgrade build-time dependencies. run once a month or so.
emerge -e system maybe once or twice a year.

dash system & login shell

dash is more efficient than bash in all respects, except perhaps for interactive use. and i always replace system default and login shells with dash.

$ cd /bin
# ln -sf dash sh

# usermod -s /bin/sh root

i faced a particular problem in gentoo.

after the rebooting the just installed system, i couldn't login as root to finish installing the rest of the system. i finally gave up and trashed the system.

i wiped the disk clean, and re-installed yet again from scratch. all i wanted to check was that i could login. what's the purpose of installing a fabulous system, if you can't login? so i left most other install tasks/config for later. i could successfully login!

now i moved on with what i normally do to my systems, just to finish up and find that i could not login!

i rememembered that the last thing i did was to replace my system default and login shells with dash. so i undid that. bash became the default again. and i could login!

the problem was isolated to dash as login shell!

further troubleshooting narrowed down the issue to login shell only. gentoo was fully working with dash as the system default shell.

my research led me to the ever helpful gentoo forums, and this post.

indeed, gentoo does not list /bin/dash in /etc/shells. problem solved!

# echo /bin/dash >>/etc/shells

gentoo second install x86 btrfs debian

Now that my Gentoo Phase 2 has been put on hold for the near future, I have to satisfy this itch to install gentoo on my main laptop. Having it on my primary rig, would allow me to use it more often than pulling out my backup system.

My blind first attempt, at a gentoo install, gave me a lot of confidence in the gentoo community. This second attempt substantially lessens the time/aggro I spent previously installing gentoo.

I significantly pruned the install path from my previous gentoo install process, removing many distractions. I could have just copied over those btrfs subvolumes, but I wanted to start clean.

Beware if you systemd, don't just blindly follow this.

Install Environment

This time I start from my running debian. I have a working environment, networking and x-browser. No faffing about with any install disks etc. And I can continue working without downtime, while gentoo/emerge is crunching cpu/disk.

You may follow this, installing from your own distro.

Partitions

I like btrfs - cow, subvolumes, snapshots. I have subvolumes for each os. I create new ones for this gentoo install, and use a few other existing ones.

# mount -L os /media/os
# btrfs subvolume create /media/os/@gentoo32
# btrfs subvolume create /media/os/@portage

The gentoo handbook refers to /mnt/gentoo. So we mount our subvolumes there.

# mkdir -p /mnt/gentoo
# mount -L os -o defaults,relatime,compress=lzo,subvol=@gentoo32 /mnt/gentoo/

I will use other subvolumes after this install completes to my satisfaction, as I don't want any accidents. This also keeps it simple & straightforward, with everything on one subvolume.

Stage3

Download, verify & extract latest gentoo stage3. I use /tmp as working directory, as we won't need those files later.

$ cd /tmp
$ wget http://distfiles.gentoo.org/releases/x86/autobuilds/current-install-x86-minimal/stage3-i686-{yyyymmdd}.tar.bz2
$ wget http://distfiles.gentoo.org/releases/x86/autobuilds/current-install-x86-minimal/stage3-i686-{yyyymmdd}.tar.bz2.DIGESTS
$ sha512sum -c stage3-*.tar.bz2.DIGESTS
# tar --numeric-owner --xattrs -xvapf stage3-*.tar.bz2 -C /mnt/gentoo/

I downloaded a 228M file, which extracted 860M. So be patient..

Filesystems

mount required psuedo filesystems
# mount -o bind /proc /mnt/gentoo/proc
# mount --rbind /sys /mnt/gentoo/sys
# mount --make-rslave /mnt/gentoo/sys
# mount --rbind /dev /mnt/gentoo/dev
# mount --make-rslave /mnt/gentoo/dev
# mount --rbind /run/shm /mnt/gentoo/run/shm

Anything outside chroot will be inaccessible.

# cp -L /etc/resolv.conf /mnt/gentoo/etc/

Enter the chroot

# chroot /mnt/gentoo /bin/bash
# source /etc/profile
# export PS1="(chroot) $PS1"

my favourite editor :-)
# ln -s /bin/busybox /usr/local/bin/vi

Portage
ref: gentoo portage

Do yourself a favour, and ignore everything the handbook says about portage.. for now!
Learning everything about portage is really really useful, but not during installation. Particularly, if you are a gentoo newbie.

Install the latest portage snapshot, with all the above settings.
emerge-webrsync -q

/usr/portage is created during this first run. Ignore all those warnings..

This will take time.. be patient ;)

News

$ man news.eselect
$ eselect news list
$ eselect news read [number]

Action the relevant news items. Do your own research though. I got news items too old, and although relevant, not completely correct either.

Timezone

$ ls /usr/share/zoneinfo
# echo "Europe/London" >/etc/timezone
# ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

Locales

$ cat /etc/locale.gen
en_GB.UTF-8 UTF-8

Each locale should be on a separate line. Atleast one should be UTF-8.

# locale-gen
$ locale -a
$ eselect locale list
# eselect locale set {number}

$ cat /etc/env.d/02locale

Reload environment, after changes.
$ env-update && source /etc/profile && export PS1="(chroot)$PS1"

Kernel

No kernel is installed. We make our own.
ref: gentoo kernel

I moved the kernel section up ahead this time. While the kernel compiles, we continue the rest of the install..
on another terminal :) Enter chroot, and reload environment.

/etc/fstab

$ cat /etc/fstab

Networking

Gentoo utils are best in class. I use netifrc. Busybox udhcpc automatically for all configured interfaces.

My wireless card wasn't detected without lspci.
$ emerge --search pciutils
# emerge --ask sys-apps/pciutils

Configure interfaces
# ln -s /etc/conf.d/net.{lo,wlp3s0}

I need iw and wpa_supplicant.
ref: wpa_supplicant
# emerge --ask net-wireless/{wpa_supplicant,iw}

# vi /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
update_config=1

# wpa-passphrase {ssid} {password} >>/etc/wpa_supplicant/wpa_supplicant.conf

# vi /etc/conf.d/hostname
hostname="{hostname}"

# vi /etc/hosts
127.0.0.1 localhost.localdomain localhost {hostname}
Misc

keyboard
# vi /etc/conf.d/keymaps

root passwd
# passwd

Bootloader

No bootloaders to be installed in this instance, as I use an existing one and add another entry in wheezy's /etc/grub.d/

menuentry "@gentoo32/vmlinuz" {
  set gfxpayload=auto
  set rtlbl=os
  set subvol=@gentoo32
  search --no-floppy --set root --label $rtlbl
  set bootoptions="root=LABEL=$rtlbl ro rootfstype=btrfs rootflags=defaults,noatime,compress=lzo,subvol=$subvol quiet"
  linux /$subvol/vmlinuz $bootoptions
  initrd /$subvol/initrd.img
}

filesystem:
ensure you have the corresponding filesystem tools.

# emerge --ask sys-fs/btrfs-progs

Don't forget the other terminal.. and finish installing the kernel & initramfs!

Exit the chroot

# exit
# reboot

gentoo phase 2

My first attempt boosted confidence in gentoo (and it's community) beyond expectation. So much that the debian to gentoo transition continues to gather pace.

In all my systems, I have always replaced the full fledged (bloatware?) tools with minimal busybox, wherever I could. Busybox is stable, and fulfils all my requirements rather nicely. This led me to voidlinux which has that same ethos in it's core. It is a great booster that gentoo could satisfy me on this count too.

I am quite a fan of minimal systems. Any features over and above that I actually use is bloatware. A perfect efficient system is one from which you can't take out anything more, rather than one you can't add anything more.

So the next phase of my gentoo adventure continues.. with gentoo uclibc on my main rig. Will this satisfy my minimal tendencies?

Update: Gentoo wiki tells me that uClibc is a dead project now, and migration to uClibc-ng begins 01-Oct-2016. Unfortunately, there is no simple migration path.

So this Phase 2 goes on hold till then, and perhaps a bit later as i watch from the sidelines for initial hiccups. I am not really a fan of bleeding-edge.

debian boot kernel panic

Debian kernel or initramfs seems to have intermittent kernel panic at boot time. I have had these on & off over many kernels/upgrades. Many times, this problem seems to go away after a few hours or days. Till then, I dual-boot one of my other systems.

Initramfs unpacking failed: junk in compressed archive
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
CPU: 1 PID: 1 Comm: swapper/0 not tainted 4.6.0-1-686-pae #1 Debian 4.6.4-1
...
Kernel Offset: disabled
---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

I suspect this happens more with the testing flavours, than with stable. I keep trying occassionally if debian kernel would boot without the kernel panic. If could boot atleast once, then I update my initramfs by

# update-initramfs -uv

Most times, this has resolved the issue.

This time, the problem seems to have continued far longer, probably because I am continuously using the system, and trying to reboot into this kernel very often. I have noticed the problem goes away, if I power off the system and come back after a few hours or days.

So, I tried to boot the alternate kernel /vmlinuz.old. And it booted clean :)

Thus the problem is further narrowed down to the current kernel, in this case linux-image-4.6.0-1-686-pae.

There are two methods to update the initramfs of an installed-kernel on debian systems.

Debian Kernel Handbook recommends
# dpkg-reconfigure linux-image-4.6.0-1-686-pae

Alternatively,
# update-initramfs -u -c 4.6.0-1-686-pae

ref: http://kernel-handbook.alioth.debian.org/ch-initramfs.html#s-initramfs-regen

wpa_supplicant systemd

I still don't prefer systemd, but sometimes you can't avoid demandware. Below is my preferred way to get systemd on wifi. This method now works with all flavours, including debian.

Identify wifi device(s)

$ iw dev
phy#0
        Interface wlp3s0
                ifindex 3
                wdev 0x1
                addr 00:00:00:00:00:00
                type managed
                channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz

Config wifi device

# vi /etc/systemd/network/wlp3s0.network 
[Match]
Name=wlp3s0

[Network]
DHCP=ipv4
IPv6PrivacyExtensions=true

[DHCP]
RouteMetric=20

Config wpa_supplicant

# vi /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf 
[sudo] password for superuser: 
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

Add wifi network(s)

# wpa-passphrase wlan passphrase >> /etc/wpa_supplicant/wpa_supplicant-wlp3s0.conf

Enable relevant systemd services

# systemctl enable wpa_supplicant@wlp3s0
# systemctl enable systemd-networkd

Reboot to test connectivity :)

If this worked, use wpa_gui for a SysTray icon to help manage wifi networks. No need for NetworkManager/Gnome all-singing all-dancing bloatware!

wpa_supplicant dhcpcd systemd debian

The leanest cleanest way to connect to wpa/2 networks is wpa_supplicant. And wpa_gui provides GUI and system tray icon, if needed. All other applications are bloat, building additional layers and complexity. Goodbye Gnome/NetworkManager!

Since moving to systemd chasing the gnome dragons, the debian ecosystem has broken down. Many debian ways of doing things have since become invalid, and systemd ways of doing things need to be understood. This understanding is still not quite clear in any knowledge base, particularly with debian.

In systemd, the cleanest way seems to be the dhcpcd hook automatically invoking wpa_supplicant.

A recent update to Debian Stretch broke wireless connectivity. Researching the issue led to dhcpcd hooks. Apparently, dhcpcd5 continues to provide the wpa_supplicant hook, but removed it as default. The fix was to add back the wpa_supplicant hook to dhcpcd hooks.

The default dhcpcd hooks are located at /lib/dhcpcd/dhcpcd-hooks/
Additional dhcpcd hooks are located at /usr/share/dhcpcd/hooks/

So we
# ln -s /usr/share/dhcpcd/hooks/10-wpa_supplicant /usr/share/dhcpcd/hooks/10-wpa_supplicant

Reboot debian, and verify wireless connectivity.

Interestingly, arch doesn't need this workaround.

Update: I have moved on from dhcpcd, and purged it.

tar backup restore

identify and mount directories/devices for backup sources and targets, i.e.
-- backup, which directory
-- backup, to which file, located where

tar - tape archiver
http://gnu.org/software/tar/manual

$ tar --help
$ man tar

some useful options
-c, --create
create a new archive

-t, --list
list the contents of an archive

-x, --extract, --get
extract files from an archive

-a, --auto-compress
use archive suffix to determine the compression program

-f, --file=ARCHIVE
use  archive file or device ARCHIVE

--numeric-owner
always use numbers for user/group names

--owner=NAME
Force NAME as owner for added files.

--one-file-system 
stay in local file system when creating archive

-p, --preserve-permissions, --same-permissions
extract information about file permissions (default for superuser)

--show-defaults
show tar defaults

-v, --verbose
verbosely list files processed

--xattrs
enable extended attributes support

backup
descend into directory, and tar current directory avoiding absolute pathname risks

$ cd {backup-directory}
$ sudo tar --one-file-system --numeric-owner --xattrs -cvapf /mnt/backup/{backup-filename}.tar.xz .

restore
descend into target directory, and untar

$ sudo tar --one-file-system --numeric-owner --xattrs -xvapf /mnt/backup/{backup-filename}.tar.xz

combine tar with netcat to backup/restore across the network. apparently, it is more efficient as the same system does not need to read & write at the same time.

gentoo kernel compile

I'm doing this so often that I need a ready reference. So here's a post :)

lspci: without it, my wireless card wasn't detected at boot.
$ emerge --search pciutils
# emerge --ask sys-apps/pciutils
$ /usr/sbin/lspci -knnvvv
$ lsmod

source
# emerge --ask sys-kernel/gentoo-sources

compression
There are many opinions about kernel compressions. My research led me to lzo. Is that the most efficient?
If you want to use lzo, you need to install lzop, or your kernel build will fail.
# emerge --ask app-arch/lzop

config
http://wiki.gentoo.org/wiki/Handbook:X86/Installation/Kernel#Activating_required_options
http://wiki.gentoo.org/wiki/Kernel/Gentoo_Kernel_Configuration_Guide

$ cd /usr/src/linux
$ cp -vi {backup}/config .config
$ make oldconfig
$ make nconfig

make
# make -j4 -s && make -j4 modules_install && make install

initramfs
http://wiki.gentoo.org/wiki/initramfs

gentoo wiki doesn't say how to.. just refers genkernel.
gentoo wiki also suggests no initramfs or modules, but including everything in kernel.

I am a fan of micro-kernels, rather than monolithic kernels. I prefer my kernel slim. Anything and everything, not required for initial boot or always in use, stays out of kernel.

I also use btrfs subvolumes, and LABELs in fstab.. so I need initramfs.

# emerge --ask sys-kernel/genkernel
# genkernel --install --no-ramdisk-modules --disklabel initramfs

Firmware:

FIRMWARE_IN_KERNEL=n
The kernel source tree includes a number of firmware 'blobs' that are used by various drivers. The recommended way to use these is to run "make firmware_install", which, after converting ihex files to binary, copies all of the needed binary files in firmware/ to /lib/firmware/ on your system so that they can be loaded by userspace helpers on request.

$ emerge --search firmware
# emerge --ask sys-kernel/linux-firmware


[1] http://wiki.gentoo.org/wiki/kernel/upgrade
[2] http://swift.siphos.be/linux_sea/kernelbuilding.html

This sound device does not have any controls

I have no sound, on my recent gentoo install.

LXQT Mixer wouldn't open. I don't even get any error/warning messages. This is not good.

So I try alsamixer.

$ alsamixer
...
This sound device does not have any controls.

This is not good either, but a bit better than nothing. I have something to work with.

It seems I have a sound device, but alsa can not connect to any controls.

Let's check the kernel driver and modules.

$ lspci | grep -i audio
00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)
$ lspci -knnv -s 00:1b.0
00:1b.0 Audio device [0403]: Intel Corporation 82801I (ICH9 Family) HD Audio Controller [8086:293e] (rev 03)
        Subsystem: Toshiba America Info Systems 82801I (ICH9 Family) HD Audio Controller [1179:ff1e]
        Flags: bus master, fast devsel, latency 0, IRQ 22
        Memory at d6900000 (64-bit, non-prefetchable) [size=16K]
        Capabilities: 
        Kernel driver in use: snd_hda_intel
        Kernel modules: snd_hda_intel

$ lsmod | grep snd
snd_hda_codec_hdmi     32710  1
snd_hda_intel          15445  1
snd_hda_controller     15342  1 snd_hda_intel
snd_hda_codec          59032  3 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_controller
snd_hda_core           16671  3 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_controller
snd_pcm                59428  4 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel,snd_hda_controller
snd_timer              14813  1 snd_pcm
snd                    38556  7 snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_hda_codec,snd_hda_intel
soundcore                656  1 snd

This looks good. It seems like the drivers have been detected, and modules loaded correctly.

What about the sound codecs?

$ lsmod | grep codec
snd_hda_codec_hdmi     32710  1
snd_hda_codec          59032  3 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_controller
snd_hda_core           16671  3 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_controller
snd_pcm                59428  4 snd_hda_codec_hdmi,snd_hda_codec,snd_hda_intel,snd_hda_controller
snd                    38556  7 snd_timer,snd_hda_codec_hdmi,snd_pcm,snd_hda_codec,snd_hda_intel

It looks like the hda codecs have been loaded. But are they the right ones?

$ cat /proc/asound/card*/codec* | grep -i codec
Codec: Realtek ID 268
Codec: Motorola ID 3055

This sound card has two codes, as detected above. And they are..

Aha, we found the problem. Intel HDA Audio doesn't want Intel HDA Codecs. The required HDA Codecs are Realtek and Motorola.. hmm??

$ /sbin/modprobe -c | grep -i realtek
nothing!

$ /sbin/modprobe -c | grep -i motorola
nothing!

Hmm.. my kernel config may be suspect. We need to check.

$ cat /boot/config-`uname -r` | grep -i codec | grep -i realtek
# CONFIG_SND_HDA_CODEC_REALTEK is not set

The required RealTek codec is unset. It has not been compiled.

We need to select SND_HDA_CODEC_REALTEK, and rebuild kernel.

What about Motorola codec?

$ cat /boot/config-`uname -r` | grep -i codec | grep -i motorola
nothing!

The kernel doesn't even know about the Motorola codec. I guess, there is nothing much we can do here.

Let's hope the RealTek codec might be sufficient for now.. We may be able to ignore the Motorola codec.

Next, we reconfig & rebuild our gentoo kernel..
ref: Gentoo Kernel compile

$ cd /usr/src/linux
$ make nconfig

> Device Drivers > Sound card support > Advanced Linux Sound Architecture > HD-Audio > SND_HDA_CODEC_REALTEK

Rebuild and install the kernel, modules and/or initramfs.

ref: gentoo kernel compile

# make && make modules_install && make install
# genkernel --install --no-ramdisk-modules --disklabel initramfs

Verify the new kernel & initramfs are in /boot.

$ ls -lh /boot/
yes!

Depending on your bootloader, you may need to regenerate (grub2) or reinstall (lilo). Check, and reboot.

System boots up.. I login and check sound. Yes, it works!

Now we can enjoy that sweet sound :)

gentoo install x86 btrfs

this post is for my reference. you may use this as a quick guide. but please understand what i have done, and not blindly copy. you should definitely read the much more comprehensive gentoo install handbook.

x86 install handbook: wiki.gentoo.org/wiki/handbook:x86
alternative install: wiki.gentoo.org/wiki/installation_alternatives
download: distfiles.gentoo.org/releases/x86/autobuilds/current-install-x86-minimal
sysresccd: sysresccd.org

i'll quickly run through the various handbook sections, and how i adapted those.

install media

gentoo suggests install from bootcd, and also offers many alternatives. i'm most impressed by the wildly flexible options available, and documented!

i have a sysresccd usb bootable. so i skip the download/create bootcd.

sysresccd startx, networkmanager, midori.. open new tabs with this page and gentoo handbook. keep them handy during the installation.

partitions

i don't usually use swap. anything that is a memory hogger is either tolerated, or purged off asap. i'm always looking for smaller applications to replace whatever i currently use. any more features than i use is bloatware.

i used to have /tmp on a dedicated partition. now i just use tmpfs, or a raw file if need be.

i have a large btrfs data partition, and i wanted to add another subvolume for gentoo. but i had second thoughts, as this was to be my first time with gentoo, and i didn't want accidents with existing data.

i created another btrfs partition, with two subvolumes - @gentoo32 and @home. if this works and is stable, i can send these subvolumes to my main btrfs partition.

sysresccd has /mnt/gentoo. if not, we create that directory for our gentoo root.

# mkdir -p /mnt/gentoo/
# mount -L gentoo -o subvol=@gentoo32 /mnt/gentoo

gentoo stage3

$ date

now we are ready for gentoo stage3, which we download from the above link, verify, and extract.
# sha512sum -c stage3-*.tar.bz2.DIGESTS
# tar --numeric-owner --xattrs -xvapf stage3-*.tar.bz2 -C /mnt/gentoo

filesystems

physical filesystems
# mount -L gentoo -o subvol=@home /mnt/gentoo/home

psuedo filesytems
# mount -o bind /proc /mnt/gentoo/proc
# mount --rbind /sys /mnt/gentoo/sys
# mount --make-rslave /mnt/gentoo/sys
# mount --rbind /dev /mnt/gentoo/dev
# mount --make-rslave /mnt/gentoo/dev

gentoo handbook says "--make-rslave operations are needed for systemd support later". if so, we probably don't need these.

on non-gentoo install media, check /dev/shm and /run/shm
$ ls -lhid /dev/shm /run/shm
$ mount | grep shm

links outside chroot become invalid. making /dev/shm/ a proper tmpfs mount can fix this.
# rm /dev/shm && mkdir /dev/shm
# mount -t tmpfs -o nosuid,nodev,noexec shm /dev/shm
# chmod 1777 /dev/shm
# mount --rbind /run/shm /mnt/gentoo/run/shm

# cp -L /etc/resolv.conf /mnt/gentoo/etc/

enter the chroot

# chroot /mnt/gentoo /bin/bash
# source /etc/profile
# export PS1="(chroot) $PS1"

i prefer busybox vi
# ln -s /bin/busybox /usr/local/bin/vi

portage
http://wiki.gentoo.org/wiki/Handbook:X86/Working/Portage

# mirrorselect -i -o >>/etc/portage/make.conf

# vi /etc/portage/make.conf
ref: make.conf.example / gentoo wiki

CFLAGS
CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"

MAKEOPTS
MAKEOPTS="-j2"

install portage snapshot
# emerge-webrsync

/usr/portage is created on first run. ignore those errors.

sync is not necessary, as portage is not updated more than once a day.
# emerge --sync --quiet --verbose

--quiet is faster, and quieter ;)
--verbose tells you what is happening
in this case, use both together ;) as they mean different things in gentoo

always keep up with the news
$ man news.eselect
$ eselect news list
$ eselect news read [number]

profiles
# eselect profile list

Available profile symlink targets:
  [1]   default/linux/x86/13.0 *
  [2]   default/linux/x86/13.0/desktop
  [3]   default/linux/x86/13.0/desktop/gnome
  [4]   default/linux/x86/13.0/desktop/kde

do yourself a favour, and select [1] the default.

i thought i was smart, and chose [2] desktop, which changed subsequently on it's own, due to something i changed somewhere else. i ended up with quite a lot of bloatware, which in itself is not so much a problem, if i didn't have to wait around half the day for all that lot to be compiled all over again :/ and then i had another issue wondering how to get rid of all that extra bloat.

# eselect profile set 1

keep checking your profile occassionally!

USE
this is the bit which gave me the most headache.. even changing my profile without me knowing about it. choose wisely!

full description of available use flags
$ less /usr/portage/profiles/use.desc
http://gentoo.org/support/use-flags

currently active use flags are a combination of your profile and configured flags in make.conf

$ emerge --info | grep ^USE

$ grep USE /etc/portage/make.conf

keep it default or ignore, till you understand a bit more..
USE=""
USE="-debug -gnome -systemd "

once you understand it, ignore defaults and manage it specifically. but not yet!
USE="-* unicode"

systemd
http://wiki.gentoo.org/wiki/Gentoo_Without_systemd
"Masking udev will not result in a broken system; Portage is smart enough to automatically replace udev by sys-fs/eudev: the systemd-free fork of udev."

i don't want systemd. so i do both.

block:
vi /etc/portage/make.conf
USE="-systemd"

mask:
vi /etc/portage/package.mask/systemd
sys-apps/systemd
sys-fs/udev

timezone

$ ls /usr/share/zoneinfo
# echo "Europe/London" >/etc/timezone
# emerge --config sys-libs/timezone-data

i prefer
# ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime

locales

vi /etc/locale.gen
en_GB.UTF-8 UTF-8

you can have more than one locales. each on separate lines. ensure at least one is utf-8.

# locale-gen
# locale -a
# eselect locale list
# eselect locale set {number}

$ cat /etc/env.d/02locale

reload environment, after any changes
$ env-update && source /etc/profile

kernel

no kernel is installed by default. make and install your own kernel.
ref: gentoo kernel compile

fstab
# vi /etc/fstab

networking
we will use gentoo netifrc method

# emerge --search netifrc

identify network interface, and autostart after boot.
ip link
# ln -s /etc/init.d/net.{lo,eth0}
# rc-update add net.eth0 default

busybox/udhcpc will be used automatically.

# vi /etc/conf.d/hostname
hostname="{localhostname}"

# vi /etc/hosts
127.0.0.1 localhostname.local.domain.name localhost

root passwd
# passwd

init/boot conf
# vi /etc/rc.conf
# vi /etc/conf.d/keymaps

misc
# emerge --ask sys-fs/btrfs-progs
# rc-update add sshd default

bootloader
whew! final stage.. before you can reboot.. into your shiny new gentoo :)

lilo or syslinux or grub2.. ordered by bloatware factor exponentially!

lilo is the most efficient, but doesn't understand btrfs :(
# emerge --ask sys-boot/lilo
# vi /etc/lilo.conf
# /sbin/lilo

extlinux is my preferred choice, but doesn't understand btrfs subvolumes/compression :(
# emerge --ask sys-boot/syslinux
# mkdir /boot/extlinux
# extlinux --install /boot/extlinux
# ln -snf . /boot/boot

# cd /usr/share/syslinux
# cp menu.c32 memdisk libcom32.c32 libutil.c32 /boot/extlinux/
i prefer ln -s, as it keeps up with any system updates.
# ln-s /usr/share/syslinux/{menu.c32,memdisk,libcom32.c32,libutil.c32} /boot/extlinux/

# vi /boot/extlinux/extlinux.conf

note: extlinux expects /boot on the root subvolume.
# mount -o bind /@gentoo32/boot /boot

grub2 is the biggest & most complicated beast.. my last preference. if you ever need to troubleshoot, you'll cry.. :'(
# emerge --ask sys-boot/grub
# grub2-install /dev/{partition}
# grub2-mkconfig -o /boot/grub/grub.cfg

the end
you could just ctrl+alt+del. a stable system would sync to disk, umount all filesystems, before calling reboot.
or be safe..

exit chroot
# exit

unmount and reboot..
# cd
# umount -l /mnt/gentoo/dev{/shm,/pts,}
# umount /mnt/gentoo{/boot,/sys,/proc,}
# reboot


update: i successfully managed to prune this install path quite significantly. see my latest post: gentoo second install x86 btrfs debian

gentoo first attempt

i finally decided to jump in, and created another btrfs partition for gentoo with two subvolumes. with btrfs i don't have anything on the root subvolume.

i really didn't expect an install to drag on for so long. i don't like to give up part-way, unless i feel it is a lost investment. and i was losing it. i would have, but for some kindly folks on the gentoo forum. the gentoo forum is one of the most responsive and helpful forums i have been in.

i made some major mistakes.. some inadvertantly, and many due to my misunderstanding of gentoo portage. what made it exponentially troublesome was the long compile times to try and get back the system to what i thought would be the normal. what made it worth continuing was the folks on the gentoo forum, and the extremely detailed online documentation.

one thing which i find disturbing is the diskspace requirement mentioned in the docs, and the discrepancy i find in my own experience. some others on the forum seem to be using many times over what i have ended up using. not comforting..

the other thing was watching the screen flash past too quickly for me to read anything useful, and too long for me doing nothing but stare at it hoping it will finish in another moment.

i was determined not to give systemd/udev a leg in here, and was chuffed that i could block/mask them out. i had a working eudev.

but all good things come to an end too.. so at the end of a very long day and an almost sleepless night.. early morning found me holding a shiny new gentoo install with lqxt :)

i was chuffed that my first reboot was a success! there weren't any visible errors.

however all was not well in my gentoo land. i think i borked the kernel config, and lsmod lists only two modules. i couldn't bring up my wifi interface. but ethernet worked. i could go online. i had lxqt running with qupzilla :)

but the toll of this looong time spellbound watching matrix flow through my screen has been a bit too much. i don't have enough energy left to celebrate my euphoria, or document my install notes. i have to leave gentoo land now for some zzz..

multiboot btrfs subvolumes

there's an idea knocking around in my head for a while. and i want to document it here, to flush it out later..

i usually multiboot, and have several systems on the same disk. my currently laptop has 12 partitions. each os is fully contained within a partition, including the bootloader on pbr. mbr is clean. partitions are efficient in one way, but scatter diskspace in another way.

half of these dozen partitions have btrfs. and i haven't had any trouble, apart from newer versions not being backward compatible. for eg, wheezy can not access the stretch btrfs, due to some new features. but bleeding-edge stretch, ubuntu, and arch can access all other btrfs partitions.

gentoo docs gave me this idea, but it was ubuntu which made it practical. the default ubuntu install created two subvolumes, one for root and another for home. whatif i create more subvolumes and install other os in each subvolume. would they coexist together on the same partition, albeit different subvolumes? and still keep them separate? i think so.

one major risk would be an install wanting to format the partition. that might wipe all subvolumes in that partition.

i could keep a separate btrfs partition for installing, and post-install copy to a relevant new subvolume in my main btrfs partition.

i would have to keep a separate btrfs partition for each os which doesn't have the bleeding-edge btrfs. all the ones on bleeding edge could be lumped in the same partition on different subvolumes.

i did a quick search to check whether someone else has tapped this/similar idea from the collective consciousness ;)
yes they have :) and i can learn from their experience

ref:

debian to gentoo

as debian builds more & more complexity/layers obscuring internals from users, i get more & more disillusioned by the current crop of debian decision-makers. jessie, the current debian stable seems no longer stable, with an unstable init at it's core.

wheezy is/was the last stable version gone oldstable now. oldstable is expected to be even more stable than stable. but recent updates have littered wheezy with systemd and ubuntu code including upstart. even oldstable has had more than a few days downtime recently, due to buggy updates. sad for debian :(

i used to like arch. but i'm very much not into bleeding edge! hence wheezy :)

i think i'll keep my debian locked on oldstable now.

my wheezy setup is very bare. most debian components have been ripped out, and replaced with busybox or bsd alternatives which are much leaner, cleaner & simply more efficient. going forward:
syslinux
btrfs
runit (like in void)
busybox (like in alpine)
jwm

my search for debian alternatives continues.. many iterations of back & forth.. and now looking towards gentoo. i guess i'm on a quest towards leaner cleaner systems.. further embracing unix philosophy.

gentoo

i'm awed at how flexible & open gentoo wants to be! and very inspired by the gentoo philosophy & social contract.

gentoo install handbook: http://wiki.gentoo.org/wiki/handbook:x86
read all of it. skim through what you don't understand, but don't skip any parts.
now read again the bits you find interesting.
finally read all of the installation section. if you didn't understand any part, re-read it or research elsewhere till all makes sense.
if not, gentoo is not for you!

http://distfiles.gentoo.org/releases/x86/autobuilds/current-install-x86-minimal/
download two files: install-x86-minimal-{date}.iso stage3-i686-{date}.tar.bz2

gentoo suggests install from bootcd. but many alternative install methods are also offered. i'm most impressed by the wildly flexible options available, and documented! seems like they care, and i feel like i want to put my lot behind them..

bios acpi dsdt

bios: basic input/output system
acpi: advanced configuration power interface
dsdt: differentiated system description table
wheezy32: debian wheezy 32bit
arch32: arch 32bit

toshiba bios seem to be one of the most notorious and worst broken. do not choose toshiba for anything but windows, and even with that be careful. dodgy bios implementations are like broken foundations to build your home, if you want to live there yourself!

identify

so how do you identify, if your bios is broken/buggy? check kernel logs:
$ dmesg -l err
toshiba_acpi: Error reading LCD brightness
indicates direction of problems. this error points towards a buggy implementation of acpi by toshiba.

$ dmesg | grep DSDT
ACPI: DSDT 0x00000000B7CEF000 095BA (v01 TOSINV TOSINV00 00000001 MSFT 01000013)
TOSHIBA Satellite detected - force copy of DSDT to local memory
ACPI: Forced DSDT copy: length 0x095BA copied locally, original unmapped
ACPI: EC: Look up EC in DSDT
indicates that bios data is (used as original, forced) not overidden.
msft indicates that toshiba bios is specific to microsoft, particular to a windows version.
poor strategy, unless they were paid-off by microsoft.

confirm

how do you confirm whether bios provided data is usable? decompile & recompile.
a successful recompile, no errors/warnings indicates a good bios! and this has nothing to do with any operating system.

we need iasl, for this purpose.

$ apt-cache show iasl
Description: Intel ASL compiler/decompiler
 iASL compiles ASL (ACPI Source Language) into AML (ACPI Machine
 Language). This AML is suitable for inclusion as a DSDT in system
 firmware. It also can disassemble AML, for debugging purposes.
Homepage: http://acpica.org
# apt-get install iasl
$ iasl -h

$ cd /tmp
$ sudo cat /sys/firmware/acpi/tables/DSDT >dsdt.dat
$ iasl -d dsdt.dat
$ iasl -tc dsdt.dsl
the first command reads the dsdt data. do it as root.
the second command decompiles this .dat into .dsl
the third command attempts to compile, thereby generating the errors/warnings we are looking for.

i see this on wheezy32
$ iasl -tc dsdt.dsl
Intel ACPI Component Architecture
ASL Optimizing Compiler version 20100528 [Jul  2 2010]
Copyright (c) 2000 - 2010 Intel Corporation
Supports ACPI Specification Revision 4.0a

dsdt.dsl  3401:                     0x00000000,         // Length
Error    4122 -                              ^ Invalid combination of Length and Min/Max fixed flags

dsdt.dsl  3408:                     0x00000000,         // Length
Error    4122 -                              ^ Invalid combination of Length and Min/Max fixed flags

dsdt.dsl  7148:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7165:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7214:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7231:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7275:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7489:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7506:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7523:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7540:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  7557:                         Name (_PLD, Buffer (0x10)
Error    4080 -          Invalid object type for reserved name ^  (found BUFFER, requires Package)

dsdt.dsl  8873:                     Method (_GTM, 0, NotSerialized)
Warning  1088 -                                ^ Not all control paths return a value (_GTM)

dsdt.dsl  8873:                     Method (_GTM, 0, NotSerialized)
Warning  1081 -                                ^ Reserved method must return a value (Buffer required for _GTM)

dsdt.dsl  9033:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9033:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl  9101:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9101:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl  9174:                     Method (_GTM, 0, NotSerialized)
Warning  1088 -                                ^ Not all control paths return a value (_GTM)

dsdt.dsl  9174:                     Method (_GTM, 0, NotSerialized)
Warning  1081 -                                ^ Reserved method must return a value (Buffer required for _GTM)

dsdt.dsl  9334:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9334:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl  9402:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9402:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl  9507:                     Method (_GTM, 0, NotSerialized)
Warning  1088 -                                ^ Not all control paths return a value (_GTM)

dsdt.dsl  9507:                     Method (_GTM, 0, NotSerialized)
Warning  1081 -                                ^ Reserved method must return a value (Buffer required for _GTM)

dsdt.dsl  9667:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9667:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl  9735:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9735:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl  9808:                     Method (_GTM, 0, NotSerialized)
Warning  1088 -                                ^ Not all control paths return a value (_GTM)

dsdt.dsl  9808:                     Method (_GTM, 0, NotSerialized)
Warning  1081 -                                ^ Reserved method must return a value (Buffer required for _GTM)

dsdt.dsl  9968:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl  9968:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

dsdt.dsl 10036:                         Method (_GTF, 0, NotSerialized)
Warning  1088 -                                    ^ Not all control paths return a value (_GTF)

dsdt.dsl 10036:                         Method (_GTF, 0, NotSerialized)
Warning  1081 -                                    ^ Reserved method must return a value (Buffer required for _GTF)

ASL Input:  dsdt.dsl - 10111 lines, 370896 bytes, 4450 keywords
Compilation complete. 12 Errors, 24 Warnings, 0 Remarks, 37 Optimizations

12 errors, 24 warnings, i.e. not good!
i get the same results on arch32 too.. so don't go blaming wheezy32!

most popular posts