Search This Blog

Loading...

Monday, January 26, 2015

Using gdebi to install and resolve dependencies for a local deb file

Debian comes with over 37,500 packages in its default distribution. Yet, occasionally, we still need to install a package which has not made it into the default distribution.

If your current system already has all the prerequisite packages installed, then life is good. You simply download the deb file, and install it with the dpkg command:

$ sudo apt-get update
$ sudo dpkg -i somelocal.deb

But, if you run into package dependency problems, you are on your own. The dpkg command does not resolve dependency problems for you.

For a Debian or Ubuntu system, a better way to install a local package is to use the gdebi command. The gdebi command accesses the repositories specified in your /etc/apt/sources.list file to resolve any dependencies.

First, install gdebi by running the following commands.

$ sudo apt-get update
$ sudo apt-get install gdebi

You need to be root in order to run the gdebi command to install a package.

$ sudo apt-get update
$ sudo gdebi somelocal.deb

Using the gdebi command saves you time if you run into dependency problems while installing a local deb package.

Sunday, December 21, 2014

How to create a swap file

Linux can be configured to use swap space, aka secondary disk storage, when physical memory is running low. Swap spaces can be allocated as disk partitions ('swap partitions') or as files ('swap files'). While swap partitions are generally preferred over swap files, if your system is a virtual private server (VPS) without a pre-configured swap partition, creating a swap file may be your only option. The following procedure describes how to create a swap file.

List swap spaces

Before you create a swap file, you should first check whether the system has any swap space pre-allocated. The easiest way is to run the free command.

$ free -h total used free shared buffers cached Mem: 497M 490M 6.2M 0B 14M 101M -/+ buffers/cache: 375M 121M Swap: 0B 0B 0B

The line labeled Swap above tells you that there is no swap space configured.

Alternatively, run the swapon command with the -s parameter:

$ sudo swapon -s Filename Type Size Used Priority

I prefer free because root privilege is not required to run the command.

Create swap file

Follow the steps below to create and activate a swap file.

  1. Create a new file pre-allocated with the desired file size.
    $ sudo fallocate -l 500M /var/swap.img

    The above command pre-allocates 500 megabytes for the file /var/swap.img.

  2. Secure the new file.
    $ sudo chmod 600 /var/swap.img
  3. Make a swap file.

    The following mkswap command sets up /var/swap.img as a swap file.

    $ sudo mkswap /var/swap.img Setting up swapspace version 1, size = 511996 KiB no label, UUID=a0a90414-adab-4c50-8b27-0d27f0c34448
  4. Activate the swap file.
    $ sudo swapon /var/swap.img

    After executing the above swapon command, verify that the swap file is indeed enabled.

    $ free -h total used free shared buffers cached Mem: 497M 464M 32M 0B 14M 104M -/+ buffers/cache: 346M 151M Swap: 499M 34M 465M $ sudo swapon -s Filename Type Size Used Priority /var/swap.img file 511996 35184 -1

    According to the above output, the swap file has been enabled. However, unless you complete the next step, the swap file will be disabled when you reboot the machine.

  5. Update file system table.

    Add the swap file to the file system table using the following command:

    $ sudo sh -c 'echo "/var/swap.img none swap sw 0 0" >> /etc/fstab'

Wednesday, December 3, 2014

How to change system timezone

When you initially install Linux, you specify the machine's timezone. After the install, you can manually change the timezone. The following procedure applies to Debian and Ubuntu systems.

Before you change the timezone, let's find out what timezone your system is currently in.

$ date Tue Dec 2 13:53:11 PST 2014

The above date command tells you that the system is on PST, aka Pacific Standard Time.

You can change the timezone interactively or through batch processing.

Interactive setup

The following command guides you through 2 screens to configure the timezone.

$ sudo dpkg-reconfigure tzdata

The advantage of specifying the timezone interactively is that you don't have to know the exact name of the timezone. The program will guide you to select your target timezone. But, if you want to automate the process through a shell script, please follow the batch method as explained below.

Batch setup

  1. Identify the name of the target timezone.

    Timezone data files are stored in the /usr/share/zoneinfo directory tree. Each continent has a corresponding subdirectory, e.g., /usr/share/zoneinfo/America. Each continent subdirectory contains timezone files named by cities in the continent, e.g., /usr/share/zoneinfo/America/Vancouver.

    $ ls /usr/share/zoneinfo/America

    Note the city where your system is located (or the nearest city in the same timezone). The timezone identifier is the concatenated continent and city names, e.g., America/Vancouver.

  2. Specify the timezone in /etc/timezone.
    $ sudo -s sh -c 'echo America/Vancouver > /etc/timezone'
  3. Run configure program.
    $ sudo dpkg-reconfigure -f noninteractive tzdata

Monday, November 24, 2014

Free on-line Introduction to Linux course

In August 2014, more than 300,000 people registered for the first offering of the Introduction to Linux course. This popular Massive Open Online Course (MOCC) is taught by the Linux Foundation, and hosted on edx. The same course starts again on January 5, 2015.

The course is designed for people who have limited or no previous exposure to Linux. Despite that, I have enrolled in it, thinking that I will pick up some new knowledge anyway. Because it is self-paced (and free), if it proves to be too easy, I will just skip the course content.

If you are interested, please go enroll at edx today.

Thursday, November 20, 2014

How to split an image for visual effects

Suppose that you've just taken a panorama photograph with your fancy digital camera.

You can display the picture as is on your blog. Or you can be a little bit more creative. How about splitting it up into 3 rectangular pieces?

Or even into 2 rows like the following.


To crop a photo into rectangular pieces, use the convert program from the ImageMagick software suite. If your system runs on Debian or Ubuntu, install ImageMagick like this:

$ sudo apt-get install imagemagick

The original panorama image (P3190007.JPG) is 4256 x 1144 pixels in width and height respectively. The following command crops the image into tiles of 1419 x 1144 pixels. The output files are named tile_, and numbered sequentially starting from 0.

$ convert -crop 1419x1144 P3190007.JPG tile_%d.JPG $ ls -al tile* -rw-r--r-- 1 peter peter 337615 Nov 19 21:45 tile_0.JPG -rw-r--r-- 1 peter peter 300873 Nov 19 21:45 tile_1.JPG -rw-r--r-- 1 peter peter 315006 Nov 19 21:45 tile_2.JPG

The convert program can automatically calculate the width and height dimensions of the output tiles. You simply tell it the number of columns and rows. For example, '3x1@' means 3 columns and 1 row.

$ convert -crop 3x1@ P3190007.JPG tile_%d.JPG

If you want to stitch the component images back together, execute the following command:

$ convert tile_*.JPG +append output.JPG

The +append parameter tells convert to join the images side by side. If, for whatever reason, you want to stack them up vertically, specify -append instead.