Category Archives: Linux_Command

Sharing history all around terminals in Linux.

By default, a terminal doesn’t share its history with another one. For example, you open a terminal(1) and type some commands. You need one more a terminal and then open another terminal(2). These terminal(1) and terminal(2) do not have the same history. (You can easily check by typing ‘history’)

All what you need to do for sharing the history for all opened terminal is adding the following code in “.bashrc” file. (Ubuntu 11.04)

export PROMPT_COMMAND='history -a; history -r'

More explanation about options, googling history.

Don’t forget “source” after editing “.bashrc” file in order to apply your changes.

Grub rescue prompted after upgrade OSX to 10.8 (Mountain Lion)

I installed dual boot, OSX and Ubuntu on my Macbook pro. After upgrading to 10.8 Mountain Lion, a frustrating thing happened. I can’t boot Ubuntu at all. Rather it keeps saying 

error: unknown filesystem.
grub rescue

It is not a shell and very limited commands can be used for this grub-rescue mode. After googling, I found the reason and solution for this.

1. Reason: The partition on my HD was changed when OSX was installed.

Source from:

When you get a grub rescue prompt, it means that the grub bootloader cannot locate it’s modules from the partition that contains them in /boot/grub. The reason for this is that the code that fits in the drive MBR record is tiny, and so it’s main purpose is to locate and load the rest of the bootloader code. Once it’s loaded it’s modules it can present the grub menu and handle the rest of the boot process. If it can’t find the modules, it presents a very limited rescue prompt.

So, what you are seeing is totally normal if you repartitioned, thereby breaking the reference the bootloader had to the partition containing the boot modules.

Since you can boot manually, the simplest fix is to manually boot and reinstall the bootloader in the MBR so that it has the correct reference to your partition. The way to do that is:

sudo grub-install /dev/sda

This assumes you boot from /dev/sda (most cases, but if not replace with the correct drive).

This solution is far simpler than using the boot-repair, but if you are unsure this may be more suitable.


2. Solution: (Original contents come from the following link. Note that it can boot into Linux installation but permanent grub partition setting procedures are wrong.

When I use the set command on grub-rescue mode, I see this:


You need to find the correct partition point where contains grub. In order to do this, the following link is very helpful but quite long. Only thing what we are looking for is

Command line tips:

  • Drives start counting at 0 (sda=0, sdb=1, etc). Partitions start counting at 1 (1=1, etc). Substitute the correct drive letter for X, correct number for Y, and substitute the correct numbers for (hd0,1).

  • You must type the entire path and kernel and initrd names if (hdX,Y)/vmlinuz and (hdX,Y)/initrd.img do not exist. You can check by running this command:

    • ls (hdX,Y)/
  • If vmlinuz and initrd.img do not exist at (hdX,Y)/, you can simplify the typing using the TAB complete feature.

  • On the linux line, type “vml” and then TAB to help complete the kernel number. Ensure the complete kernel name is entered. Be sure to fill the kernel number completely, and don’t forget the “root=” and “ro” sections of the linux line.

  • On the initrd line, type “ini” and TAB to fill in a large part of the name. Continue typing/TABBING to ensure the complete .img name is used.

  • Sections in bold should be changed to match the user’s system.

Type ls to show partition layout in grub-rescue mode.


In order to locate pointing the right point this link might help.

It is also quite long and a complicated article, only thing what we need is:

Locate the Ubuntu partition and the folder containing the Grub modules.
The Grub folder containing the modules must be located so the correct modules can be loaded. This folder would have been created during the initial installation of Ubuntu and should be located in the Ubuntu partition. This folder would normally be located at either (hdX,Y)/boot/grub or(hdX,Y)/usr/lib/grub/i386-pc

Find your existing Ubuntu partition and the module folder.

ls                               # List the known drives (hdX) and partitions (hd<span style="color: red;">X,Y</span>)
ls (hd<span style="color: red;">X,Y</span>)/                      # List the contents of the partition's root
ls (hd<span style="color: red;">X,Y</span>)/boot/grub             # Normal location of the Grub 2 modules.
ls (hd<span style="color: red;">X,Y</span>)/usr/lib/grub/i386-pc  # Alternate location of the Grub 2 modules.
  • ls – should return all known drives (hdX) and partitions (hdX,Y)
  • ls (hdX,Y)/ – should show the contents of the root directory of the partition.
    • If you get an “error: unknown filesystem” this is not your Ubuntu partition; more on that later.
    • If this is the Ubuntu partition, you will see the Ubuntu folders, including lost+found/home/boot/ and vmlinuz and initrd.img. Use this address as the first part of the next command.
  • ls (hdX,Y)/boot/grub – should display several dozen *.mod files. This is the folder you are looking for.
    • If you don’t find the modules, try the alternate location: ls (hdX,Y)/usr/lib/grub/i386-pc

After exploration, I found my Linux installation was installed hd0,gpt4 not hd0,gpt3.

Then following commands lines will boot into your Linux system.

set prefix=(hd0,gpt4)/boot/grub
set root=(hd0,gpt4)
insmod /boot/grub/linux.mod
linux /vmlinuz root=/dev/sda4 
initrd /initrd.img

This successfully booted me into ubuntu. Next, the discussion suggested running the following in a shell:

Generate grub configuration file.

sudo update-grub

Then install grub into your partition (hd0,gpt4)

sudo grub-install --recheck /dev/sda

IMPORTANT: It is not /dev/sda4 but /dev/sda

In summary, this post deals with a little bit complicate topics, grub-rescue and grub-reconfiguration and partitions. The links in this post covers these topic in depth and very long and sophisticate. Therefore there are massive, messy and nasty copy-n-paste contents from the original links. Those who want to read and understand more stuffs behind this article, please have a look the following links.

Fixing apt-get install auto completion.

I installed Ubuntu 12.10 on my odriod and auto completion just didn’t work.

It is a very useful feature to install using apt-get but the ubuntu provided from Hardkernel company didn’t include bash-completion package.

Therefore, installing bash-completion first

sudo apt-get install bash-completion

then appending the following lines into your .bashrc file.

if [ -f /etc/bash_completion ]; then
 . /etc/bash_completion

Finally, apply the changes to a terminal.

 source ~/.bashrc