Posts Tagged ‘linux’

Fixing drive failure when using mdadm/raid1 on boot device (CentOS 5)



I am using CentOS 5 for one of my servers, and use raid1 and md for
the mirroring between two drives.

Then one of the drives fail (which they eventually will), here is how
you fix it:

I have taken info from these pages for this blog post:…

In this example I have two hard drives, /dev/sda and /dev/sdb, with
the partitions /dev/sda1 and /dev/sda2 as well as /dev/sdb1 and
/dev/sda1 and /dev/sdb1 make up the RAID1 array /dev/md0.
/dev/sda2 and /dev/sdb2 make up the RAID1 array /dev/md1.
/dev/sda1 + /dev/sdb1 = /dev/md0
/dev/sda2 + /dev/sdb2 = /dev/md1
/dev/sdb has failed, and we want to replace it.

First of all: ‘cat /proc/mdstat’ is your friend – it will show you the
status of your raid during the whole process.

In the output from ‘cat /proc/mdstat’ you will see an (F) behind a
failed device, or it will be missing alltogether.

First, fail and remove the failed device(s):
mdadm –manage /dev/md0 –fail /dev/sdb1
mdadm –manage /dev/md0 –remove /dev/sdb1
Repeat for other MD-devices containing sdb-parts.
Now the output from ‘cat /proc/mdstat’ should only contain parts from sda.

Power down, change the drive, and turn it back on.

To make the same partitions on sdb as you have on sda, do this:
sfdisk -d /dev/sda | sfdisk /dev/sdb

‘fdisk -l’ should now show the same partitions on sda and sdb.

Next, add the proper parts from sdb to the relevant md-device. So if
md0 contains sda1, do this:
mdadm –manage /dev/md0 –add /dev/sdb1
Repeat for all md-devices so you have the same parts from sda and sdb
in all of them.
Check with ‘cat /proc/mdstat’.

Let is sync back up (check with ‘watch -n 10 cat /proc/mdstat’ until
it finishes).

Now, fix grub:
grub>root (hd0,0)
grub>setup (hd0)

If you’re unlucky and can’t’ boot because the wrong device is first
(trying to boot from the clean/new hard drive), follow these steps:

First boot into a live cd with your os.
Then activate the RAID:
1) mkdir /etc/mdadm
2) mdadm –examine –scan > /etc/mdadm/mdadm.conf
3) mdadm -A –scan

Then reinstall grub. In this example, you have /boot on md0 and / on md1:
1) mkdir /mnt/sysimage
2) mount /dev/md1 /mnt/sysimage
3) mount -o bind /dev /mnt/sysimage/dev
4) mount -o bind /proc /mnt/sysimage/proc
5) chroot /mnt/sysimage /bin/bash
6) mount /dev/md0 /boot
Then fix grub (same as above):
grub>root (hd0,0)
grub>setup (hd0)

Voila, you have a working raid again with grub managing to boot your system 🙂

amixer in ubuntu


If you want to change the volume in Ubuntu 11.10 it seems that amixer
is kind of bugged when it comes to toggle (mute/unmute). When
toggling Master, it also mutes all the separate groups (Front,
headphone, PCM and so on), but when toggled again it only unmutes
Master, which leaves the rest muted…

I came across a nice workaround that i wanted to share. The solution
was written by Jim Hunziker on this page:

1) Make a with the following content:

#!/bin/bash CURRENT_STATE=`amixer get Master | egrep 'Playback.*?[o' | egrep -o '[o.+]'|head -n 1`if [[ $CURRENT_STATE == '[on]' ]]; then    amixer set Master muteelse   amixer set Master unmute   amixer set Front unmute   amixer set Headphone unmute   amixer set PCM unmutefi

2) chmod u+x

3) Bind it to some key (f.ex. XF86AudioMute) to run



Cutting bits from avi-file with ffmpeg/mencoder


I wanted to cut out two bits from an avi-file and then join them to
get one small file from a large file. I thought using ffmpeg would be
easy for this, but it turns out it might have a but with avi/wmv so I
ended up using mencoder instead.

The original try I did with ffmpeg was:
ffmpeg –ss 00:05:52 -t 00:00:11 -i bigfile.avi small_clip.avi
It looks like it wants to do what I want, since it makes a file where
the first 11 seconds are the ones I want, but then the sound
disappears and all of the rest of bigfile.avi is there (the video at

I could not find any solution for this on the interwebs, so I ended up
trying mencoder which worked:
mencoder -oac copy -ovc copy -ss 00:05:52 -endPos 00:00:11 bigfile.avi
-o small_clip.avi
I repeated the above for all the clips from bigfile.avi and then put
them together:
mencoder -oac copy -ovs copy -idx -o joined_clip.avi small_clip1.avi
small_clip2.avi and so on

Google Chrome and Kerberos


Just a short tip for those of you that use Google Chrome and want to
utilize Kerberos to login to sites:
You need to start Chrome with an extra command-line option. Why this
isn’t configurable inside Chrome is a mystery, but anyways – here is
the solution:
1) Make sure you have a kerberos ticket (check with klist or do a new kinit )
2) Start Chrome as this:
google-chrome –auth-server-whitelist=”domain”
domain can f.ex. be *

Voila, Kerberos-login works.

API and RedHat Network


If you use RedHat Enterprise Linux in a big environment, you probably
use RedHat Network (RHN) as well.

RHN has a very well documented API, which can be used for all tasks
you want to do.

Here is a small script I wrote to list out all of our systems and when
they last checked in:


import xmlrpclib
import getpass
from sys import stderr
import sys

RHN_URL = “”

