May 15

Linux: Understanding Symbolic Links

Understand the effects of a symbolic and hard link and how they differ.
What are they?

Symbolic links are like shortcuts or references to the actual file or directory. Most of the time these links are transparent when working with them through other programs. For example you could have a link to a directory to one hard drive inside a directory that lies on a different hard drive and an application will still treat it the same.

Symbolic links are used all the time to link libraries and make sure files are in consistent places without moving or copying the original. Links are often used to “store” multiple copies of the same file in different places but still reference to one file.
Creating a Symbolic Link

To create a symbolic link in Linux we use this syntax:
ln -s /path/to/original/ /path/to/linkName

What happens if I edit the link? Any modifications to the linked file will be changed on the original file.
What happens if I delete the link? If you delete the link the original file is unchanged. It will still exist.
What happens if I delete the original file but not the link? The link will remain but will point to a file that does not exist. This is called an orphaned or dangling link.
Creating a Hard Link

You can create a hard link like so:
ln /path/to/original.file /path/to/link.file
The Difference Between Soft and Hard Links
Hard links

Only link to a file not a directory
Can not reference a file on a different disk/volume
Links will reference a file even if it is moved
Links reference inode/physical locations on the disk

Symbolic (soft) links

Can link to directories
Can reference a file/folder on a different hard disk/volume
Links remain if the original file is deleted
Links will NOT reference the file anymore if it is moved
Links reference abstract filenames/directories and NOT physical locations. They are given their own inode

Practice Makes Perfect

To really grasp the concept of symbolic links lets give it a shot.

Go into the tmp directory:
cd /tmp

Make a directory
mkdir original

Copy over the host.conf file or any file to test with.
cd original
cp /etc/host.conf .

List the contents and take note of the inode (first column)
ls -ila

Create a symbolic link to host.conf called linkhost.conf
ln -s host.conf linkhost.conf

Now do list out the inodes
ln -ila

Notice how the inode for the link is different.

Now create a hard link to the same file
ln host.conf hardhost.conf

Now list the inoes one more time
ln -ila

Notice how the inode numbers are exactly the same for the hard link and the actual file.

Lets try some file operations now

Open up linkhost.conf and edit it and save it

Now look in host.conf and notice that the changes were made

Lets move host.conf now and see if it causes any problems
mv host.conf ../

Uh oh, now when we list the directory our link turned red lets see what is in side it
cat linkhost.conf
cat: linkhost.conf: No such file or directory

It looks like our symbolic link is now broken as it linked to a file name and not the inode. What about our hard link?
cat hardhost.conf

Looks like our hard link still works even though we moved the original file. This is because the hard link was linked to the inode the physical reference on the hard drive where the file resides. The soft link (symbolic link) on the other hand was linked to the abstract file name and was broken the moment we moved the file.

This leads to an interesting question. What happens if I delete a hard link? Even though the hard link is referenced to the physical location of the file on the hard drive though an inode, removing a hard link will not delete the original file.

Symbolic links will remain intact but will point to a non existent file.

By: Mark Sanborn

Category: Linux | Comments Off on Linux: Understanding Symbolic Links
May 15

Linux: Manage Time in Ubuntu Through Command Line

View Time

To view the current date and time, the following command will be enough

date
Set Time

To change time means to set a new time. To set time in Ubuntu (or any Linux), just run the following command

sudo date newdatetimestring

where newdatetimestring has to follow the format nnddhhmmyyyy.ss which is described below

nn is a two digit month, between 01 to 12
dd is a two digit day, between 01 and 31, with the regular rules for days according to month and year applying
hh is two digit hour, using the 24-hour period so it is between 00 and 23
mm is two digit minute, between 00 and 59
yyyy is the year; it can be two digit or four digit: your choice. I prefer to use four digit years whenever I can for better clarity and less confusion
ss is two digit seconds. Notice the period ‘.’ before the ss.

Let’s say you want to set your computer’s new time to November 25, 2013, 21:40:55, then you would use:

sudo date 112521402013.55

It couldn’t be any easier, could it? The source of this information was a good post on Ubuntu Forums (Set time/date via command line).
Change Time Zone

You may update or change your time zone by

tzconfig
dpkg-reconfigure tzdata (thanks to Mario, see comment below)

This command will guide you through the process of setting a new time zone. You may also choose UTC (GMT) if you want.

If your system does not have tzconfig, you may use something else.

tzselect

If your system does not have tzdata, install it as below:

sudo aptitude install tzdata

This will provide a set of different time zones to choose. If you would like to set the time to UTC, choose the option which says something like ‘none of the above’, or ‘none of these’ or something to this effect. In my case it was option 11. Then it asks for difference from UTC (GMT and GST is also the same thing). I chose GST-0 as the option and it set the time as UTC.
Sync Clock Via NTP

If you want to sync your clock with NTP servers, it is also very easy. Just make sure you have the file ntp.conf file in /etc. How can you check it?

ls /etc/ntp.conf

If you see /etc/ntp.conf as a result, you already have that file. If the ls command gives an error, you do not have it. If so, you may create it yourself.

sudo vim /etc/ntp.conf

This file will be used to automatic synchronization of the clock. I do not know if the client uses this file automatically or one has to configure something first.  You need to install ntpd in order to make use of this ntp.conf file.

Whether you have the file already or not, make sure it has at least the following data

driftfile /var/lib/ntp/ntp.drift
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server pool.ntp.org

Here you may replace, add, and/or remove any servers you wish. You will find a list of time servers from the public NTP time server list.

You may manually sync the clock using the following

sudo ntpdate servername

where servername can be any public or private time server. You may always choose the following without hesitation

sudo ntpdate pool.ntp.org

If you don’t have ntpdate installed, you can install it via:

sudo aptitude install ntpdate

By: HS

Category: Linux | Comments Off on Linux: Manage Time in Ubuntu Through Command Line
April 21

Linux: Finding a File containing with a particular text (grep)

grep command form (syntax)

grep “text string to search” directory-path

Examples

For example search for a string called redeem reward in all text files located in /home/tom/*.txt directory, use
$ grep "redeem reward" /home/tom/*.txt

Task: Search all subdirectories recursively

You can search for a text string all files under each directory, recursively with -roption:
$ grep -r "redeem reward" /home/tom

Task: Only print filenames

By default, grep command prints the matching lines You can pass -H option to print the filename for each match.
$ grep -H -r “redeem reward” /home/tom
Output:

...
filename.txt: redeem reward
...

To just print the filename use cut command as follows:
$ grep -H vivek /etc/* -R | cut -d: -f1
Output:

...
filename.txt
...

By: Nixcraft
Category: Linux | Comments Off on Linux: Finding a File containing with a particular text (grep)
April 6

Linux: ZFS pool migration – troubleshooting notes – Ubuntu mount on reboot issues

Migrating and existing ZFS pool to a new server
1. Export spool from older server
2. Attach drives
3. Type: zpool import – The drives will be listed with their drive ID’s
First major issue:
In my case I had two ID’s for the two drives that were being mirrored.  I  could import either one, but importing the wrong one made it so I could no longer see the correct pool.  Even after a reboot the second and correct pool was unavailable to even be discovered.  I exported the pool and then reconnected the drives to my original server which was Open Indiana.  I then ran spool import and was able to see both ID’s I re imported the correct ID and everything was working on the original server.
Apparently I have created the same pool name under both ID’s the main issue was the first ID was version 13 and the second ID was version 28.  I exported the working pool imported the non working older pool and ran “zpool upgrade datapoolname 28”.  I exported the data pool again and reattached it to the new server.  This resolved some strange import errors.
4. spool import 11036020738792080304 -f
I was getting “directory not empty” errors and errors stating that the pools cannot be mounted.
5. Type: zfs get mountpoint – discovered that the SOURCE showed that the mount points were imported
I decided to clean up my mount points by reassigning them
I set the root directory mount point to none since the main volumes are underneath it and I was getting directory not empty errors
6. Type: zfs set mountpoint=none datapoolname
7. Type: ifs set mountpoint=/export/data/directoryname1 datapoolname/directoryname1
8. Type: ifs set mountpoint=/export/data/directoryname1 datapoolname/directoryname2
This change the SOURCE to a LOCAL setting
9. Typed:  zfs set sharesmb=on datapoolname – The pools would mount, but I would still get errors and they would not remount on a reboot.
This lead me to my final issue which became getting my zpool to mount on reboot.
After a couple of hours of reading and testing I discovered that a lot of people are having this problem with ZFS on Ubuntu.
10. I ended up modifying the end of /etc/rc.local with the following:
zfs mount -a
exit 0
Now on reboot the pools are automatically loading.

By: Nighthawk

Category: Linux | Comments Off on Linux: ZFS pool migration – troubleshooting notes – Ubuntu mount on reboot issues
April 5

Linux: Centos – System stops booting at atd service

In VirtualBox after upgrading Centos 6.3 to 6.4 the server would freeze after the graphical start-up bar moved all of the way to the right.
I dropped into single user mode on the server and ran init 5
The start up process would hang after posting “Starting atd [ok]”

I rebooted back to single user mode and went to see what service followed atd

I looked through /etc/rc5.d which lead me to rc.local being the last script to run
Nothing of significance was trying to run in rc.local

I made the assumption that the problem must be with gnome.

I ran startx

I received the message (EE)module ABI major version (10) doesn’t match the server’s version (13)

I went to /etc/X11/xorg.conf and mv’d it to xorg.conf-old

I then rebooted and the issue was resolved.

Category: Linux | Comments Off on Linux: Centos – System stops booting at atd service