Showing posts with label Linux - How to's. Show all posts
Showing posts with label Linux - How to's. Show all posts

Time sync with NTP server

A simple time lag on a remote server could be the root-cause of many issues ranging from missing logs to data inconsistencies. The following technique can help in syncing the server with the NTP server to reset the lag.

Check for NTP server that is referenced currently
root~# ntpq -p
remote refid st t when poll reach delay offset jitter
===========================================================
pool.ntp.org .INIT. 16 u - 1024 0 0.000 0.000 0.000
Compare current date on local machine vs NTP server
root~# rdate -n -p pool.ntp.org
Mon Jun 16 18:44:46 UTC 2014
root~# date
Mon Jun 16 18:25:03 UTC 2014
Update local machine Time (remove “-p” from rdate command)
root~# rdate -n pool.ntp.org
Mon Jun 16 18:45:35 UTC 2014
root~# date
Mon Jun 16 18:45:37 UTC 2014

VirtualBox Guest Additions on Linux | Missing kernel headers

If you think the VirtualBox Guest Additions has not installed correctly/completely, do the following:
sudo /etc/init.d/vboxadd setup
If there are any error messages, please refer to the following file for hints.
/var/log/vboxadd-install.log
If there are errors similar to the one shown below, read further for the solution.
/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  Stop.
Install the headers for the current running kernel.
sudo apt-get install linux-headers-$(uname -r)
Re-install the Guest Additions.
sudo /etc/init.d/vboxadd setup
Try if things are working fine. Say mount a shared folder.
sudo mount -t vboxsf share /home/jack/host
The above scenario was faced and resolved on Debian Squeeze. The commands should hold good for any Linux distro.

GDB | Core file analysis

All that is required to use the GNU Debugger (gdb) is the core file and the binary/executable file (with debugging symbols included) that actually caused the core. If the same version is not available, the closest one can be used.

Run the gdb using the following command:
$ gdb <binary_file_path> <core_file_path>
On the gdb prompt, use the following commands for further debugging:
$ bt                    
(short for backtrace, to get a stack trace and each frame's number from the time of the crash)

$ where
(an alternative to backtrace)

$ frame <stack_frame_number>
(replace number with the corresponding number in the stack trace to select a particular stack frame)

$ list
(to see code around that function)

$ info locals 
(to see the local variables)

$ print <name_of_variable> 
(replacing "name_of_variable" with a variable name, to see its value)

$ help
(to see additional commands)

Mount USB Drive in Linux | How to

To use an USB drive in Linux, just insert it into the USB drive slot on your PC. Usually a pop-up will appear and guide you. If it does not happen, type 'dmesg' command & locate your USB drive. The output should be something like this.

$ dmesg
...
...
USB Mass Storage Device Found /dev/sda1 ...
...

If you are unable to locate it in the above mentioned way, use the 'fdisk -l' command at the prompt. In addition the existing partitions, you will get some additional output as follows.

$ fdisk -l
...
...
Disk /dev/sda: 8036 MB, 8036285952 bytes
255 heads, 63 sectors/track, 977 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         978     7847904    c  W95 FAT32 (LBA)
Partition 1 has different physical/logical endings:
     phys=(976, 254, 63) logical=(977, 5, 51)

The /dev/sda1 is where your Linux has a new block device for your USB drive. You need to mount it now to access its contents. This can be done by the mount command using the following 2 steps.

$ mkdir /mnt/usb
$ mount /dev/sda1 /mnt/usb

Now, you can navigate to the /mnt/usb directory and access the contents in the USB drive. When you want to disconnect your USB drive after usage, do not forget to unmount it using the following command.

$ umount /dev/sda1 /mnt/usb