[HOWTO] Install Firefox 4 in Ubuntu 10.04 Lucid Lynx and 10.10 Maverick Meerkat

Firefox 4 has been released recently and it is not available via update manager in Ubuntu 10.04 Lucid Lynx and 10.10 Maverick Meerkat. The Ubuntu Mozilla Daily Build PPA provides it but it always the latest daily build and not the stable version.

For stable version, you can use Firefox Stable PPA. To install the PPA in Lucid or Maverick, just launch Synaptic (System>Administration>Synaptic Package Manager) and then go to Settings>Repositories>Other Software. Now click Add and paste in the following:

ppa:mozillateam/firefox-stable

Close the Repositories window and then click reload. When it is done, search for firefox-4.0-gnome-support and mark it for installation. It should mark other required packages. Apply and wait for installation to finish.

[HOWTO] Remount /cdrom as Read-Write in a Live Unetbootin Setup

If you have used Unetbootin to setup a Live Ubuntu Environment, you will find that the partition containing the Unetbootin files will be mounted on /cdrom as read-only, which means, even if you launch nautilus with gksu or sudo, you will not be able to make changes to the file-system. There is however, an easy workaround which involves remounting the filesystem with a single command. Open up the terminal and type in the following:

sudo mount /cdrom  -o rw,remount

Now, you should be able to write into the filesystem.

[HOWTO] Run apache server with www directory in a different server

This is an experiment in which I wanted to see if it is possible to run apache on one server and have www directory in a different server (physical or virtual). I don’t know the possible benefits of such a system or a scenario where this could be helpful, neither am I aware of different ways to achieve the same. But I tried it and am posting the results anyways. 😀

The Problem

I am assuming a hypothetical problem where a user wants to run apache server in one machine and have the www directory in a different system. Let’s call the machine with apache2 installed as Web Server (WS) and for the system with www directory, lets use the name File Server (FS).

The Plan

The plan is to mount the www directory of FS to a directory of WS with sshfs and configure apache in WS to use that sshfs directory.

Working Environment

I am using my Debian Testing system as FS and Ubuntu 10.10 Maverick Meerkat inside VirtualBox virtual machine (using Bridged connection) as WS which has apache installed. I have openssh server installed in FS and openssh client and sshfs installed in WS.

Plan Execution

Apache Configuration
First, lets login to WS and configure apache to use a directory in normal user’s home directory (/home/ws_username/www) by editing /etc/apache2/sites/available/default. The DocumentRoot is set to /home/ws_username/www and a Directory is set to /home/ws_username/www/ (no virtual hosts, however, using virtual hosts should not be much different either).
Stop apache server for now:

sudo service apache2 stop

Testing SSH connection from WS to FS
Now, connect from WS to FS using:

ssh fs_username@fs_ip_or_domain_name

and verify connection is OK. Add to known hosts (if connecting for the first time). Then type

exit

to disconnect.
Setting up SSH connection without password
If not already created, create a ssh key pair using the command in WS:

ssh-keygen

That should ask you where to store the rsa public key (it is stored by default in /home/ws_username/.ssh/id_rsa/ as /home/ws_username/.ssh/id_rsa/id_rsa.pub). Use a blank password. If you use a password, you may have to use ssh-agent for authentication later (not covered in this article). Now, transfer the pub key to FS using scp.

scp ~/.ssh/id_rsa/id_rsa.pub fs_username@fs_ip_or_domain_name:

Then, ssh to FS:

ssh fs_username@fs_ip_or_domain_name

Now, add the rsa keys copied from WS earlier to authorized_keys file in FS:

cat id_rsa.pub >>~/.ssh/authroized_keys
rm id_rsa.pub

Exit to disconnect and drop to WS shell.
Testing SSH connection from WS to FS without password
If you followed the instructions correctly, you will be able to connect to FS from WS without password when you use SSH.

ssh fs_username@fs_ip_or_domain_name

Exit to disconnect:

exit

Manually mount the www directory in FS to WS using sshfs
Now, test if sshfs is able to mount the directory from FS to WS. Let us assume the www directory is in /home/fs_username/webprojects and is properly readable/writable (as required) by fs_username.
First, allow the user to mount by adding the ws_username to fuse group by running the following command:

sudo gpasswd -a ws_username fuse

Mount the directory to /home/ws_username/www using sshfs:

