In this post I will be explaining you about adding Swap to Ubuntu manually after installing the Operating System.

If you are installing Ubuntu alone on the system, it won’t ask for adding the swap memory. All the time I am talking about Swap memory right, what is Swap memory actually?

Linux RAM consists of chunks of memory blocks called as Pages. If the pages are filled the system will become slow. To avoid this problem we will be adding Swap Memory. This will take some memory in the hard-disk and acts as an alternate RAM for Ubuntu. Linux swap allows the system to harness more memory that it was physically available.

However, allocating Swap Memory does have disadvantages. Because hard disks have a much slower memory than RAM, virtual private server performance may slow down considerably. Additionally, swap thrashing can begin to take place if the system gets swamped from too many files being swapped in and out.

Check for Swap:

Before we proceed to add a swap file we need to check whether there are any swap files are or not by having a look at the summary of swap usage. To check run the following command in the terminal.

sudo swapon -s

An empty list will confirm that you have no swap files enabled:

Filename                     Type                   Size                  Used                Priority

Check the File-system:

Once if we are confirmed that we do not have a swap file enabled, we can check how much space we have on the server with the df command. The swap file will take 512MB, since we are only using up about 8% of the /dev/sda, we can proceed.

Command: df

Filesystem       1K-blocks      Used           Available       Use%       Mounted on
/dev/sda2        20907056       1437188     18421292      8%             /
udev                  1964644          4                  1964640         1%            /dev
tmpfs                789380            804              788576           1%            /run
none                  5120                0                   5120                0%            /run/lock
none                 1973448          592              1972856         1%            /run/shm

Creating and Enabling the Swap file:

Now it’s time to create a swap file using the dd command.

sudo dd if=/dev/zero of=/swapfile bs=1024 count=512K

where of=/swapfile designates the file’s name. In this case the name is swapfile.

Subsequently we are going to create the swap file by creating the swap area:

sudo mkswap /swapfile

Now you will be able to see the manually created swap file in the swap summary.

sudo swapon -s

The results of the above command will be:

Setting up swapspace version 1,   size  = 262140 KiB no label, UUID=103c4545-5f-c5-47f3-a8b3-dfbdbd64fd7eb

Finish up by activating the swap file:

sudo swapon /swapfile

Now, you will be able to view the swap file in the swap summary:

sudo swapon -s

Filename                Type        Size            Used     Priority
/swapfile                 file          262140      0             -1

This file will be there on the virtual private server until the machine reboots. You can ensure the swap is permanent by adding it to the fstab file. To do this run the following command in the terminal:

sudo nano /etc/fstab

and paste the following lines there

/swapfile               none         swap         sw       0      0

Finally to prevent the file readable by the other users you need to give the necessary permissions for the swap file:

sudo chown root:root /swapfile

sudo chmod 0600 /swapfile

Note: It is not necessary to take the exact values as if it is in the post. Those values are directly pasted from my terminal when I was adding swap to my file system.

That’s it now you have created the swap file.

# My first bug fix: Mozilla

In this post I’ll be sharing about my experience on my first open-source contribution and installing the Mozilla browser source code for experimenting. This post contains answers for almost all the problems which you will be facing during the build (Mozilla Build). For beginners, simply this is what you have to follow if you want to contribute to Mozilla.

My experience with open-source contribution:

Before when I was in first year by seeing all my seniors, fixing bugs and contributing to open-source. After a while, when our sir told to start open-source contribution, I was completely confused at one point when I have to choose an organization to work on. Finally I have decided to work for Mozilla. It was really like solving the puzzle when I was trying to install the Mozilla source code. After doing lot’s of experiments some how I finally managed to complete the build. It was really funny trying to get through the errors and completing the build. After that it took a while for me to find some minor bugs to work on. When I was assigned to a bug and I was blank in the sense don’t know where to start and what to do. At that time I have decided to take help from IRC.  During my first bug fix I was asking silly silly questions and the people are a kind of irritated on me. But in IRC you will get help for almost all the questions which you have. Anyway it was really fun doing open-source contribution.

Installing Mozilla-browser source code:

Installing Mozilla Source code mainly involves the following steps:

• Installing the dependencies required for the build.
• Building the Mozilla source code.

You can get the mozilla.hg file either from here or from the Mozilla site. The mozilla.hg file is from where you will be installing the source code of the latest browser.

Installing the dependencies required for the build:

To get the build installed in your system you need to install the following the Linux build prerequisites which are nothing but the libraries which all are necessary for the build to get installed.

• sudo apt-get install mercurial g++ make autoconf2.13 yasm libgtk2.0-dev libglib2.0-dev libdbus-1-dev libdbus-glib-1-dev libasound2-dev libcurl4-openssl-dev libiw-dev libxt-dev mesa-common-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

Building the Mozilla source code:

The following installation process explains for people who all are installing the source code through mercurial(.hg) file. The mercurial build is preferred for the people who have very poor Internet connections. The mercurial bundle is nothing but like the off-line version of the hg clone which you can download and install when ever you want.

1. Initialize a new repository (in a directory called ‘mozilla-central’ here):

mkdir mozilla-central

hg init mozilla-central

Un-bundle the bundle file to that repository:

To use the below command in windows, export the \path\to\hg and invoke the command from command prompt.

cd mozilla-centeral

hg unbundle /path/to/your/bundle.hg

(The unbundle will take quite a lot of time)

3. Add the following lines to the file mozilla-central/.hg/hgrc which you may have to create it, so that hg will automatically know where to pull changes from in future (replacing  mozilla-central‘ as appropriate):

      [paths]
default = https://hg.mozilla.org/mozilla-central/

4. Update the repository to get all the changes since the bundle was created long back. To get the update run the following command in the mozilla folder.

      hg pull

5. Check out a working copy from your new up to date repository:

      hg up or hg update

You now have a clone of mozilla-central that is identical to one made via “hg clone”.

6. Now, you have done all the requirements to be done for the building the source code. The build is going to take quite a lot of time approximately 2 hours. So please be patient. To start the build run the following command in the terminal.

./mach build

7. Once if you have completed the build you can run the browser by using the following command.

/home/user-name/mozilla-central/obj-x86_64-unknown-linux-gnu/dist/bin/firefox

Note: If you have any problems during the build then feel free to comment in the post. 🙂