Posts Tagged ‘Ubuntu’

Remove old linux kernels

Posted: January 12, 2013 in System Administration
Tags: ,

When upgrading linux kernel, Ubuntu does not automatically remove previous version of the kernel. Yup, it is good if you keep the previous version, so that if anything crashes (eg: your driver is incompatible with the new kernel), you may revert to the old kernel. However, sometimes the old kernels may accumulate and fill up your disk space. Therefore, if you are running fine on your current kernel, you can choose to remove the old ones to free up some disk space. Here’s how you can do it.

  1. Launch your preferred package or software manager. The new Ubuntu ships with Ubuntu Software Center, so you may use that.
  2. Under installed software, search for linux-image.
  3. Remove all kernels other than your current version. (You may find out your kernel version by executing “uname -r” on the terminal.) Using the screenshot below as example, the current kernel version is 3.2.0-35-generic-pae. So we will remove other kernels, which are 3.2.0-23-generic-pae, 3.2.0-24-generic-pae, and 3.2.0-29-generic-pae. The package ‘Generic Linux kernel image’ needs not be removed because it is just a meta-package to pull in the latest kernel image.
  4. Ubuntu Software CenterThen, under installed software, search for linux-headers.
  5. Do the same as step 3. Remove previous version of the linux headers.
  6. Remove GRUB entries for older kernels.

The Nautilus file manager in Ubuntu features a search-for-document tool for quite a long time. However, its functionality is quite limited as it allows the user to search only for file name, but not the contents of the file. Personally, I was quite shocked because the ability to search for file contents has been available in its Microsoft counterparts since Windows 98.

Apparently, Linux users are more proficient at the command line. Grep is a command line tool that allows the user to search for specific pattern or text, given lines from the standard input or a file. Once you know grep, searching the content of files will become so easy as never before.

To search in a single file, use the following command. (Please do not type in the ‘$’, which is the prompt symbol for a terminal).

$ grep "Search text" filename.txt

Typically, we would like to look up the file contents of the whole directory. We can use the -r option to search recursively under a directory and use the -l option to suppress printing every matched lines and printing only the matching file names.

$ grep -r -l "Search text" dir

Or instead, if we wish to print every lines, the -n option can be used to print line numbers.

$ grep -r -n "Search text" dir

Besides, grep supports the use of regular expression by passing it the following options: -G (Basic RegExp), -E (Extended RegExp), and -P (Perl RegExp).

Below are some other usage of grep, which uses piping, i.e taking the output of another command and directing it back into the standard input, so that grep can search within the output. Some of us probably have known these commands before digging deep into grep, since these commands are so widely use.

$ lspci | grep 'Network'
$ egrep '(vmx|svm)' /proc/cpuinfo
$ ls -l | grep rwxrwxrwx
$ ps -A | grep -i firefox
$ du | grep 'mp3' | more
$ dmesg | egrep '(s|h)d[a-z]'
$ ps -ef | egrep '^root ' | awk '{print $2}'
$ lsof | grep -i TCP
$ lsof | grep ' root ' | awk '{print $NF}' | sort | uniq | wc -l

Finally, I would leave it for you, the reader, to figure out what each the above command does.

I’ve kept a Ubuntu Server installed on my laptop for almost a year. Only until recently that I have tried to connect the server through the wireless networking card. Indeed, I’ve been through some hard times, searching and trying desperately to get the wireless card to work. The server doesn’t have a desktop manager, i.e no GUI, so everything has to be done in the terminal. So here I am to explain the whole process to ease others who would also wish to configure their networks using the command line.

  1. The first step is to check that you have the appropriate tools installed. In the command line, type in the following.
    sudo apt-get install wireless-tools

    This will install the Wireless Tool package containing the following tools:

  2. Next find out the chipset of your wireless card. To do this, type in
    lspci | grep Network


    lsusb | grep Network

    depending on whether you use a pci or usb card. The output will be like

    02:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)
  3. Now you know your chipset. Some wireless chipsets work out of the box. In my case, it’s a Broadcom chipset and it’s not supported by default. For this step try google for the appropriate drivers, or you may use ndiswrapper if your Wifi card comes with a Windows driver.
  4. After installing the driver, make sure the card can be detected.

    The command will list your wireless card. For example:

    lo        no wireless extensions.
    eth0      no wireless extensions.
    eth1      unassociated  ESSID:off/any
              Mode:Managed  Channel=0  Access Point: 00:00:00:00:00:00
              Bit Rate=0 kb/s   Tx-Power:off
              Retry:on   RTS thr:off   Fragment thr:off
              Power Management:off
              Link Quality:0  Signal level:0  Noise level:0
              Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
              Tx excessive retries:0  Invalid misc:0   Missed beacon:0
    virbr0    no wireless extensions.
    pan0      no wireless extensions.

    Sometimes, the wireless card is disabled so you get “no wireless extensions” for every device.
    You can activate your card by typing

    sudo ifconfig eth1 up

    Then re-execute iwconfig to make sure it is okay.

  5. Issue the following command to scan for wireless network.
    sudo iwlist eth1 scan

    and the output:

    eth1      Scan completed :
              Cell 01 - Address: 00:22:6B:6A:3E:85
                        Frequency:2.437 GHz (Channel 6)
                        Quality:5/5  Signal level:-50 dBm  Noise level:-90 dBm
                        Encryption key:off
                        Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                                  24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s
                                  12 Mb/s; 48 Mb/s
  6. Connect to the access point of your own choice. The ESSID is the identification name given to an access point. Identify the ESSID you wish to connect.
    sudo iwconfig eth1 essid "FKMWifi"
    sudo iwconfig eth1 mode managed
    sudo iwconfig eth1 commit
  7. For WEP or WPA encrypted network, you need to input the key. For WEP encrypted networks, the following two commands applies. Use the first command if you have an ASCII key and it will translate the key to its hexadecimal form.
    sudo iwconfig eth1 key s:password
    sudo iwconfig eth1 key 70617373776f7264

    For WPA encrypted network, you have to generate the WPA-PSK key using the essid and your password.

    wpa_passphrase <your_essid> <your_ascii_key>

    And the output will be something like


    Notice the last line of hex gibberish. Use that as your WPA-PSK key and issue the command

    sudo iwconfig eth1 key b51f838d5e7ea198d2dc141350687f6ea7b1995215c9b40b302dc6ca96c94537
  8. Obtain an IP address from the DHCP server by issuing the command
    sudo dhclient eth1

    The output similar to the below will be printed.

    Listening on LPF/eth1/00:21:00:b7:db:2d
    Sending on   LPF/eth1/00:21:00:b7:db:2d
    Sending on   Socket/fallback
    DHCPREQUEST of on eth1 to port 67
    DHCPACK of from
    bound to -- renewal in 240 seconds.
  9. Ping an publicly known address to check that everything works.
  10. Additionally, you might want to save the hassle by configuring your network to connect automatically once your computer starts. Modify /etc/network/interfaces by adding the following lines.
    sudo vim /etc/network/interfaces

    For WEP encrypted network:

    auto wlan0
    iface wlan0 inet dhcp
    wireless-essid   <your_essid>
    wireless-key     <your_password>

    For WPA encrypted network:

    auto wlan0
    iface wlan0 inet dhcp
    wpa-ssid <your_essid>
    wpa-psk <your_wpa_psk_key>

Other resources:
WifiDocs – Ubuntu Official Documentation
Configuring encrypted wireless network