sshfs -o idmap=ws_username fs_username@fs_ip_or_domain_name:/home/fs_username/webprojects  /home/ws_user/www

Confirm successful mounting by listing the contents:

ls /home/ws_username/www

Unmount when done testing:

fusermount -u /home/ws_username/www

Setup /etc/fstab to be able to mount and unmount using mount and unmount instead
Open up /etc/fstab and add the following line:

sshfs#fs_username@fs_ip_or_domain_name:/home/fs_username/webprojects /home/ws_username/www fuse fsname=sshfs#fs_username@fs_ip_or_domain_name:/home/fs_username/webprojects,users,allow_other,uid=1000,gid=104,comment=sshfs,exec,reconnect,transform_symlinks,BatchMode=yes,noauto 0 0

Don’t use uid and gid values as they appear above. Instead, get those values by running the following command in terminal:

id

Make sure to use the uid and gid (of fuse group) from the output of the above command. Save the file.
Then open up /etc/fuse.conf and add or uncomment the line:

user_allow_other

Try mounting and unmounting using mount and unmount

mount /home/ws_username/www
ls /home/ws_username/www
umount /home/ws_username/www

Setup auto-mount on connection (ifup) and auto-unmount on disconnect (ifdown)
Create a file /etc/network/if-up.d/mountsshfs with the following contents:

#!/bin/sh

## http://ubuntuforums.org/showthread.php?t=430312
## The script will attempt to mount any fstab entry with an option
## "...,comment=$SELECTED_STRING,..."
## Use this to select specific sshfs mounts rather than all of them.
SELECTED_STRING="sshfs"

# Not for loopback
[ "$IFACE" != "lo" ] || exit 0

## define a number of useful functions

## returns true if input contains nothing but the digits 0-9, false otherwise
## so realy, more like isa_positive_integer 
isa_number () {
    ! echo $1 | egrep -q '[^0-9]'
    return $?
}

## returns true if the given uid or username is that of the current user
am_i () {
	[ "$1" = "`id -u`" ] || [ "$1" = "`id -un`" ]
}

## takes a username or uid and finds it in /etc/passwd
## echoes the name and returns true on success
## echoes nothing and returns false on failure 
user_from_uid () {
    if isa_number "$1"
    then
		# look for the corresponding name in /etc/passwd
    	local IFS=":"
    	while read name x uid the_rest
    	do
        	if [ "$1" = "$uid" ]
			then 
				echo "$name"
				return 0
			fi
    	done </etc/passwd
    else
    	# look for the username in /etc/passwd
    	if grep -q "^${1}:" /etc/passwd
    	then
    		echo "$1"
    		return 0
    	fi
    fi
    # if nothing was found, return false
   	return 1
}

## Parses a string of comma-separated fstab options and finds out the 
## username/uid assigned within them. 
## echoes the found username/uid and returns true if found
## echoes "root" and returns false if none found
uid_from_fs_opts () {
	local uid=`echo $1 | egrep -o 'uid=[^,]+'`
	if [ -z "$uid" ]; then
		# no uid was specified, so default is root
		echo "root"
		return 1
	else
		# delete the "uid=" at the beginning
		uid_length=`expr length $uid - 3`
		uid=`expr substr $uid 5 $uid_length`
		echo $uid
		return 0
	fi
}

# unmount all shares first
sh "/etc/network/if-down.d/umountsshfs"

while read fs mp type opts dump pass extra
do
    # check validity of line
    if [ -z "$pass" -o -n "$extra" -o "`expr substr ${fs}x 1 1`" = "#" ]; 
    then
        # line is invalid or a comment, so skip it
        continue
    
    # check if the line is a selected line
    elif echo $opts | grep -q "comment=$SELECTED_STRING"; then
    	
    	# get the uid of the mount
        mp_uid=`uid_from_fs_opts $opts`
        
        if am_i "$mp_uid"; then
			# current user owns the mount, so mount it normally
			{ sh -c "mount $mp" && 
				echo "$mp mounted as current user (`id -un`)" || 
				echo "$mp failed to mount as current user (`id -un`)"; 
			} &
		elif am_i root; then
			# running as root, so sudo mount as user
			if isa_number "$mp_uid"; then
				# sudo wants a "#" sign icon front of a numeric uid
				mp_uid="#$mp_uid"
			fi 
			{ sudo -u "$mp_uid" sh -c "mount $mp" && 
				echo "$mp mounted as $mp_uid" || 
				echo "$mp failed to mount as $mp_uid"; 
			} &
		else
			# otherwise, don't try to mount another user's mount point
			echo "Not attempting to mount $mp as other user $mp_uid"
		fi
    fi
    # if not an sshfs line, do nothing
done </etc/fstab

wait

Create another file /etc/network/if-down.d/umountsshfs with the following contents:

#!/bin/bash

# Not for loopback!
[ "$IFACE" != "lo" ] || exit 0

# comment this for testing
exec 1>/dev/null # squelch output for non-interactive

# umount all sshfs mounts
mounted=`grep 'fuse.sshfs\|sshfs#' /etc/mtab | awk '{ print $2 }'`
[ -n "$mounted" ] && { for mount in $mounted; do umount -l $mount; done; }

Make both files executable and owned by root:

sudo chmod 755 /etc/network/if-up.d/mountsshfs /etc/network/if-down.d/umountsshfs
sudo chown root:root /etc/network/if-up.d/mountsshfs /etc/network/if-down.d/umountsshfs

Test the working of scripts
Enter the commands (assuming the ethernet interface as eth0):

sudo ifdown eth0   #disconnect
sudo ifup eth0   #connect

Test if the directory is mounted:

ls /home/ws_user/www #should list files

Disconnect:

sudo ifdown eth0

Test if the directory is unmounted:

ls /home/ws_user/www #should not list files

Connect back:

sudo ifup eth0   #connect

You can also reboot the system to test if the directory properly mounts at startup.

Start Apache and Test

sudo service apache2 restart

Test using a web browser.

References

http://ubuntuforums.org/showthread.php?t=430312
https://bugs.launchpad.net/ubuntu/+source/sshfs-fuse/+bug/243298
http://linux.dsplabs.com.au/sshfs-read-connection-reset-by-peer-p73/
http://www.debian-administration.org/articles/152
https://help.ubuntu.com/community/SSHFS

[HOWTO] Setup a Minimal Ubuntu LAMP server (with ssh server)

In this article, I will describe how I went about to install the bare minimum LAMP server using Ubuntu Minimal installation iso. I downloaded Maverick Meerkat version of Minimal CD image from the Minimal CD Image Download Page. You can use the server ISO but you may end up with unwanted packages and you will need to download the whole ~700 MB ISO to start, while Minimal CD is just ~13MB. Also, since the Minimal CD downloads the latest packages from the repos during installation, you need not update immediately further saving data volume.

I am installing inside VirtualBox 4.0 Beta. However, these instructions should apply to other Virtualization solutions or even a physical machine.

Boot into the computer with the CD Image (either burn it to business card CD-ROM or normal CD-ROM if using Physical Machine otherwise just mount inside VirtualBox) and follow the on-screen instructions and select appropriate settings that apply to you. At the last stages of the installation, you will be asked to select packages, select none. It will complete installing the basic packages and install Grub and reboot.

After reboot, you will be able to login. After logging in, enter the following command:

sudo apt-get install mysql-server phpmyadmin ssh

The above command should install the following components:
openssh-server
apache2
mysql-server
mysql-client
php
phpmyadmin

At the end of the installation, just select appropriate settings and setup passwords.

Now, when you launch a browser in another machine, you can open http://IP.OF.THE.MACHINE and you will see that system is ready, if everything went right. The installed size is less than 1GB (excluding swap).

Hope this helps.

[HOWTO] Bring back “Network”, “Services”, “Time and Date” and “Users and Groups” in Gnome Menu

If you have installed your system via netinstall or by selecting packages one by one, or if you somehow removed some gnome packages, you may be missing some menu items. I noticed that I did not have some entries in System>Administration menu, namely, “Network”, “Services”, “Time and Date” and “Users and Groups”. I tried to search for them in Synaptic and Apt-file but failed to locate the exact package. So, I did some hit and trial and found the package was “gnome-system-tools”. I just installed it via synaptic and the menu entries were back.

[HOWTO] Properly install VirtualBox 4 beta in Ubuntu/Debian/Linux Mint (and other Debian/Ubuntu derivatives)