# Using stderr so redirect of the script to a file still works for prompts:
stderr.write(‘Please input your RHN username: ‘)
u = raw_input().rstrip(‘n’)
p = getpass.getpass(stream=sys.stderr)

client = xmlrpclib.Server(RHN_URL, verbose=0)
key = client.auth.login(u, p)
list = client.system.listUserSystems(key)

for group in list:
sysname = group.get(‘name’)
sysid = group.get(‘id’)
last_checkin = group.get(‘last_checkin’)
print ‘{0} – {1} ‘ .format (sysname, last_checkin)


Hope that might be useful for someone else.

For more info on RHN’s APIs:

Ubuntu 11.04 and workspaces


A little bit difficult to find, so this is more of a “note to self”.

How to change number of workspaces in Ubuntu:
1) Open a Terminal.
2) To change the number of rows, type the following command, changing
the final number to the number you wish. Press Enter.
gconftool-2 –type=int –set /apps/compiz-1/general/screen0/options/vsize 2
3) To change the number of columns, type the following command,
changing the final number to the number you wish. Press Enter.
gconftool-2 –type=int –set /apps/compiz-1/general/screen0/options/hsize 2

Voila. Why can’t this be changed through some gui?

NRK nett-tv i Ubuntu


Kjapp fremgangsmåte for å se NRK sin nett-tv i Ubuntu:

1) Installer repository MediUbuntu:
sudo wget –output-document=/etc/apt/sources.list.d/medibuntu.list$(lsb_release -cs).list &&
sudo apt-get –quiet update && sudo apt-get –yes –quiet
–allow-unauthenticated install medibuntu-keyring && sudo apt-get
–quiet update

2) Gjør MedUbuntu tilgjengelig i software-senteret osv:
sudo apt-get –yes install app-install-data-medibuntu apport-hooks-medibuntu

3) Installer w32codecs:
sudo apt-get install w32codecs
Eller om du har amd64:
sudo apt-get install w64codecs

4) Installer gnome-mplayer:
sudo apt-get install gnome-mplayer

5) Installer MediaPlayerConnectivity for FireFox:

6) Når MediaPlayerConnectivity spør, velg følgende for Windows media-filer:

Voila, nå kan du klikke på TV-klipp på og de åpnes i gnome-mplayer.

NRK Nett-TV hjelp:

Nostalgy for Thunderbird


I just found the best addon ever for Thunderbird: Nostalgy. It’s so
good, I just felt like sharing with the world 🙂

This addon makes is super-easy to copy or move a mail to another
folder, without using the mouse. To do this, you have two main modes:
1) Press s or c to copy a mail. This opens a text-field on the
status-line where you can start to type the folder you want to move or
copy the mail to. You will get auto-completion, and it remembers the
last x number of folders you moved/copied to. Press arrow up/down to
choose a folder and enter to move/copy the mail.

2) Make a rule based on sender and/or subject. When a mail matches
one of these rules, you will see it on the status-line, and you can
press shift-s or shift-c to move it to the folder automatically.

The addon can be configured very much, and is accectly what I feel was
missing in my thunderbird at least.

Great work, Alain Frisch. You will receive a donation from this happy
“customer” 🙂

Now, go get it yourself:

Thunderbird: IMAP Mailbox isn’t selectable


There was a problem with Thunderbird that was bugging me for a long while. If I did a search across all my folders, I would always get a pop-up window with the message “not a selectable mailbox” or something like that.

Finally today I decided to investigate how to solve this and I found this blog entry. I tried it, and it worked! This is what I did:

  • I located the .mailboxlist file that lists all the folders of the offending IMAP account. In my case the file was in my home directory. Easy!
  • In .mailboxlist I deleted the entries to the offending folders.  Apparently they should haven’t been listed there. These folders are meant to be carriers of other folders and therefore they have no messages. Why the file .mailboxlist lists them, I don’t know and I would love to hear if someone knows.
  • In my Thunderbird profile folder I went to the directory ImapMail/my.offending.imap.account. In my case the Thunderbird folder is .thunderbird. This folder has a directory with a strange name and the suffix .default; this is the default profile. In this default profile I found ImapMail.
  • Inside that my.offending.imap.account directory there is a list of files with suffix .msf. I simply deleted the files that corresponded with the offending folders.
  • I restarted Thunderbird… and voilà, now the offending folders are greyed out and in italics. And there were no more errors of this type.

What a relief.

(Shamelessly stolen from – Thanks Diego )




I just got a new laptop, installed Windows and VMWare on it, and then installed Ubuntu as a virtual machine. It worked like a charm, but when I was going to login, the keyboard didn’t work…

After googling a bit, I came across this:

This fixed my problem, thank you Edvard Heiberg Holst!

Shamelessly, I include his text here, in case he removes his webpage:

Keyboard not working with Ubuntu 10.04 in VmWare Fusion
Written by Edvard Heiberg Holst
Tuesday, 27 April 2010 03:07

I just downloaded and installed Ubuntu 10.04 LTS with VMWare Fusion 3.
When the login screen appeared I tried to enter the password but to my
great surprise, nothing happened.

After investigating the matter, it seems like this issue is related to
a vmvare setup script issue.

To fix the problem, first use the on-screen keyboard to log in to
Ubuntu.When you come to the login screen click on the “Universal
Access Preferences” (It’s the little guy in the circle) on the bottom
toolbar to the left of the date and time. Then click on the pop-up
that says “Universal Access Preferences”. Then put a check mark next
to “Use on-screen Keyboard”. Reboot and you will have an on-screen
keyboard that works. Once your in to your Gnome desktop the keyboard
works fine.

Then, open up a terminal and type:

sudo dpkg-reconfigure console-setup

Then follow the on-screen instructions, reboot, and you are good to go!

%d bloggers like this: