Posts Tagged ‘ubuntu’

Remove annoying update pop-ups from Ubuntu Oneiric(12.04)

Saturday, August 25th, 2012

Open /etc/xdg/autostart/update-notifier.desktop, find NoDisplay and edit it to false.

154
155
156
157
158
159
160
161
162
163
...
Icon=update-notifier
Exec=update-notifier
Terminal=false
Type=Application
Categories=
NotShowIn=KDE;
NoDisplay=false
X-GNOME-Autostart-Delay=60
X-Ubuntu-Gettext-Domain=update-notifier

Update-notifier will then show up in the application gnome-session-properties, where it can be disabled. When disabled, a modified version of update-notifier.desktop is written to ~/.config/autostart/.

Manual recovery from Windows 7 System Image Backup(VHD) using Ubuntu/Linux

Sunday, July 1st, 2012

Windows 7 system image backup saves the whole windows partition in raw format inside a VHD-file(Virtual Hard Disk). The VHD format is also used in virtual environments, as Hyper-V and Virtualbox. Unfortunately Windows system restore is limited in the capability to restore to another disk layout. But with the use of vdfuse in virtualbox-fuse(universe) it's possible to restore the partitions manually with a Ubuntu Live system. Then you are in complete control yourself, disk layout etc.

This was done to restore a system disk(crashed SSD) to a regular hard drive which was already in use (contained the backups). The partition on the regular hard drive was moved to make room for the system partitions in the beginning, and the backup was mounted through vdfuse and restored with dd.

Walk through
Prepare a Ubuntu Live system(USB, cdrom, etc) and boot it. Partition the new disk with GParted. In my special case, I moved my existing partition to the right/end of disk. Then I noted the new placement:

1
sudo fdisk -l /dev/sdb

I'm not sure where Windows system image stores (if it does) the MBR, but you could search through the WindowsImageBackup folder for a file of 512 bytes. Most likely, it manually creates the partitions and writes a fresh boot sector. This can also be done by creating the partitions and using a Windows install disc/USB to repair the startup. There should be a 100MB "System reserved" primary partition with bootflag enabled, and the Windows partition itself. Here I just copy the working MBR from the crashed disk:

1
2
MAKE SURE YOU KNOW WHICH HARD DRIVE IS WHICH BEFORE USING DD
sudo dd if=/dev/sda of=/dev/sdb bs=512 count=1

Then I added the already moved partition (the data is still there, we just lost the reference to the partition when moving MBR from sda to sdb).

1
sudo fdisk /dev/sdb

If you haven't a moved a partition, skip this step: Reboot computer, use an Windows install disk to check the integrity of the moved partition (chkdsk), when done boot Ubuntu again.

Add universe to apt sources(/etc/apt/sources.list):

1
2
3
4
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu/ precise universe

archive.ubuntu.com can be replaced with your local mirror. Usually the local mirror is named XX.archive.ubuntu.com, where XX is your country code (no for Norwegian -> no.archive.ubuntu.com).
Update apt and install virtualbox-fuse:

1
2
sudo apt-get update
sudo apt-get install virtualbox-fuse

Mount the partition which contains the backup (WindowsImageBackup directory). Find the VHD-files. Create two empty directories and mount the VHD-files(read only):

1
2
3
4
sudo mkdir /media/f1
sudo mkdir /media/f2
vdfuse -r image-file1.vhd /media/f1
vdfuse -r image-file2.vhd /media/f2

Inside the VHD-files, there is a Partition1 file. This is the raw image of the partition backed up. In f1/f2 you should find one Partition1 file which is 100MB, and another which is the same size as your Windows partition. You could mount these files to look at the backup:

1
2
3
4
sudo mkdir /media/temp
sudo mount -o loop,ro /media/f1/Partition1 /media/temp
ls /media/temp
sudo umount /media/temp

When ready, use dd to copy its contents to you new partition:

1
2
3
MAKE SURE YOU KNOW WHAT YOU ARE DOING, 
DD DOES NOT CARE ABOUT YOUR IGNORANCE!!
sudo dd if=/media/f1/Partition1 of=/dev/sdXX bs=64M

if is the input file, of is the output file. XX is the partition, one character and one number. sda1 is sda's first partition, sdc3 is sdc's third partition.

Umount the partition with the backups, reboot and cross your fingers.

roundcube, sqlite2, ubuntu 11.10 and cherokee

Wednesday, February 15th, 2012

Roundcube only supports sqlite2(RC v0.7.1). Unfortunately Ubuntu 11.10 doesn't have sqlite2 available in the repos(not sure why, security?), and MySQL/PostgreSQL seems like an overkill for a single user roundcube installation.

Fix: install php5-sqlite and get sqlite2 from natty(11.04). The module sqlite.so is actually loaded by default(/etc/php5/cgi/conf.d/sqlite.ini) but missing in the oneiric package.

1
2
3
4
5
apt-get install php5-sqlite
wget http://security.ubuntu.com/ubuntu/pool/main/p/php5/php5-sqlite_5.3.5-1ubuntu7.7_i386.deb
dpkg -x php5-sqlite_5.3.5-1ubuntu7.7_i386.deb /tmp
cp /tmp/usr/lib/php5/20090626+lfs/sqlite.so /usr/lib/php5/20090626+lfs/
service cherokee restart

Reference: https://bugs.launchpad.net/ubuntu/+source/php5/+bug/875262

XBMC and pulseaudio master volume (Ubuntu 11.10)

Saturday, October 15th, 2011

If you use XBMC as standalone in Ubuntu(choose it in the login screen), volume control is limited to XBMC as a source in pulseaudio. If you login to Gnome/Unity/whatever, and forget to set sound level to 100% before you logout, XBMC sound volume will suffer from this.

Solution:
You can control sound volume in terminal with

1
pactl set-sink-volume # n%

.
# is a number of a so called sink, which is the same as an output device(analog, HDMI, SPDIF, etc). n% is percentage of volume. This will set sink 0 to 100% volume:

1
pactl set-sink-volume 0 100%

You need to find out which number your default output device is:

1
pactl list sinks

Should output something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Sink #0
	State: RUNNING
	Name: alsa_output.pci-0000_00_1b.0.analog-stereo
	Description: Intern lyd Analog Stereo
	Driver: module-alsa-card.c
	Sample Specification: s16le 2ch 44100Hz
	Channel Map: front-left,front-right
	Owner Module: 4
	Mute: no
	Volume: 0:  90% 1:  90%
	        0: -2,75 dB 1: -2,75 dB
	        balance 0,00
	Base Volume: 100%
	             0,00 dB
...

Play some music and test(music should mute 1 second):

1
pactl set-sink-volume 0 0%; sleep 1; pactl set-sink-volume 0 90%

To get XBMC set volume to 100% before startup we create a new command called xbmc-standalone-max-volume. Do this as root:

1
2
cp /usr/bin/xbmc-standalone /usr/bin/xbmc-standalone-max-volume
nano /usr/bin/xbmc-standalone-max-volume

In xbmc-standalone-max-volume find pulse start section and add three lines after it:

1
2
3
4
5
6
7
8
9
10
11
12
PULSE_START="$(which start-pulseaudio-x11)"
if [ -n "$PULSE_START" ]; then
  $PULSE_START
else
  PULSE_SESSION="$(which pulse-session)"
  if [ -n "$PULSE_SESSION" ]; then
    XBMC="$PULSE_SESSION $XBMC"
  fi
fi
# set volume to 100%
PACTL="$(which pactl)"
$PACTL set-sink-volume 0 100%

Now edit XBMC session:

1
nano /usr/share/xsession/XBMC.desktop

Change Exec and TryExec:

1
2
3
4
5
6
[Desktop Entry]
Name=XBMC
Comment=This session will start XBMC Media Center
Exec=xbmc-standalone-max-volume
TryExec=xbmc-standalone-max-volume
Type=Application

You may also do the same with xbmc -> xbmc-max-volume, but when inside gnome you could simply use your keyboard and Alt-Tab, set volume up, and Alt-Tab back.

Howto pause pm-suspend when program is running

Thursday, May 19th, 2011

I have a backintime running every hour. Sometimes, it's running when I suspend/hibernate the machine. The suspend will fail, because backintime refuses to suspend. BIT will fail because network is pulled down. Then we have backintime running forever, and suspend/hibernate failing forever too(until you kill BIT manually).

This script will wait until backintime is done, and then let the computer suspend/hibernate.

/etc/pm/sleep.d/01_backintime:

1
2
3
4
5
6
7
8
9
10
#!/bin/bash
case "${1}" in
  hibernate|suspend)
    while pgrep -f "/usr/bin/backintime "; do
      sleep 5
    done
  ;;
esac
 
exit 0

Remember to make the file executable.

disable screen saver when looking at flash videos(youtube, vimeo, etc)

Wednesday, May 18th, 2011

Run this script at startup of Gnome.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
 
# cleanup any bad state we left behind if the user exited while flash was running
gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
 
turn_it_off=0
sleepcomputer0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_computer_ac`
sleepdisplay0=`gconftool-2 -g /apps/gnome-power-manager/timeout/sleep_display_ac`
 
# run loop forever
while true; do
  # interval between checks
  sleep 30
  SS_off=0
  # make id variable of window in focus
  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
  # make pid array of every command with libflashplayer in full(-f) command
  for pid in `pgrep -f libflashplayer` ; do
    # check if window in focus is our libflashplayer
    if [ $pid == `xprop -id $current_window_id | grep PID | cut -d" " -f3` ]
      then SS_off=1
    fi
  done
 
# check to see if xine is being used
#  if pgrep xine > /dev/null; then
#    SS_off=1
#  fi
#
# check to see if current application is fullscreen
#  current_window_id=`xprop -root | grep "_NET_ACTIVE_WINDOW(WINDOW)" | cut -d" " -f5`
#  if xprop -id $current_window_id | grep "_NET_WM_STATE_FULLSCREEN" > /dev/null; then
#    SS_off=1
#  fi
 
  # read current state of screensaver
  ss_on=`gconftool-2 -g /apps/gnome-screensaver/idle_activation_enabled`
 
  # change state of screensaver as necessary
  if [ "$SS_off" = "1" ] && [ "$ss_on" = "true" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool false
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int 0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int 0
    turn_it_off=1
  elif [ "$SS_off" = "0" ] && [ "$ss_on" = "false" ] && [ "$turn_it_off" = "1" ]; then
    gconftool-2 -s /apps/gnome-screensaver/idle_activation_enabled --type bool true
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_computer_ac --type int $sleepcomputer0
    gconftool-2 -s /apps/gnome-power-manager/timeout/sleep_display_ac --type int $sleepdisplay0
    turn_it_off=0
  fi
done

Reference: http://ubuntuforums.org/showthread.php?p=10832670#post10832670

Remove title from Firefox when maximized(Chrome style)

Friday, May 13th, 2011

Add this to CompizConfig under "Window Decorations" in the field "Decoration windows":

1
(any)&!(class=Firefox&state=maxvert&role=browser)

Toggle maximize with Alt-F10. If you hide the "Menu Bar", you can show it with Alt Gr-F10. This allows for semi-full-screen-mode.

This was tested with Firefox 4 on Linux Mint 10. Install with:

1
2
3
sudo add-apt-repository ppa:mozillateam/firefox-stable
sudo apt-get update
sudo apt-get install firefox ubufox

References:
http://www.webupd8.org/2011/03/firefox-4-get-tabs-in-title-bar-like.html
http://community.linuxmint.com/tutorial/view/337

Roundcube and automatic addressbook

Friday, May 6th, 2011

With automatic addressbook plugin on roundcube, I could not create the MYSQL table. I'm running Ubuntu 10.04 LTS, with mysql-server 5.1.41. Got error message:

1
2
3
4
ERROR 1064 (42000) at line 1: You have an error IN your SQL syntax; CHECK the manual that corresponds TO your MySQL server version FOR the RIGHT syntax TO USE near '--!40008
   --ON DELETE CASCADE
   --ON UPDATE CASCADE
)' at line 15

Found this solution at roundcubeforum.net.

Use this command to create table:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
CREATE TABLE `collected_contacts` (
  `contact_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `changed` datetime NOT NULL DEFAULT '1000-01-01 00:00:00',
  `del` tinyint(1) NOT NULL DEFAULT '0',
  `name` VARCHAR(128) NOT NULL,
  `email` VARCHAR(128) NOT NULL,
  `firstname` VARCHAR(128) NOT NULL,
  `surname` VARCHAR(128) NOT NULL,
  `vcard` text,
  `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`contact_id`),
  KEY `user_collected_contacts_index` (`user_id`,`email`),
  CONSTRAINT `collected_contacts_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Turn on wake on lan

Tuesday, April 26th, 2011

Turning on WOL in BIOS is not enough with onboard ethernet SiS900(rev 91). Turn on with ethtool:

1
ethtool -s eth0 wol g

Add to rc.local or similar to make it persistent through reboots.

monit – monitor your services

Sunday, November 28th, 2010

After I got my home server up running, I was looking for a easy way to monitor it services. Earlier I've used MRTG, Smokeping, Cacti and similar, but this time I was looking for something really easy and lightweight. The graphs in MRTG and similar is useful to have, but my main focus was to monitor the health of a service and alert if it's not.

When I found Monit, I understood that monitor software with web front end, graphs and user management(Zabbix, Zenoss core, with more) was an total overkill for my task. Monit is easy to use, repairs the faulty service and have a nice web front end to see the current status.

Install

Since Monit comes with Ubuntu, it's easy:

apt-get install monit

Edit monit to start. Change startup=0 to startup=1

nano /etc/default/monit

Edit /etc/monit/monitrc. The file is self explainable and there is good documentation on http://mmonit.com/monit/documentation/monit.html. My stripped file looks like this:

set daemon  120           # check services at 2-minute intervals
with start delay 60  # optional: delay the first check by 1 minute
set logfile syslog facility log_daemon
set mailserver localhost,               # primary mailserver
set mail-format { from: monit@mydomain.no } # some mailservers bounce domains not found in DNS
set alert arve@mydomain.no
set httpd port 2812 and
use address localhost  # only accept connection from localhost
allow localhost        # allow localhost to connect to the server and
allow monit:passwd   # allow user monit with password passwd
include /etc/monit/conf.d/* # include conf files

I then created files in /etc/monit/conf.d. Here is my localhost file.

check system localhost
if loadavg(5min) > 4 then alert
if loadavg(15min) > 2 then alert
# filesystems
check filesystem root with path /
if space usage > 80% then alert
check filesystem home with path /home
if space usage > 95% then alert
# cron
check process cron with pidfile /var/run/crond.pid
start program = "/etc/init.d/cron start"
stop  program = "/etc/init.d/cron stop"
if 5 restarts within 5 cycles then timeout
# sshd
check process sshd with pidfile /var/run/sshd.pid
start program = "/etc/init.d/ssh start"
stop program = "/etc/init.d/ssh stop"
if failed port 22 protocol ssh then restart
if 5 restarts within 5 cycles then timeout
#  samba
check process smbd with pidfile /var/run/samba/smbd.pid
start program = "/etc/init.d/smbd start"
stop  program = "/etc/init.d/smbd stop"
if failed host 192.168.1.2 port 139 type TCP  then restart
if 5 restarts within 5 cycles then timeout
#  nfs
check host server.lan with address 192.168.1.2
start = "/etc/init.d/nfs-kernel-server start"
stop = "/etc/init.d/nfs-kernel-server stop"
if failed port 2049 then restart

Services are automagically restarted and you are alerted by email if pid file does not exist, or there is no running service with that pid. If statements holds extra tests for services, and services without pid file can be watched by checking the service over network.

Also services on the network can be watched. Here is another server I'm watching:

check host seljebu.no with address seljebu.no
if failed port 143 proto imap with timeout 2 seconds then alert
if failed port 465 type tcpssl proto smtp with timeout 2 seconds then alert
if failed url http://seljebu.no/ with timeout 2 seconds then alert

Restart monit.

service monit restart

Look for errors.

tail /var/log/syslog

If you get error message /etc/monit/conf.d/host:12: Error: syntax error '=', change all instances of " with ".

Thats it!