I downloaded deb of VirtualBox beta 1 from the beta packages page of Oracle website and installed it. However, while launching Virtual Machines created with Oracle VirtualBox 3.x (closed source version), I got the following error:

Failed to open a session for the virtual machine [machine name].
A virtual device is configured in the VM settings but the device implementation is missing.
A possible reason for this error is a missing extension pack. Note that as of VirtualBox 4.0, certain features (for example USB 2.0 support and remote desktop) are only available from an ‘extension pack’ which must be downloaded and installed separately (VERR_PDM_DEVICE_NOT_FOUND).

Details:
Result Code:
NS_ERROR_FAILURE (0x80004005)
Component:
Console
Interface:
IConsole {515e8e8d-f932-4d8e-9f32-79a52aead882}

It was clear that it requires an extension pack. I went back to the download page and found an extension pack named “Oracle_VM_VirtualBox_Extension_Pack-4.0.0_BETA1-68572.vbox-extpack” (newer versions may be available now so name may be different) and downloaded it. I installed it by double clicking it. It opens with VirtualBox by default (if it doesn’t, open with and select VirtualBox). The following error popped up:

Failed to install the Extension Pack /path/Oracle_VM_VirtualBox_Extension_Pack-4.0.0_BETA1-68572.vbox-extpack.
Failed to locate load the main module (‘/usr/lib/virtualbox/ExtensionPacks/Oracle_VM_VirtualBox_Extension_Pack/linux.x86/VBoxPuelMain.so’): VERR_FILE_NOT_FOUND.

Details:
Result Code:
NS_ERROR_FAILURE (0x80004005)
Component:
ExtPackManager
Interface:
IExtPackManager {8104df65-74d6-4e33-b374-50aa062b4afd}

When I tried to launch a Virtual Machine, I got the previous error. However, when I tried to reinstall the Extension, I got the following error:

Extension pack ‘Oracle VM VirtualBox Extension Pack’ is already installed. In case of a reinstallation, please uninstall it first.

I learned from WebUpd8 that libstdc++5 was required for it. So, I just installed it by typing the following in terminal:

 sudo apt-get install libstdc++5

Then, after restarting VirtualBox, I was able to launch my Virtual Machines again.

[HOWTO] Setup a Live Testing Environment for Ubuntu Daily Builds right from the Harddisk

If you are keen about the changes in the next version of Ubuntu, 11.04 (Natty Narwhal), and want first hand experience, you can setup your own live testing environment which boots right from the harddisk. You can of course test the ISOs in Virtualbox, but if your card is not supported for Virtualbox 3D, you won’t be able to test the new Ubuntu Unity interface.

Requirements
Computer running Linux with Internet Access
The computer must have graphics card supported by default by Ubuntu

Assumptions
I am assuming you are running another copy of Ubuntu. If the instructions don’t actually fit with your system, feel free to do whatever applies to your distro.

Getting the latest CD Images
Ubuntu 11.04 Natty Narwhal is under heavy development. The CD images are updated daily for users and developers to test. They are available here. However, if you download full ISO images daily, you will be wasting a lot of data transfer and time. Instead, you can download the changes only using zsync. Here is how.

Open up the terminal and install zsync:

sudo apt-get install zsync

Now, go to the daily images page and look for .zsync files of the ISO you want to try. For instance, if you want to try Ubuntu 11.04 32bit, you will need the zsync file natty-desktop-i386.iso.zsync. Don’t download the zsync file though. You will just need the URL to the zsync file. To get that on Firefox, right click and click “Copy Link Location”.

Now, you will need a directory where you want to download the images. Create a directory and make sure about 2 GB of space is available in the drive. Then, just open up the terminal and change to that directory and type in the following:

zsync http://cdimage.ubuntu.com/daily-live/current/natty-desktop-X.iso.zsync

where X is one of amd64+mac, amd64, i386, powerpc+ps3 or powerpc.
(The second part of the above command is the link you copied in the above step.)

Now, whenever you wish to get the latest Ubuntu ISO image, just run the same command from the same directory and your ISO will be updated. zsync will download only the changed parts from the server and the download will require less data transfer and hence will be faster.

