Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Tuesday, October 7, 2014

Disk Metadata : Superblock, Directory and Inodes

Metadata
Filesystem blocks are user for 2 purposes : To store User data and Metadata
  • User data - stores actual data contained in files
  • Metadata - stores file system structural information such as superblock, inodes, directories
Metadata describes the structure of the file system. Most common metadata structure are superblock, inode and directories.

Superblocks
Every FS has a superblock which contains info about filesystems such as :
  • File system type
  • Size
  • Status
  • Information about other metadata structures
    • For filesystems with 1k blocksizes, a backup superblock can be found at block 8193
    • For filesystems with 2k blocksizes, at block 16384
    • For 4k blocksizes, at block 32768.
List backup superblocks:
# dumpe2fs /dev/hda3 | grep -i superblock

If Superblock  is corrupted, restore with backup :
# e2fsck -f -b 8193 /dev/sda3
 
Inode
 
 An inode is a data structure on a Linux Unix FS which stores stores basic information about a regular file, directory, or other file system objects.  

Monday, April 28, 2014

Recover deleted files used by any process in Linux from RAM memory.


Every thing in Linux is a File. A file in turn is actually a pointer to inode which contain the actual data on the disk, permissions, ownership. Now what happens when a file is deleted ? Only the link is removed by not the inode or the actual data. if a process is using the file, or if the file is open , the inode is not released for overwriting util the process is done with the file. Such files will remain in the server memory (RAM). 

Lets discuss how to recover such deleted files which is being used by a process.

Lets do it with an example.

Create a test file.
# touch testfile.txt

Echo some random data on it.
# cat /dev/random > testfile.txt

Open the file using some command like below.
# less  testfile.txt

# ps -ef | grep -i less
less 4607 root  4r  REG 254,4   21  
           8880214 /root/testing.txt (deleted)

All the open files remain in the memory and hence in the /proc filesystem. The important columns in the above output are the second one, which gives you the PID of the process that has the file open (4607), and the fourth one, which gives you the file descriptor (4). Now, we go look in /proc, where there will still be a reference to the inode, from which you can copy the file back.

# ls -l /proc/4607/fd/4
lr-x------ 1 root root 64 Apr  7 03:19 
             /proc/4607/fd/4 -> /root/testing.txt (deleted)
  
To recover the deleted file in memory, just copy as below.
 #cp /proc/4607/fd/4 testing.txt.bk


Hurray you got your file back. Just make sure not to use "-a" switch while copying the file as this will copy the broken softlink.

JK

 

Tuesday, April 8, 2014

Sendmail Error : NOQUEUE: SYSERR(root): No local mailer defined NOQUEUE: SYSERR(root): QueueDirectory (Q) option must be set

Error using m4 macro while building sendmail.cf from sendmail.mc on RHEL 6 / CentOS 6 flavors?

