How I managed to fix EFI booting on my archlinux laptop after changing Motherboard

My less than a year old, Thinkpad x230 just got back from repairs – a dead motherboard. Thinkpads maybe tough but not tough enough for “The Mehul Test” :-P, this is the 2nd Thinkpad that’s suffered the same fate in my hands.

That’s the backstory, now getting back to the problem at hand. So, I got the motherboard changed, for free as it’s within warranty. The Lenovo repaircenter called and said they can’t boot Windows off the hard disk. I told them to hold back as it has Linux and would require some BIOS change. Fiddled around with BIOS settings, upgraded the BIOS to the latest version, still no go. Tried booting from the USB drive which I installed arch from, it showed blank screen. After fiddling around and browsing forums and trying IRC channel in vain, I decided to try the UEFI Shell. Thus, I went to the archlinux wiki and read up on it.

So, the bcfg command is the way to go. At first, I blindly copy pasted it from the wiki page and failed a couple of times. 

bcfg boot add 3 fs0:\EFI\refind\refind_x64.efi "rEFInd"

The above did add a boot entry which took me to the USB drive boot menu only. After a couple of minutes, it struck me that there were fs0 and fs1 among the entries when UEFI shell was launched. fs1 is what pointed to the my SSD drive. So, I went ahead and typed

bcfg boot add 3 fs1:\EFI\arch-grub\grubx64.efi "rEFInd"

And voila! That worked. Just before that, I typed

fs1:

and then did ls to see the contents. I could see that the contents were what was on the SSD in EFI partition and then gave the bcfg command.

This UEFI is super duper confusing. And I must admit, I barely understand it. I just managed to solve this issue by bruteforcing everything I could lay my eye upon. Unfortunately, it wasn’t documented anywhere nor could I find it via Google search. Hope this blog post helps someone who gets stuck with similar issue.

Access VirtualBox Guest Network From Outside

I have been looking for a way to enabling network inside virtualbox so that I can access it from anywhere thus being able to run various services inside virtual environment, trying out anything without any worries.

Here’s a simple how-to borrowed from archlinux wiki

Install bridge utils for creating bridge and uml_utilities for creating a tun device

pacman -S bridge-utils uml_utilities

Open the file /etc/udev/rules.d/60-vboxdrv.rules and add the following line to it

KERNEL==”tun”, OWNER=”root”, GROUP=”vboxusers”, MODE=”0660″

Then type the following command to load the tun module

modprobe tun

Now, let’s setup a bridge device to bridge network from your physical network interface to the virtual one

  • Create a bridge interface

brctl addbr br0

  • Set your interface in promiscous mode so it can accept packets from any interface

ifconfig <interface name> 0.0.0.0 promisc

  • Now, bridge the bridge interface with the real network interface

brctl addif br0 <interface name>

  • Now set the bridge interface to acquire IP address as your physical network interface would. eg if eth0 is your network interface and it acquires IP via DHCP then

dhclient br0

  • And finally add virtualbox host interface

VBoxAddIF vbox0 <VirtualBox user> br0

Now start VirtualBox and go to network settings. Select network interface as ‘host networking’ and interface device as ‘vbox0’.

Now you need to give an unused IP address in your IP range of the internet gateway. If you cannot provide that due to some reason then what you can do is create a virtual interface say eth0:0 then bind bridge network to that interface and setup NATing to pass packets between virtualbox and external network.

Some nifty fun with Linux and PDF files

Let me narrate 3 nice experiences with pdf on Linux while at work

1) Merging multiple PDF files

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOUTPUTFILE=filename.pdf file1.pdf file2.pdf……..fileN.pdf

2) Convert ps to pdf

ps2pdf file.ps file.pdf

3) Compressing PDF files.

4) Convert images to PDF

convert image1.jpg image2.gif image3.tiff…….imageN.xyz filename.pdf

Viewing MS Word files on Command Line

I had to urgently view a MS Word file but I didn’t have a word processor on my system to view it in, KWord2 beta wasn’t able to support MS Word files. And I couldn’t find any small word processor or the one that wouldn’t being a gnome and a half in with itself. So, I decided to explore the CLI way.

I came across this nice article on how to view MS Word files on CLI. One of those softwares which I tried out is antiword, as it seemed most suitable to my purpose. A nifty utility to download and use while Oo.org takes it’s sweet couple of hours.