Setting it up to boot
When you have the latest ISO, you will need to test them by booting. As I mentioned earlier, you could use Virtualbox but it may not support your graphics card for 3D and hence testing Unity may not be possible. Another program you can use is “Startup Disk Creator” (also known as usb-creator-gtk), but it only lets you create USB disks. If you have USB disks and don’t mind writing lots of files to it on a daily basis (assuming you will be testing all the daily builds), you could use that. However, USB Flash drives are prone to failure if used in that way.
The program we are going to use is unetbootin. It allows you to setup booting ISOs right from the Harddisk. It is available in the repositories in most Linux distributions but the latest version may not have hit the repositories yet, so it is recommended to download it from the official page. But it is recommended to install the one from your repositories too so that the dependencies are installed.

Make it executable by doing a chmod +x or by right clicking the downloaded file and selecting properties and checking the “Allow executing file as program” in Permissions tab.


Now, launch unetbootin and select the DiskImage option (and not the distribution) and browse to locate the latest daily ISO you downloaded using zsync. Select Type as Hard Disk and Drive as / and click OK.


When done, reboot and hold on Shift when the computer just starts to bring up the Grub menu. In the Grub menu, select the “Unetbootin” entry (and not the other ones, they may not work).

To setup the latest downloaded ISO again, run Unetbootin and uninstall the existing entry and repeat the same process.

Note: If you are using this setup, skip any updates to grub.

Happy testing.

[SOLVED] Compiz text input problem in Ubuntu 11.04 Natty Narwhal Alpha 1

If you are using Ubuntu 11.04 Natty Narwhal Alpha, you may face compiz crashes. To recover from compiz crash, you can do a

compiz --replace

, but sometimes, you are not able to input text any more so doing that is not possible. Then, all you can do is restart the system. However, compiz can be restarted from other terminals. If you encounter a crash and are no longer able to input text, press Ctrl+Alt+F1 and login. Now, type in the following:

DISPLAY=:0.0 compiz --replace

Now, when you press Ctrl+Alt+F7, you will see that compiz has restarted and you can type text again. If some components (like unity) fail to load, bring up the terminal by pressing Ctrl+Alt+T and type in

compiz --replace

to load compiz again.

If it does not work, login to the terminal (Ctrl+Alt+F1-F6) and remove the compiz settings directory from your home directory. Here is how you do that:

cd
mv .compiz-1 compiz-old

Now, restart compiz:

DISPLAY=:0.0 compiz --replace

Hope this helps.

[HOWTO] Enable Alt+F2 in Ubuntu Natty 11.04 Narwhal Alpha 1

If you have installed Ubuntu Natty Narwhal Alpha 1, you will notice the new Unity interface and hence no Gnome Panel(s) anymore. Since “Run Application” dialog is a part of gnome-panel, it is not possible to enable the same “Run Application” dialog. If you wish, you can achieve that by running the gnome-panel, but this is not the recommended course of action if you wish to keep running unity.
So, the other way to make it work is to use third party run dialogs from repositories. One of the best run dialog is gmrun. It is available in Ubuntu universe repositories. Open up the terminal (by pressing Ctrl+Alt+T) and type in the following to launch Synaptic Package Manager:

sudo synaptic

Then, go to Settings>Repositories and Enable the Universe repository.

After having done that, close the repository window and synaptic. In the terminal, type in the following:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install gmrun compizconfig-settings-manager

Now, lets launch compizconfig-settings-manager. Just type in the following in the terminal:

ccsm

Search for commands and enable it. Click on Commands to set commands and Key Bindings. In Command line 0, type in gmrun and in Key Bindings tab, click on the Disabled button and check Enable to Enable it. Press the Grab key combination button and press Alt+F2. In the dialog that pops up, click “Disable Run Applications”.

If all goes well, you can now press Alt+F2 and a “Run Program” dialog will pop up. You can use tab to complete fields and press Ctrl+R to search older run entries.

Hope this helps.

[HOWTO] Disable Unity Interface and restore original (classic) interface in Ubuntu Natty Narwhal

Unity interface is the default interface in Ubuntu 11.04 Natty Narwhal. It consists of the dock and launchers. However, if you don’t like the dock, animations and the interface as a whole, you can just disable it and login to Ubuntu Classic Desktop.

Logout and type in(or select) your username and in the bottom panel, select “Ubuntu Classic Desktop” instead of “Ubuntu Desktop Edition”. When you login next time, the same will be selected by default.

To re-enable Unity interface, just select “Ubuntu Desktop Edition” during login.