Schlagworte: ubuntu
03.06.12
Use hybrid suspend method by default with pm-utils/Linux (suspend to RAM and disk)
There is this nice method of suspending a computer to RAM (which is quick to suspend and resume, but still uses some battery) and after a given amount of time to disk, if it has not been waken up since then (e.g. after 15 minutes).
Ubuntu (and any other distribution using pm-utils) supports this via the pm-utils package and its pm-suspend-hybrid script.
Unfortunately this is not used by default (even hibernation is not available from the menu by default), but only normal suspend.
The following configuration snippet will make pm-utils use the "suspend_hybrid" method instead of "suspend" when being invoked:
You have to create a file like /etc/pm/config.d/00-use-suspend-hybrid and add the following code (e.g. via sudo -e /etc/pm/config.d/00-use-suspend-hybrid):
Code:
# Always use suspend_hybrid instead of suspend | |
if [ "$METHOD" = "suspend" ]; then | |
METHOD=suspend_hybrid | |
fi |
I came up with this solution after having asked for a method to do so at Ask Ubuntu.
This way hybrid suspend will be used automatically if you select e.g. "Suspend" from the menu or close your laptop's lid (both actions call pm-suspend which then gets remapped).
You can configure the amount of time before hibernation (Suspend To Disk) is being invoked with the PM_HIBERNATE_DELAY variable (in seconds), which you can just configure in the same file, too:
Code:
# Always use suspend_hybrid instead of suspend | |
if [ "$METHOD" = "suspend" ]; then | |
METHOD=suspend_hybrid | |
fi | |
PM_HIBERNATE_DELAY=300 # invoke hibernation to disk after 5 minutes (300 seconds) |
You might want to make sure that the hybrid method is supported on your system via the following code. If it says "0" it should work:
Code:
sudo pm-is-supported --suspend-hybrid && echo $? |
Happy suspending.
15.09.11
Disable disk cache in Chromium / Google Chrome
There is no user interface in Google's browser Chrome yet to disable the disk cache, or control its size (version 14 appears to have something in the developer tools section).
But it can be done using command line options when starting the browser, and you can configure this globally for Ubuntu.
The following command line flags will use /dev/null ("the sink") as cache dir, and additionally limits it to 1 byte:
--disk-cache-dir=/dev/null --disk-cache-size=1
(I have tried just --disk-cache-size=0 or 1, but it did not appear to work as expected)
On Ubuntu/Debian, you can just add these flags to the CHROMIUM_FLAGS variable in /etc/chromium-browser/default and it will be used every time when starting Chromium.
The motivation to do this comes from me using a local (intercepting) HTTP proxy with its cache on a RAM disk. Therefore I do not want Chromium to store quite the same retrieved files on disk again.
Additionally, this is a SSD, which is not that happy about being written to in general.
Therefore /tmp is a tmpfs mount already, and the same should be the case for temporary browser files.
26.02.11
Puppet definition to add Launchpad PPA repository
Link: https://gist.github.com/844735
The provided puppet definition(s) will allow you to add a PPA repository on a host managed by Puppet, e.g. by means of a class like this:
Code:
class blueyedppa { | |
pparepo { "blueyed/ppa": apt_key => "7CC17CD2" } | |
} |
I have created this to easily add the Current BOINC releases PPA to one of my hosts, and refactored a previously snippet for this.
Since I could not find anything for this, but questions asked about it, I like to share this. The actual code is available at the Gist linked to by this post.
18.08.10
Reinstall Debian init.d scripts into default runlevels
The following zsh snippet allows you to re-install any missing startup/init.d links.
This can be useful/required when e.g. installing an upstart based distribution (like Ubuntu Lucid) has removed some of those, and you want them back after downgrading to Hardy or switching to Debian testing (like I just did).
(apt-get install --reinstall won't bring back those links; you would have to purge (apt-get purge) and reinstall the package instead, removing any other configuration of the package though)
It basically looks for any init scripts that are not present in /etc/rc?.d/S* and then looks at the packages' postinstallation script for an update-rc.d command.
It will not install anything, but only output them (and allows you to pipe it into "sh" for execution).
Worked fine on my "messed up" system, but has rather odd results on my Maverick desktop.
Code:
for i in /etc/init.d/* ; do | |
a=( /etc/rc?.d/S*$i:t(N) ); | |
((${#a})) && continue; | |
package=$(dpkg -S $i 2>/dev/null |cut -d: -f1); | |
[[ -z $package ]] && continue; | |
echo "# $i: $package"; | |
grep "update-rc\.d $i:t" /var/lib/dpkg/info/$package.postinst; | |
done |
(in case you need to extract the init script altogether, the following might help for starters:
dpkg-deb --extract /var/cache/apt/archives/$PACKAGE.deb /tmp/foo.)
21.05.10
Useful wrappers for apt-get, apt-source and apt-file
Link: https://github.com/blueyed/oh-my-zsh/blob/master/plugins/apt/apt.plugin.zsh
I've finally started to manage the setup of my dotfiles (configuration files) for shell, editor etc.
It is based on the popular dotfiles repository of ryanb and my fork can be found at github:blueyed/dotfiles.
While I'm still in the process of setting this up, I've just added the apt-* helpers I wrote some years ago:
They provide neat things like asrc -g hardy hello to get the version of the "hello" package from hardy (via "apt-get source" and the version number grepped from "apt-cache madison" - so you need to have it in your apt sources list, of course).
Also, ashow -g testing hello will show the package from Debian testing.
Apart from that these are mostly aliases, like "aup" for "sudo apt-get update" and some of them support shell completion (of package names) for e.g. "ainst" ("sudo apt-get install"). Shell completion works in both zsh and bash (at least).
You can get the file (to be sourced in a shell) from:
https://github.com/blueyed/oh-my-zsh/blob/master/plugins/apt/apt.plugin.zsh.
Feedback is very welcome and I am sure some of this is in packages like debian-goodies already (actually, there's nothing like that in _that_ package, but..).
Does it make sense to add (parts of) it to some package for easy installation across Debian/Ubuntu?
18.12.09
Convert etckeeper repository from Bazaar to Git
Quite a while ago I've installed etckeeper and changed the configuration to use Bazaar as its backend for myself (and sponsored/helped with a patch to change the default in Ubuntu).
However, already the first comment asked me why I would be using you Bazaar, if Git was that much faster (and required less space).
At that time I've thought, that Bazaar would catch up, and they (luckily) have done so in some areas, but Git is still a lot faster.
Therefore I've decided to change the repository from bzr to git. I've done so on my home machine and will do so on my dedicated server boxes in the next days, so it's a not only a recommendation but also documentation.
Howto convert a bzr repository to git (etckeeper)
Open a root shell, then you should export $GIT_DIR first:
export GIT_DIR=/etc/.git
The following will then convert /etc from a bzr to a git repository ("fast-export" is included in bzr-fastimport - you may have to install this first):
bzr fast-export --export-marks=$GIT_DIR/bzr.mark /etc | git fast-import --export-marks=$GIT_DIR/git.mark
After this (which will take a while depending on your history) you want to adjust the VCS setting in etckeeper.conf (uncomment VCS=git and comment VCS=bzr):
sed -i -r -e s/'#\s*(VCS="git)"'/'\1'/ -e s/'VCS="bzr"'/'# \0'/ /etc/etckeeper/etckeeper.conf
I don't remember correctly, but the Git repository was not really setup correctly in the end - but the following fixed it:
etckeeper init
Benchmarks
I've done some benchmarking, comparing "$DVCS status" against each other. This will look if there are any files modified in the current tree, and it's what etckeeper does before and after upgrading (IIRC).
The following shows the commands with cold and warm caches (I've cleared the disk caches when changing to a new set).
What you can see is not only that "git status" is twice as fast with a cold cache (and even more with a warm one), but also that bzr takes even more time to print a single line of "It sure does!".
$ sudo time git st
0.01user 0.04system 0:05.61elapsed 1%CPU (0avgtext+0avgdata 0maxresident)k
29232inputs+688outputs (113major+1605minor)pagefaults 0swaps
$ sudo time git st
0.02user 0.02system 0:00.06elapsed 59%CPU (0avgtext+0avgdata 0maxresident)k
16inputs+688outputs (0major+1716minor)pagefaults 0swaps
$ sudo time bzr st
0.14user 0.06system 0:11.74elapsed 1%CPU (0avgtext+0avgdata 0maxresident)k
17840inputs+8outputs (36major+3750minor)pagefaults 0swaps
$ sudo time bzr st
0.16user 0.03system 0:00.32elapsed 62%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+3787minor)pagefaults 0swaps
$ sudo time bzr rocks
It sure does!
0.20user 0.05system 0:08.19elapsed 3%CPU (0avgtext+0avgdata 0maxresident)k
17392inputs+8outputs (34major+3422minor)pagefaults 0swaps
$ sudo time bzr rocks
It sure does!
0.16user 0.01system 0:00.20elapsed 92%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+3458minor)pagefaults 0swaps
I'll update this post when scripting for the update of my various OpenVZ containers, but the basic information should stand.
From now on, I will save 5+ seconds on any "aptitude safe-upgrade". Hopefully this multiplies somehow, so the time investment into this post pays back.. ![]()
14.10.09
HAL configuration for Kingsis Peripherals Evoluent VerticalMouse 3
To configure my Kingsis Peripherals Evoluent VerticalMouse 3, I've added the following fdi (HAL configuration info) to /etc/hal/fdi/policy/evoluent-verticalmouse3.fdi:
XML:
<?xml version="1.0" encoding="ISO-8859-1"?> | |
<deviceinfo version="0.2"> | |
<device> | |
<match key="info.capabilities" contains="input.mouse"> | |
<match key="input.product" string="Kingsis Peripherals Evoluent VerticalMouse 3"> | |
<merge key="input.x11_driver" type="string">evdev</merge> | |
<merge key="input.x11_options.Emulate3Buttons" type="string">no</merge> | |
<merge key="input.x11_options.EmulateWheelButton" type="string">0</merge> | |
<merge key="input.x11_options.ZAxisMapping" type="string">4 5</merge> | |
<merge key="input.x11_options.ButtonMapping" type="string">1 2 2 4 5 6 7 3 8</merge> | |
</match> | |
</match> | |
</device> | |
</deviceinfo> |
The most important part (for me) here is ButtonMapping: by default only the wheelbutton triggers middle click, but since it's rather hard to press (and I use it often for pasting), I've mapped it to the middle button on the right side, too.
Also, the thumb button becomes "Back" (in browsers) and the lowest button on the right triggers the context menu.
Update: This was meant to included in Ubuntu Karmic (see bug 451729), but then got removed again (not everybody liked it).
Update^2: for udev (which is used solely since Ubuntu Lucid), I've transformed it into the following file (which you can store as /etc/udev/rules.d/90-local-xorg.rules):
Code:
ACTION!="add|change", GOTO="xorg_local_end" | |
KERNEL!="event*", GOTO="xorg_local_end" | |
| |
ENV{ID_INPUT_MOUSE}!="1", GOTO="xorg_local_end" | |
ENV{ID_MODEL}!="Evoluent_VerticalMouse_3", GOTO="xorg_local_end" | |
| |
ENV{x11_options.Emulate3Buttons}="no" | |
ENV{x11_options.EmulateWheelButton}="0" | |
ENV{x11_options.ZAxisMapping}="4 5" | |
ENV{x11_options.ButtonMapping}="1 2 2 4 5 6 7 3 8" | |
| |
LABEL="xorg_local_end" |
(see also https://wiki.kubuntu.org/X/InputConfiguration for more information)
Update^3: This is bugged in Ubuntu Lucid.