Another nice thing is that it can be used when you don’t have X running or if you’re connecting via SSH.

Viewing the file in antiword is as simple as typing

antiword filename.doc

Though it has a few options to format stuff via parameters, I don’t need them. But, they can be quite useful for some purposes.

Pipe the document through a pager and nicely sit and enjoy reading your MS Word document over Command Line Interface.

My thoughts on the software – simple, easy to use and makes life easy when all you want is to view simple text from a MS Word document. What I miss the most in the software is the ability to open odt files 😦

Experience of emoving mysql in debian/ubuntu forcefully

I had faced this instance where there ocurred problem with mysql configuration in debian. Something went wrong with the configuration and could not be traced out. We needed to fix it soon and reinstall was the easy option as there was no useful data.
But, the package couldn’t be removed because mysql is stopped before removing, Here, what was happening was that the init script would neither start or stop mysqld due to configuration error. Thus, the package couldn’t be removed as it failed to stop mysql.
So, thus I followed a hack’ish kind of a method to remove mysql.
First I killed mysqld by using top. Then I edited the file /var/lib/dpkg/mysql-server.prerm to remove the relevant section. So, now when I remove the package, the script won’t try to stop mysql-server.
Thus, I was cleanly able to remove the package without any problems.
Also, you get choice whether you want to keep your databases or remove them. Thus, is safe if you have important database.
Though, this method doesn’t have any bad side effects as far as I know, but still it would be better to sort out the configuration issues but here I had no other choice as it was important to remove it quickly and also there were no important configuration saved.

Finch – IM Client for command line

Finch is an IM and IRC client for command line. It supports all the protocols supported by pidgin. Like pidgin, it makes use of libpurple. So, all your account configured for pidgin can be used on finch too .
It has nifty shortcuts based on alt keys to navigate around. Making it quite simple to use for those people who are faster with keyboard than with mouse. . Some frequently used shortcuts are :-

  • Alt + q – quit
  • Alt + c – close window
  • Alt + n – next window
  • Alt + p – previous window
  • Alt + a – View available actions
  • Alt + w – list of windows
  • Alt + m – move window
  • Alt + r – resize window
  • F10 – Show menu for current window
  • Alt + tab – next URGENT window
  • Alt + Shift + tab – previous urgent window

Not so difficult to remember the shortcuts. No use of mouse required at all
Alas! Keybindings don’t work under screen so I can’t run it in screen session rest everything is perfect.

Start rtorrent using init scripts

Searching around the net I came across 2 articles which helped in writing the init script presented below.
There are 3 versions of the script – one for gentoo based distros one for debian based distros and one for Fedora, which is quite similar to debian one.
Requirements for running the scripts

  • rtorrent
  • screen
  • adequate knowledge to operate rtorrent and screen

Steps to get started

  • Copy the contents of the script for your distro to a file
  • Save it with the name indicated in the script
  • Make the file executable with following command

chmod +x /path/to/file

  • Add it to your default boot level as indicated in the comments
  • Change the TUSER value from username to your username
  • Optionally you can change rtorrent to some other bittorrent client depending on your preference. NOTE:- It should be a CLI bittorrent client

The gentoo version of the script

#!/sbin/runscript

# To add the script automatically at the startup execute the following command in the terminal
# eselect rc add rtorrent default

RTUSER=username
TORRENT=/usr/bin/rtorrent

opts=”start stop”

depend() {
#this daemon needs internet to function
need net.eth0
use logger
}

start() {
#display to user that what is being started
ebegin “Starting rtorrent”
#start the process and record record it’s pid
start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER
# To interact with rtorrent you will need to reattach the screen
einfo “To use your rtorrent session, reattach screen using following command:”
einfo “screen -r torrent”
#output failure or success
if [[ $? -eq 0 ]]; then
if [[ $? -eq 0 ]]; then
eend “Process started successfully”
else
eend “Process failed to start”
}

stop () {
#display that we are stopping the process
ebegin “Stopping rtorrent”
#stop the process using pid from start()
start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
eend “Process stopped successfully”
else
eend “Process failed to stop”
}

Debian version

#!/bin/bash

# To start the script automatically at bootup type the following command
# update-rc.d torrent defaults 99

RTUSER=username
TORRENT=/usr/bin/rtorrent

case $1 in
start)
#display to user that what is being started
echo “Starting rtorrent”
#start the process and record record it’s pid
start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER
#output failure or success
#info on how to interact with the torrent
echo “To interact with the torrent client, you will need to reattach the screen session with following command”
echo “screen -r torrent”
if [[ $? -eq 0 ]]; then
echo “The process started successfully”
else
echo “The process failed to start”
;;

stop)
#display that we are stopping the process
echo “Stopping rtorrent”
#stop the process using pid from start()
start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
echo “The process stopped successfully”
else
echo “The process failed to stop”
;;

*)
# show the options
echo “Usage: {start|stop}”
;;
esac

Seems that debian version will work for Fedora too. Still, here’s the script

#!/bin/bash

# To start the script automatically at bootup type the following command
# chkconfig add torrent

RTUSER=username
TORRENT=/usr/bin/rtorrent

case $1 in
start)
#display to user that what is being started
echo “Starting rtorrent”
#start the process and record record it’s pid
start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER
#output failure or success
#info on how to interact with the torrent
echo “To interact with the torrent client, you will need to reattach the screen session with following command”
echo “screen -r torrent”
if [[ $? -eq 0 ]]; then
echo “The process started successfully”
else
echo “The process failed to start”
;;

stop)
#display that we are stopping the process
echo “Stopping rtorrent”
#stop the process using pid from start()
start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent
#output success or failure
if [[ $? -eq 0 ]]; then
echo “The process stopped successfully”
else
echo “The process failed to stop”
;;

*)
# show the options
echo “Usage: {start|stop}”
;;
esac

One thing I need to implement is to show status. If it is started or stopped. Reload or restart doesn’t seem to make much sense to me thus I haven’t implemented those.
This is only the initial version it may have bugs. Please report them so they can be corrected.
Debian and fedora users please try it and report if it works.
For user of other distros, if interested, please provide some idea of your distro’s init system or attach some init script so that I can work on it.
For people familiar with init system, it would be great to post your modifications/improvements/bug fixes/ideas to this script.

Mirage – A lightweight GTK+ Image Viewer

Being a fluxbox user I have been looking for some lightweight imageviewer. xloadimage can always be invoked from CLI whenever needed.
While helping a friend build up a XFCE based gentoo system we discovered mirage. Mirage needs only pyGTK installed, which should be available on most linux distributions these days.
Some of the useful features of mirage are :-

  • Lightweight
  • Easy to use interface
  • Small app coded in python and GTK+
  • Supports various image formats like png, svg, jpeg, gif, etc.
  • Shows thumnails of all images in current directory
  • Displays basic information about size, resolution and compression of images in the status bar at the bottom
  • Supports basic editing features like rotate, flip, crop, resize, saturation,
  • It can also show images in the current directory as a slide show.
  • Option for viewing remote images
  • It can also take screenshots and save it in png format

Here’s a screenshot of mirage taken in mirage itself

Mirage image from Mirage

Mirage image from Mirage

More can be found on Mirage’s website
It has 4 modes for opening a file –

  • Smart Mode,
  • Zoom to Fit Mode,
  • 1:1 Fit Mode and
  • Last Active Mode.

Here’s the definition of smart mode, from mirage’s website

Smart Mode uses 1:1 zooming if the image is smaller than the available space and Fit Mode if the image is larger.

It also supports command line arguments, though they may not be utilized too much. Nonetheless it is available if needed.

Now, I have left it’s best part to the last. It supports custom actions eg. pressing ctrl +e opens the image in gimp, alt + t to create thumbnail of the image and so on. All these can be easily changed too by editing it’s values in Edit=> Custom Actions=> Configure. You can also add new values as to your liking

One great use of mirage I have found for myself is when using elinks for browsing certain websites which are supposed to be text based but I may stumble upon a couple of interesting sounding images. Mirage can then be easily invoked from elinks to view the images from the website.

Patching xorg-server-1.4.0.90 to work on gentoo/freebsd

While compiling xorg-server on gentoo/freebsd, I was getting an error. So, I paid a visit to #gentoo-bsd on irc.freenode.net. WIth the help of friendly people out there I found that it’s missing something but seemed to be out of luck as we couldn’t find out what was missing.

A quickfire query at bugs.gentoo.org revealed that there was indeed a bug filed with xorg-server-1.4.0. You can find the bug at http://bugs.gentoo.org/show_bug.cgi?id=205149
So, basically I needed to patch up my xorg-server files with the 2 patches given out there. Continue reading