[root@cent1]# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
m4:/etc/mail/sendmail.mc:10: cannot open `/usr/share/sendmail-cf/m4/cf.m4': No such file or directory
[root@cent1]#

The above error is because the package sendmail-cf is not installed.


You will have the below error messages on the /var/log/maillog file also. 

sendmail[3215]: gethostbyaddr(10.0.3.15) failed: 2
sendmail[3215]: NOQUEUE: SYSERR(root): No local mailer defined
sendmail[3215]: NOQUEUE: SYSERR(root): QueueDirectory (Q) option must be set

The above error is because the sendmail.cf is not configured properly. 

Fix is to install the package sendmail-cf, build sendmail.cf from sendmail.mc and restart sendmail service.

Install the sendmail-cf

# yum install -y sendmail-cf


Comment the entry which makes the sendmail listens only to loopback address as below by adding "dnl" on /etc/mail/sendmail.mc

# vi /etc/mail/sendmail.mc
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

# service sendmail restart

Check if sendmail is started properly.

[root@cent1 ~]# netstat -tulnp |  grep -i :25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      3748/sendmail
[root@cent1 ~]#

Hope this helps.
Jk


Thursday, April 25, 2013

Set Setuid, Setgid and Sticky bit in Linux

Special permissions on files and directories in linux are : SetUID, SetGID and Sticky bit.

With the help of “chmod” command  we can implement the special permissions on file and directories.

SUID / Set User ID : A program is executed with the file owner's permissions (rather than with the permissions of the user who executes it).

SGID / Set Group ID : Files created in the directory inherit its GID, i.e When a directory is shared between the users , and sgid is implemented on that shared directory , when these users creates  directory, then the created directory has the same gid or group owner of its parent directory.

Sticky Bit :  It is used mainly used on folders in order to avoid deletion of a folder and its content by other user though he/she is having write permissions. If Sticky bit is enabled on a folder, the folder is deleted by only owner of the folder and super user(root). This is a security measure to suppress deletion of critical folders where it is having full permissions by others.

Wednesday, January 16, 2013

Network Bonding / NIC Teaming in Linux


Network Bonding :- NIC teaming or network bonding is nothing but combining or aggregating multiple network connections in parallel. This is done to increase throughput, and to provide redundancy in case one of the links fails or Ethernet card fails. The Linux kernel comes with the bounding driver for aggregating multiple network interfaces into a single logical interface called bond0.

Bonding is nothing but Linux kernel feature that allows to aggregate multiple like interfaces (such as eth0, eth1) into a single virtual link such as bond0. The idea is pretty simple get higher data rates and as well as link failover. Steps To Configure Bonding in Linux



Step #1: Create a Bond0 Configuration File:
CentOS stores network configuration in /etc/sysconfig/network-scripts/ directory. First, we need to create a bond0 config file as follows:

# vi /etc/sysconfig/network-scripts/ifcfg-bond0
Append the following lines:
DEVICE=bond0
IPADDR=192.168.1.20
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes

You need to replace IP address with your actual setup. Save and close the file.


Friday, March 30, 2012

The Find command cheat sheet


The Find Command Cheat Sheet


1. Basic find command
# find -name "TestFile"

2. Find Files Using Name and Ignoring Case
# find -iname "TestFile"

3. Limit Search To Specific Directory Level Using mindepth and maxdepth
# find / -maxdepth 3 -name passwd
-maxdepth --> will go 3 directories below -- / 1st; /etc 2nd; /usr/bin 3rd

# find / -mindepth 3 -maxdepth 5 -name passwd
will go 3 depths first and upto 5 -- so will not disply under /; /usr; /usr/bin

4. Executing Commands on the Files Found by the Find Command.
user -exec {} /;
# find -iname "TestFile" -exec md5sum {} \;

5. Inverting the match.
To inver the match use the "-not" switch
# find / -not -iname "TestFile"

6. List inodes of the files
# ls -i1 test*
16187429 test-file-name
16187430 test-file-name

# find -inum 16187430 -exec mv {} new-test-file-name \;
# ls -i1 *test*
16187430 new-test-file-name
16187429 test-file-name

7. Find file based on the File-Permissions
You can :
    * Find files that match exact permission
    * Check whether the given permission matches, irrespective of other permission bits
    * Search by giving octal / symbolic representation

# find . -perm -g=r -type f -exec ls -l {} \;
Will display all files with group permission read. Not files with readonly group permission

# find . -perm g=r -type f -exec ls -l {} \;
Will dispay files with 040 permission. i.e files with group read only permisison

# find . -perm 040 -type f -exec ls -l {} \;
Will dispay files with 040 permission. i.e files with group read only permisison

Friday, February 4, 2011

Mount NTFS partition in Linux

Mount NTFS partition in Redhat Enterpris Linux / Ubuntu Linux


Enterprise Linux distributions like Redhat Enterprise Linux ( RHEL ) does not provide native support to Windows NTFS partitions. However you may wand to mount a NTFS formated partiiton in your RHEL box. Here is a simple howto to mount NTFS partitions in your RHEL box.

First of all you need to install a couple of packages. You can use YUM for installing the packages. The rpmforge yum repo contains required rpm packages for mounting NTFS partitions on Linux server. The packages are fuse and fuse-ntfs-3g.

              # yum install fuse fuse-ntfs-3g
Yes, you are done now you can mount ntfs partitions on your rhel server using the mount commandas follows.

             # mount -t ntfs-3g /dev/device-name /mount-point

For example:
           # mount -t ntfs-3g /dev/sdb1 /media

This one also works!!!!!

          # mount.ntfs-3g /dev/sdb1 /media
Newer Ubuntu distributions like Ubuntu 10.04 LTS natively supports NTFS partiitons, so in a Ubuntu server you can mount NTFS partition by just using the above mount commnad.



Thursday, November 11, 2010

How to reset root password in Ubuntu 10.04 LTS


In this how to we shall discuss how to reset root password in Ubuntu 10.04 LTS. I guess this howto will be of highly useful if you forgot your root password in Linux servers particularly in debian based systems like Ubuntu.

Single User Mode in Ubuntu 
To reset the root password you have to boot to single user mode. Follow to steps below to boot to the single user mode in Ubuntu 10.04 LTS.

Please note that Ubuntu 10.04 LTS use the GRUB 2 as bootloader. The first boot option will be used by GRUB 2 by default and it will be used for booting without waiting for user input. So you need to interrupt the boot process for getting boot menu.

Thursday, October 7, 2010

Set date and time in Ubuntu LTS 10.04

How to set Date and Time in Ubuntu 10.04 LTS Lucid Lynx via command line.

You can use the “date’ command for setting Date in any ubuntu bases distributions.

It is better to take a peek into the man pages of the ‘data’ command via:

                  # man date

The man page of date command in Ubuntu might be a bit confusing for all. Let me explain the process to you!!!

Type in the following command, replacing:

                  nn with two digit month (e.g. 01, 05, 12),
                  dd with two digit day (e.g. 02, 24, 31),
                  hh with two digit hour in 24 hour clock format ( 00, 03, 23), 
                  yy/yyyy with the year in two digit or four digit (optional),
and after a period symbol (.) ss with two digit second (00, 05, 59).

The syntax of the date command is:
            # date nnddhhmmyyyy.ss
or
            # date nnddhhmmyy.ss :- in two digit year format
or      
            # date nnddhhmm :- With minimum required parameters (without year and second)
or         
            # date nnddhhmm.ss :- Without year

Month from 01 to 12 (nn)
Day from 01 to 30/31 (dd)

Hour from 00 to 23 (hh)
Minute from 00 to 59 (mm)
Year in four or two digit format (yy yyyy)
Seconds after the period (.) symbol from 00 to 59 (ss)


Example for specifying 21st september, 2010 6:54:20 PM, you should type in the command

             # date 092118542010.20

To specify set NTP server for automatic time synchronyzation:

            # sudo ntpdate NTP-SERVER_URL_OR_IP

I guess I made it faily simple for updating date and time in Ubuntu Server / Desktop LTS 10.04. Also you can try this command in any of the linux based distributions such as RedHat Enterprise Linux, SUSE Enterprise Linux, Fedora etc.
     

Monday, September 20, 2010

Setting up DNS in Ubuntu 10.04 LTS Lucid Lynx

The DNS setup is also a starignt forward job in Ubuntu 10.04 LTS. Like all other major distributions like Redhat Enterprise Linux, Ubuntu distributions also use the /etc/resolv.conf file for DNS resolving.


To cause your machine to consult with a particular server for name lookups you simply add their addresses to /etc/resolv.conf.

Open the /etc/resolv.conf file in your favoirite editor and specify the DNS server in it.

               # sudo vi /etc/resolv.conf
              
              search example.com
              nameserver 192.168.10.1

Here 192.168.10.1 is my DNS server in my example.com domain. Now if your server does not have the file resolv.conf in your /etc directory, dont worry you can simply create it and edit it as above.

       # touch /etc/resolv.conf

Similarly you can assign static lookups in your /etc/hosts file.

             # sudo vi /etc/hosts


             #
 
             192.168.10.100 test test.example.com

If you specify these host explicitely in the /etc/hosts file then the domain name rsolution will takes place fastly.

Setting hostname in Ubuntu 10.04 LTS

In my last post i have described how to configure network in Ubuntu 10.04 LTS in bare metal form. Now we will check how to configure hostname in Ubuntu based distributions. First of all let me asure that the process of seting up hostname is very straight forward in Ubuntu 10.04 LTS.


You can directly query or set the hostname with the "hostname" command.

The current hostname can be viewed using:

             # sudo /bin/hostname

To set hostname you can use the command:

                     # sudo /bin/hostname demo.demoserver.in

NOTE: Need not to say that you should change the hostname from demo.demoserver.in to your requirements.

While rebooting Ubuntu based distributions will read the hostname from /etc/hostname file.

So you can open the file /etc/hostname in your favourite editor and specify the hostname there to make the change persistant.

                # sudo vi /etc/hostname


             # specify your hostname here.
             demo.demoserver.in

Network Interface Configuration in Ubuntu 10.04 LTS Lucid Lynx

Normally all the users will create and configure their network while installing the Operating System Itself. However here I am post the process of configuring the network using command line in Ubuntu 10.04 LTS Lucid Lynx. You can also configure network using GUI utilities in Ubuntu 10.04 LTS such as network-admin or else your famous ifcfg command etc.


Here I am following the bare metal method and will edit the main network configuration files for providing the network information. The main network configuration file of any Ubuntu based distribution is the "/etc/network/interfaces" file. Just open the file in your favourite editor and start configuring it as follows.

Monday, August 2, 2010

Things I do not like about Ubuntu LTS 10.04

The new Ubuntu 10.04 release is a great release and it is really a task to find things you dislike. Anyhow no operating system is perfect and this one also has some flaws. But now itself I am telling you that this is from my point of view and my dislikes may not be your dislikes!!!!
  • The new themes
Well the first thing I dislike about the Ubuntu 10.04 LTS is its new themes. These new themes do nothing but set back the looks of the previous versions. Ok, these themes must be on account of the GNOME 3.0 but the default theme selected is, according to my opinion, is a great mistake. This is also coming on the heels of the rumors of the possible inclusion of RGB support in the GTK widgets, which would have enabled real transparency in all widget sets. This did not happen (and is still not happening). My concern is that most new users will install 10.04 and have trouble getting beyond the default themes.

Thursday, July 29, 2010

Things I love about Ubuntu 10.04 LTS Lucid Lynx

The things I Love and Hate about the new Ubuntu 10.0.4 Lucid Lynx.
  • GNOME 2.30
This is the final 2.x release before the major upgrade to 3. This will be the last time you will see the GNOME 2.X in Ubuntu flavor. For me it is fantastic. GNOME 3 will be a graceful successor to GNOME 2.x. In fact, I can promise that GNOME 3 will succeed where KDE 4 failed — in being a useful desktop upgrade right out of the starting gate.

  • HAL begone
Ubuntu 10.04 has done away with HAL (Hardware Abstraction Layer) during the boot process. This means that 10-second boot time has finally arrived. Hence the 10 second booting can be achieved in a charming way. The removal of HAL also drastically speeds up resume-from-suspend times for those of you in laptop land.

Thursday, May 13, 2010

Landscape 1.5: Ubuntu Server Monitoring & Management Tool

Canonical has released its new server monitoring and management tool Landscape with its Ubuntu 10.04 LTS (Long Term Support) edition. The application is meant to make Ubuntu sever monitoring, management and package provisioning easy.

Ease of use is the main advantage of Ubuntu based distributions. However not much solutions were available to manage and monitor a group of Ubuntu servers simultaneously. Finally Canonical developed its own solution and that is “Landscape”. And with the release of their new distribution Ubuntu server 10.04 LTS Lucid Lynx, they have updated the older version to Landscape 1.5. The new version Landscape 1.5 is available as an on-site server and an online service from Canonical. Landscape is a simple and easy to use web based application that provides powerful automated system management capabilities such as management, monitoring and provisioning of packages across multiple machines, thereby lowering your per-systems cost of management and administration.

Tuesday, May 4, 2010

Ubuntu 10.04 LTS Server Edition Released

Canonical, on April 27 2010, announced the release of the Ubuntu 10.0.4 LTS server Edition release. This release includes extended security and maintenance updates free of charge to all users for five years. Ubuntu 10.04 LTS is the successor of the widely acclaimed Ubuntu 8.04 LTS. Ubuntu 10.04 LTS will be available for free download from Thursday 29 April.
   
Ubuntu 10.04 LTS will also spot a larger network of open-source and proprietary application providers certifying their applications on Ubuntu Server Edition than ever before. About 100 organizations have signaled their intent to certify applications on the platform, including Alfresco, Ingres, IBM, VMware, Zimbra, Yahoo! and many others with more expected to follow post-launch. Dell has announced its intention to support Ubuntu 10.04 LTS Server Edition and will offer Ubuntu Enterprise Cloud as an option on its PowerEdge-C product line - servers specifically designed for building cloud environments.

Wednesday, March 3, 2010

Labeling a Linux partition - Volume Labels

Here we shall discuss about labeling a Linux partition and its advantages. 

You might have seen labeled partitions if you have opened and viewed the /etc/fstab file. There you can see that the 'root', 'home', 'boot, and other system partitions are labeled and are mounted using the label rather than referring the device name. The advantage is that, the root partition will be the same even if the device name got changed in an unlikely event during the system startup. The volume labels make the partition retain a consistent name regardless of where they are connected and what else are connected. And for your information such an unlikely event of changing the device name is quiet often if you are mounting mounting multiple iSCSI drives to your system. 

Hope you know about the iSCSI target and initiator stuffs, it is the low cost, high efficient alternative for costly storage solutions. Hope I could give you an elaborate post about iSCSI soon coz that too is one of my hot favorite topic.  However here we will discuss about labeling the Linux partition labeling.

setuid File Permission in UNIX/Linux

In this post I am going to describe you about the 'setuid' in UNIX and Linux.

setuid or 'set user ID upon execution' and setgid or 'set group ID upon execution' are UNIX access right flags which are used to allow users to run an executable file with the permission of the executable file's owner or group. If the setuid is enabled for an executable file, the user executing the file will get permissions of the user or group that owns the executable file. This is very useful for allowing users on a computer system to run programs with temporarily elevated privileges for performing a particular task. 

These programs are needed for performing some tasks like 'ping' from an unprivileged user. The ping executable in /usr/bin folder is set with setuid bit on and consider its owner is root. So that whenever the ping command is used it is executed with elevated privileges and hence all the unprivileged users can use the ping command unless they are explicitly blocked form using it via some other means. By this hope you got the concept of setuid. Please continue reading for knowing more about setting, listing and more about setuid. 

Tuesday, March 2, 2010

SSH login to remote servers without password.

Hello guys this time I give you a how-to for logging into a remote server/desktop without being prompted for password.

SSH or Secure Shell is a program that allows you to log into a remote machine over a network and execute commands. It also allows you to move files from one computer to another. All the communication including password transmission are highly encrypted. Hence it can be used to create a secure communication over insecure channels. It protects a network from attacks like DNS spoofing, IP spoofing and IP source routing. Thats the reason why the SSH has effectively replaced older remote log in protocols like rlogin, rsh, rcp, telnet etc.

While using SSH log in entire communication including password transmission is is encrypted. SSH uses 3DES, Blowfish, AES and arcfour as encryption algorithms. So it is virtually impossible for a hacker to eavesdrop your password. Here I will describe how to create a secure communication channel between two servers securely and enable password-less login between them. This would be quiet useful while using scripts for logging into remote machines and executing commands. You don't have to store the remote machine's password in the script and also it is quiet annoying to type in password every time you log in to the remote machine via SSH.

Saturday, February 27, 2010

How to install Windows XP in an existing Linux machine.

Intro:
Installing Linux in an existing Windows Machine is not at all a big deal, rather it is quiet straight forward. You just have to leave some hard disk space for Linux and install it on the remaining hard disk space. The Linux boot loader is INTELLIGENT enough to identify that a Windows OS is already installed there and it will automatically adjust the boot loader "GRUB" for dual booting.

However our famous Windows operating systems are not that intelligent but clumsy and it will delete the whole boot loader "GRUB" completely. We will reinstall the GRUB and edit the /etc/grub/grub.conf file to correct it.

I want to go generalized and this how-to is applicable for any version of Linux using GRUB bootloader and windows os. However here I used Ubuntu 9.1 and Windows Server 2003 both 32 bit.