Yearly Archives: 2017

HP TOC

Complete guide: Transfer Of Control (TOC) in HP servers

Everything you need to know about TOC i.e. Transfer Of Control reset in HP servers. It’s a way to initialize system halt and memory dump in an emergency.

What is TOC?

TOC stands for Transfer Of Control! Its a way out for sysadmin when their system stops responding or hung or not taking any inputs and they need to take memory dump before resetting system. This memory dump is helpful for investigating the cause of system abnormality.

Whenever TOC order (hardware signal) has been issued to the system, it stops all current work and starts dumping current memory information in the dump device specified in configurations. Once dumping completes, the system resets.

Why to invoke TOC?

There are many reasons like utilization being high, the disk is getting full, some process going in a loop, many processes forked (Error like sh: The fork function failed. Too many processes already exist.), etc which could bring the system down to its knees. In such a situation there is no way than resetting system since these issues make the system unusable or not responding. So why TOC? Even the normal reset will do the job.

But if you are interested in the root cause of what has happened on the system which brought it down then you will need a memory dump for analysis. This memory dump can be generated when TOC is issued. Since the system doesn’t respond to the user, you can not check what’s happening and then the memory dump is only hoped for investigation after reboot. Hence, TOC reset is always recommended in case of system hung issues.

How to do TOC reset ?

  1. TOC can be invoked by using the TOC switch on the back of your HP server.
  2. Using TC command in the GSP menu.
  3. Using vparreset with option (for vPars)
TOC switch :

Its located in the back of your HP server normally a push button. Sometimes it also accompanied by GSP reset switch too. You need to use it to activate TOC.

TC command in GSP :

Login to GSP or MP. Goto command menu using CM. Then use TC command there to reset with TOC.

MP MAIN MENU:

         CO: Consoles
        VFP: Virtual Front Panel
         CM: Command Menu
         CL: Console Logs
         SL: Show Logs
         FW: Firmware Update
         HE: Help
          X: Exit Connection

[Server-mp] MP> cm
                Enter HE to get a list of available commands

                      (Use ^B to return to main menu.)

[Server-mp] MP:CM> TC
vparreset command :

Using -t option with vparreset command reset vPars with TOC.

# vparreset -p <vpar_name> -t

					

How to get boot path of vpmon in HPUX

Learn to identify the boot path of vpmon vPar Monitor. It’s important to know vpmon path when you are planning activities on virtual partitions in HP hardware

What is vpmon?

vpmon is vPars Monitor. It’s a daemon that monitors vPars in the background. It also provides a shell MON> through which various operations can be performed on vPars. Hence vpmon is a very crucial component when it comes to deal with vPars. Also, unless specified, all operations by vpmon are performed on boot disk from which it was spawned. So boot disk of vpmon is an important aspect while planning any activity on vPars.

The only vparload is the command which has the facility to specify different disk on which operation to be performed. Or else all commands of vpmon runs on boot disk it was booted from.

Boot path of vpmon

To get boot path of vpmon you need to run below command from one of the vPar running HPUX.

testsvr# vparstatus -m

Console path: No path as console is virtual
Monitor boot disk path: 0.0.4.1.0.1.0
Monitor boot filename: /stand/vpmon
Database filename: /stand/vpdb
Memory ranges used: 0x0/349224960 monitor
0x14d0c000/237568 firmware
0x14d46000/581632 monitor
----- output truncated -----

You can see boot path against Monitor boot disk path (highlighted above). This is the hardware address of the disk which you need to decode to get disk name in kernel/OS. IT can be decoded as below from left to right :

  1. This is cabinet number
  2. This is I/O chassis (0 is front, 1 is back)
  3. Its I/O bay
  4. Its slot number
  5. Rest is ctd

Normally, the first disk of first vPar people set as vpmon boot path.

RHEL6 boot process

Understand step by step how RHEL6 system boots. Walkthrough of  RHEL6 boot process which lists all the tasks, activities happen during boot.

Anyone starting to learn Linux must know the boot process of Linux. Here is this post I will be explaining the boot process of Red Hat Enterprise Linux 6 i.e. RHEL6. In brief RHEL6 boot process can be summarized as below :

  1.  Powered on system loads boot loader once it completes POST. The boot loader in turn loads GRUB.
  2. GRUB loads kernel into memory which further loads necessary modules and mount root partition as read-only.
  3. Kernel invokes /sbin/init program and hands it over the boot process.
  4. Init program loads all services as per run level and mounts mount points
  5. The user is presented with a login screen.

Lets see each point in detail to understand RHEL6 boot process properly.

1. Power on and boot loaders:

Whenever the system turned on, it runs POST (Power on self-test) to check all hardware and its operating state. Once POST is cleared, the system runs BIOS. BIOS is a basic input-output system which is the lowest level interface for hardware. BIOS gets loaded in memory and checks system, connected peripherals, boot device path. Lastly, BIOS will load the first sector of the bootable disk in memory which is the MBR master boot record. Once MBR loaded, BIOS hand over boot control to it.

MBR is a small machine code that has a first stage boot loader. The first stage or stage-1 boot loader exists to locate the second stage boot loader and load it in memory only. The second stage or stage-2 boot loader is GRUB. Now boot control is with GRUB.

In UEFI based systems, BIOS is replaced by UEFI. It’s much powerful than BIOS. It has its own architecture, CPU, device drivers. It can mount and read file systems. Such systems have EFI partitions that have EFI’s own boot loaders which can load operating systems or stage-2 boot loaders.

2. GRUB:

GRUB displays a list of available kernels to the user in the graphical interface (like below). Its configuration file is /boot/grub/grub.conf (for BIOS) or /boot/efi/EFI/redhat/grub.conf (for UEFI). Here user can select its kernel to boot using arrow keys and press enter. If not then it will boot default selected kernel when selection time passes out. We can even reset the forgotten root password on this screen.

Once GRUB destined to load the kernel, it searches the kernel binary of it under /boot partition. The boot loader then places one or more appropriate initramfs (Initial RAM file system) images into memory (as seen in the above screenshot). The initramfs is used by the kernel to load drivers and modules necessary to boot the system. Once kernel and initramfs are loaded into memory, boot control is taken by the kernel.

3. Kernel:

Once kernel gets boot control, it quickly run though below tasks:

  • Initialize and configure memory, hardware, and attached peripherals.
  • Decompress initramfs into /sysroot and loads necessary drivers from it
  • Loads virtual devices related to file systems like LVM etc.
  • Free up memory by removing initramfs image
  • Create a root device, mount root partition (read-only)

Now, the kernel is fully loaded and operational. But no services loaded in the system yet so the system is not usable for humans. To load rest of the services kernel calls /sbin/init program and hand it over boot process to him.

4. Init program :

/sbin/init i.e. init process spawns very first in a system with PID 1 and it will be parent process for many system processes or zombie/defunct processes all the time. Init executes and calls various scripts as below :

  • Runs /etc/rc.d/rc.sysinit to start swap, set environment, FS checks, and some system initialization steps.
  • Process jobs in /etc/event.d directory which has run level specific settings
  • Set function library /etc/rc.d/init.d/functions
  • Runs background processes from their respective rc directories. Default specified in /etc/inittabe.g. for run level 3, it will execute /etc/rc.d/rc3.d/ . Mostly rc directories are having symbolic links of start/stop services.
  • Once all processes started in the specified run level, init finishes, and spawns login screen.

5. Login screen:

Once init completes loading RC directories, it forks Upstart which in turns call /sbin/mingettymingetty will be forked for each virtual console. Run level 1 i.e. single user mode has 1 while run level 2 to 5 has 6 virtual consoles. /sbin/mingetty starts communication with tty devices, sets terminal modes, prints login screen (with messages if any), and prompt username to the user!

This completes RHEL6 boot process from power up to login prompt!

How to open the file in the read-only mode under vi or vim

Learn how to open the file in the read-only mode under vi or vim editor. Opening it as read-only prevents any accidental edits in the file and maintain file integrity. 

“vi editor” is sysadmin’s and programmer’s daily text editor in Linux Unix systems. Opening a file to view its content can be achieved by many commands like cat, more, less etc. But many prefer to open a file in vi editors to view. Especially when the file is long and one needs to search particular terms in it. Vi editor makes it easy to search content, line numbering while viewing files.

One of the disadvantages is you are prone to accidentally alter file content and end up saving it in the file. This is a threat to file integrity and hence needs to be avoided. The option is to view files in vi editors carefully or open them in read-only mode!

Lets see different ways to view file in read only mode under vi :

1. Use of view command

One of the widely used ways to view files in vi editors. Simple open file with view command. It will open in vi editors and any attempt to save/alter data will result in failure, securing your file from accidental edits.

# view test.txt

This is test file
Test text
File ends here.
~
~
~
~
~
"test.txt" [readonly] 3L, 44C

You can see above it shows readonly at the bottom and open file in vi editors. If you get into INSERT mode to edit any content of the file you will see below warning.

W10: Warning: Changing a readonly file

If you try to save edited content then you will see below warning

E45: 'readonly' option is set (add ! to override)

So this is 2 level warnings before you could actually save the file using override option w!. There is no way you could *accidentally* ignores two warnings and make accidental edits in the file!

2. vi or vim command with -R option

Another way is to open the file in vi editors with -R option. It functions the same way as above and also shows the same double-layered warning messages when you enter INSERT mode and try to save the file. This option still lets you save the edits made in the buffer by using override w!.

You can open file using vi -R filename

3. vi modifications not allowed mode

Modification not allowed mode can be called using -M option. From the man page, The ’modifiable’ and ’write’ options will be unset, so that changes are not allowed and files can not be written.

Unlike the above two options, this mode won’t let you edit files at all. It will show below error at the bottom when you enter INSERT mode.

E21: Cannot make changes, 'modifiable' is off

So you won’t be able to type in anything even you try INSERT mode. If you try to save the file with :w then it will show you below error :

E142: File not written: Writing is disabled by 'write' option

This makes it the most secure way to open files in the read-only mode under vi to avoid accidental content alteration!

Let us know which way you use most in your daily operations in comments. Happy viewing! 🙂

Everything you need to know about the zombie process

Understand what is zombie process in Linux Unix, how the process goes to a zombie state, how to handle the zombie process, what is the impact of zombie processes.

In very lame terms, the Zombie process is a process that is present in the process table even if it’s already dead! The zombie process is also known as a defunct process. To understand how the zombie process gets created let see how to process exiting takes place from memory.

How the zombie gets created

Whenever the process completes its execution, it exits and notifies its parent process that his child has died. At this time, the parent process supposes to execute the WAIT system call which reads dead child process status and other details. Once the wait system call completes, a dead child will be removed from memory. At this point, if the parent process is not coded properly or unable to read this status from a child for some reason then it won’t fork wait system call. This in turn keeps the dead child process in memory & process table.

This whole operation completes very fast. Zombie takes a very tiny amount of memory to live in so a couple of zombies on the server are harmless. Many zombie processes have parent PID as 1 which is the init process. When a child is dead but not cleared from memory and parent process exists then those child zombies will be taken over by init. Init usually runs its child zombie clearance periodically. So its possible those zombies get cleared out in it.


How to check the zombie process

You can list zombie processes on your server with below command :

# ps aux |grep Z
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     16479  0.0  0.0 103304   812 pts/0    S+   10:44   0:00 grep Z
oracle9  14523  0.0  0.0  52367   702 pts/1    Z    09:15   1:00 asldjkeh

In the above output watch out for STAT column. Z indicates the zombie process. Even top command shows a total number of zombie processes on the system. Check highlighted field in yellow :

You can get parent PID of the zombie process using ps or pstree command.


How to kill the zombie process

You simply can’t! Because of its Zombie! It’s already dead! The maximum you can do is to inform its parent process that its child is dead and now you can initiate a wait system call. This can be achieved by sending SIGCHLD a signal to parent PID using below command :

# kill -s SIGCHLD <ppid>

Here, ppid is the parent process id.


Impact of the zombie process on the system

As we already discussed, a couple of zombie processes are harmless. But if they are growing rapidly then there are two areas which may be bottlenecked and your system prone to panic :

  1. Each zombie holds its PID hence rapidly growing zombies can exhaust all available PIDs on the system and then no new process can be forked by the kernel.
  2. Even zombie holds a very tiny amount of memory, huge numbers can make a difference. A large number of zombies can hog a considerable amount of memory contributing to high memory utilization of the machine.

If your system is flooded with zombies that are not being cleared even by init, system reboot can be tried for a quick refresh. Obviously this would be the last resort you should be looking at.

Dynamic Root Disk DRD configuration in HPUX

Learn how to configure Dynamic Root Disk (DRD) in HPUX. Understand how to clone root disk, view files in it, activate, and deactivate DRD disk.

Dynamic Root Disk aka DRD is a root disk cloning tool from HP. This tool aims to provide system integrity solutions at maintenance activities performed on the root disk. On DRD cloned disk you can perform any maintenance activity which you planned to do on actual live disk without worrying about disturbing the running system. You can activate cloned disk and reboot server which then boots from altered cloned disk. If you observe your changes are not perfect, you can re-activate your old live root disk hence getting back to the original state within minutes!

Proposed normal DRD clone disk life cycle is :

  1. Clone live root disk
  2. Mount cloned disk
  3. Make any changes you want on the cloned disk
  4. Activate cloned disk and reboot server
  5. Now system boots from cloned disk (Your old live disk is intact!)
  6. If you want to go back to the old state, set the old live disk as the primary boot disk
  7. Reboot system and your old live disk will be booted as it is.

Let’s see different operations which can be done through dynamic root disk commands.

1. How to clone root disk using DRD

DRD has its own set of commands to perform operations on clone disk. To clone your live root disk, attach/identify unused disk with the same or more capacity than live root disk with the same technology/model. Once identified, use below command :

# /opt/drd/bin/drd clone -v -x overwrite=true -t /dev/dsk/c0t2d0

=======  04/22/16 16:42:47 IST  BEGIN Clone System Image (user=root)  (jobid=testsrv)

       * Reading Current System Information
       * Selecting System Image To Clone
       * Selecting Target Disk
       * Converting legacy DSF "/dev/dsk/c0t2d0" to "/dev/disk/disk6"
       * Selecting Volume Manager For New System Image
       * Analyzing For System Image Cloning
       * Creating New File Systems
       * Copying File Systems To New System Image
       * Making New System Image Bootable
       * Unmounting New System Image Clone
       * System image: "sysimage_001" on disk "/dev/disk/disk6"

=======  04/22/16 17:14:18 IST  END Clone System Image succeeded. (user=root)  (jobid=testsrv)

DRD binary resides in /opt/drd/bin. Use clone argument todrd command and supply target disk path with -t option (which will be final cloned disk). There are a few options which can be used with -x. We used here to overwrite disk if any data resides in it. This command execution takes 30 mins to hours time depending on your root VG size.

In the end, you can see system image has been cloned on disk /dev/dsk/c0t2d0 i.e. /dev/disk/disk6. You can check the status of DRD using the below command which lists all details about the cloned disk.

# /opt/drd/bin/drd status

=======  04/22/16 17:24:21 IST  BEGIN Displaying DRD Clone Image Information (user=root)  (jobid=testsrv)

       * Clone Disk:               /dev/disk/disk6
       * Clone EFI Partition:      AUTO file present, Boot loader present, SYSINFO.TXT not present
       * Clone Creation Date:      04/22/16 16:43:00 IST
       * Clone Mirror Disk:        None
       * Mirror EFI Partition:     None
       * Original Disk:            /dev/disk/disk3
       * Original EFI Partition:   AUTO file present, Boot loader present, SYSINFO.TXT not present
       * Booted Disk:              Original Disk (/dev/disk/disk3)
       * Activated Disk:           Original Disk (/dev/disk/disk3)

=======  04/22/16 17:24:32 IST  END Displaying DRD Clone Image Information succeeded. (user=root)  (jobid=testsrv)

2. How to mount the cloned disk

Once the disk is cloned, you can view data within it by mounting it. Use mountargument with drd command.

# /opt/drd/bin/drd mount

=======  04/22/16 17:30:20 EDT  BEGIN Mount Inactive System Image (user=root)  (jobid=testsrv)

 * Checking for Valid Inactive System Image
 * Locating Inactive System Image
 * Mounting Inactive System Image

=======  04/22/16 17:30:31 EDT  END Mount Inactive System Image succeeded. (user=root)  (jobid=testsrv)

This will create a new VG on your system named drd00 and mounts clone disk within it. All you root disk mount points in the cloned disk will be mounted on /var/opt/drd/mnts/sysimage_000 e.g. /tmp in the cloned disk will be available on /var/opt/drd/mnts/sysimage_000/tmp mount point. See below output for your understanding:

# bdf
Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol3    4194304  176968 3985984    4% /
/dev/vg00/lvol1    2097152  158344 1923696    8% /stand
/dev/vg00/lvol8    12582912  846184 11645064    7% /var
/dev/vg00/lvol7    10485760 3128368 7299968   30% /usr
/dev/vg00/lvol6    10485760  456552 9950912    4% /tmp
/dev/vg00/lvol5    10485760 4320288 6117352   41% /opt
/dev/vg00/lvol4    4194304   21304 4140408    1% /home
/dev/drd00/lvol3   4194304  176816 3986136    4% /var/opt/drd/mnts/sysimage_000
/dev/drd00/lvol4   4194304   21304 4140408    1% /var/opt/drd/mnts/sysimage_000/home
/dev/drd00/lvol5   10485760 4329696 6108024   41% /var/opt/drd/mnts/sysimage_000/opt
/dev/drd00/lvol1   2097152  158408 1923696    8% /var/opt/drd/mnts/sysimage_000/stand
/dev/drd00/lvol6   10485760  456536 9950928    4% /var/opt/drd/mnts/sysimage_000/tmp
/dev/drd00/lvol7   10485760 3196640 7232232   31% /var/opt/drd/mnts/sysimage_000/usr
/dev/drd00/lvol8   12582912  876016 11615544    7% /var/opt/drd/mnts/sysimage_000/var

You can even un-mount DRD cloned disk using drd unmount command.

# /opt/drd/bin/drd umount -v 

=======  04/22/16 17:30:45 IST  BEGIN Unmount Inactive System Image (user=root)  (jobid=testsrv)

       * Checking for Valid Inactive System Image
       * Locating Inactive System Image
       * Preparing To Unmount Inactive System Image
       * Unmounting Inactive System Image
       * System image: "sysimage_001" on disk "/dev/disk/disk6"

=======  04/22/16 17:30:58 IST  END Unmount Inactive System Image succeeded. (user=root)  (jobid=testsrv)

3. Different tasks which can be performed on cloned DRD disk

There are different maintenance activities that you can perform on this cloned DRD disk. To name a few: patch installation, editing some system files manually, tuning static kernel parameters, etc.

To execute tasks on the cloned disk you need to supply commands as an argument to drd runcmd option. For example, if you want to view /etc/hosts file in the cloned image,  use drd runcmd cat /etc/hosts

# /opt/drd/bin/drd runcmd kctune -B nproc+=100

=======  04/22/16 18:15:54 IST  BEGIN Executing Command On Inactive System Image (user=root)  (jobid=testsrv)

       * Checking for Valid Inactive System Image
       * Analyzing Command To Be Run On Inactive System Image
       * Locating Inactive System Image
       * Accessing Inactive System Image for Command Execution
       * Setting Up Environment For Command Execution
       * Executing Command On Inactive System Image
       * Executing command: "/usr/sbin/kctune -B nproc+=100"
WARNING: The backup behavior 'yes' is not supported in alternate root
         environments.  The behavior 'once' will be used instead.
       * The automatic 'backup' configuration has been updated.
       * Future operations will ask whether to update the backup.
       * The requested changes have been applied to the currently
         running configuration.
Tunable            Value  Expression  
nproc    (before)   4200  Default     
         (now)      4300  4300        
       * Command "/usr/sbin/kctune -B nproc+=100" completed with the return code "0".
       * Cleaning Up After Command Execution On Inactive System Image

=======  04/22/16 18:16:23 IST  END Executing Command On Inactive System Image succeeded. (user=root)  (jobid=testsrv)

See above example where I tune kernel parameters within the cloned disk.

You can even install patches using command drd runcmd swinstall -s /tmp/patch123.depot. Even if patch which needs a reboot can be installed. Since you are installing it on cloned (nonlive) root disk, the server won’t be rebooted. To make these changes live on your server, you need to boot the server with this cloned disk.

4. How to activate DRD cloned disk

To activate the dynamic root disk, you need to run drd activate command. Actually, this command sets your cloned disk path as a primary boot path which you can do by setboot command too!

# /opt/drd/bin/drd activate -x reboot=true

=======  04/22/16 18:20:21 IST  BEGIN Activate Inactive System Image (user=root)  (jobid=vm19)

       * Checking for Valid Inactive System Image
       * Reading Current System Information
       * Locating Inactive System Image
       * Determining Bootpath Status
       * Primary bootpath : 0/0/0/0.0x0.0x0 before activate.
       * Primary bootpath : 0/0/0/0.0x2.0x0 after activate.
       * Alternate bootpath : 0/0/0/0.0x1.0x0 before activate.
       * Alternate bootpath : 0/0/0/0.0x1.0x0 after activate.
       * HA Alternate bootpath :  before activate.
       * HA Alternate bootpath :  after activate.
       * Activating Inactive System Image
       * Rebooting System

If you set reboot to false, it will just set the primary boot disk path and exists. After that when you manually reboot the system, it will boot from cloned disk.

If you don’t choose auto-reboot then you will have a chance to reverse activate operation using deactivate command argument.

5. After booting cloned disk

If you boot your system from dynamic root disk, below things will be changed :

  1. Root VG mirroring will be missing
  2. Past live root disk will be intact
  3. Past live root disk will be removed from setboot primary/alternate boot path settings
  4. You have to restore the root mirror
  5. You have to check and set the alternate boot path
  6. Your system will be having all changes (patch install, kernel tuning) you made on the cloned disk

Dynamic Root Disk is a very powerful tool when it comes to chopping down your downtime. If you have little downtime window and need to perform a large number of patching which requires the reboot. Patch cloned disk and just reboot server during your short downtime!

Learn Linux Unix: File permissions & ownership

Basic Linux and Unix fundamentals of file permissions and ownership. Learn what are they and how to set/edit them in different ways.

One of the basic fundamentals while learning Linux or Unix is file permissions and their ownership. One should be clear about what is file ownership is and what its permissions mean. in *nix world, everything is treated as file devices and directories too. Each file has its own owners and permissions. Permission data decides who can do which operations on that file.

Ownership :

Each file has two ownership details attached with it: Owner and group.

The owner is the user (listed in /etc/passwd) who owns that file. He must have created that file or previous owner of file/superuser made him the owner of that file. Owning a file means all owner level permissions are applicable to that user for that particular file.

A group is a group (listed in /etc/group) who has rights on that file. Group-level permissions are applicable to that group. This detail introduced so that a large number of people’s access can be managed for that file with only one set of permissions.

Files owner details can be seen in ls -lrt output  under 3rd and 4th column as below :

# ls -lrt
total 0
-rw-r--r-- 1 root    sysadmin 0 Feb  9 10:40 file1
-rw-r--r-- 1 oracle9 dba      0 Feb  9 10:40 file2
-rw-r--r-- 1 user3   apps     0 Feb  9 10:40 file3

In above example,

root, oracle9, and user3 are owners.
sysadmin, dba, and apps are groups.

Sometimes you see numbers instead of the owner or group. Those are orphaned files whose owner or group does not exist on the system.

How to change file ownership :

To change file ownership you have to use change owner (chown) command. The command should be supplied with a new owner and group along with a file name whose ownership needs to be changed.

# ls -lrt
-rw-r--r-- 1 user2 dba 0 Feb  9 10:40 file1
# chown root:sysadmin file1
# ls -lrt
-rw-r--r-- 1 root sysadmin 0 Feb  9 10:40 file1

Observe the example above how it changed owners. To run successful chown command, you must be the current owner of that file or you must be a superuser.

Permissions :

Permissions control how and who access the file and perform operations on it. There are 3 permissions parameters defined in *nix world: read, write, and execute. It has number representation as well.

  • Read permission denoted by 4 or r
  • Write permission denoted by 2 or w
  • Execute permission denoted by 1 or x

If you see, the above example again, the output’s first column is permission details. That is 10 character field which can be decoded as :

  1. File bit
  2. Read bit for owner
  3. Write bit for owner
  4. Execute bit for owner
  5. Read bit for the group
  6. Write a group for group
  7. Execute bit for the group
  8. Read bit for others
  9. Write bit for others
  10. Execute bit for others

File bit denotes the type of file. There are various values you can see here. Few are as below :

  • d : directory
  • - : file
  • l : Symbolic link
  • b : block device file

The rest are 3 sets of 3 bit each for the owner, group, and others. Others mean any user id which is not the owner or part of the specified group. For example -rw-r--r-- means its a file, which can be read & write by the owner and can only be read by group members, others. -rwxrwxrwx means read, write, and execute permissions to all!

Whenever a file is created, its default permissions are decided by umask value defined in the system.

How to change file permissions :

To change file permission, you need to use chmod command. You have the liberty to specify only one set of permissions (for user or group or others) or all three sets, use of character, or number representation of permissions and owners.

Below are few examples :

# chmod 744 file1      <<Set rwx to owner & read for group, owners
# chmod o+x file1      <<Adds execute permission for others
# chmod u+x,g+x file1  <<Adds execute permission for owner and group
# chmod u-x file1      <<Removes execute permission for owner

How to change directory permissions recursively 

Recursively means changing permission of all the files and directories upto depth 1 in directory. To change directory permission recursively you need to use switch -R along with chmod command followed by directory.

For example :

root@kerneltalks # chmod -R 755 /tmp/testdata
root@kerneltalks # ls -lrt /tmp/testdata
total 0
-rwxr-xr-x 1 root    sysadmin 0 Feb  9 10:40 file1
-rwxr-xr-x 1 oracle9 dba      0 Feb  9 10:40 file2
-rwxr-xr-x 1 user3   apps     0 Feb  9 10:40 file3

As you can see in the above output after changing permission recursively, all files within /tmp/testdata directory changed permissions to 755.

6 ways to check Linux kernel version

Learn how to check the Linux kernel version using the command line. Helpful commands to check your kernel versions, releases, codenames, etc.

This post aims at checking your Linux kernel version using commands. We will be discussing different ways to fetch this data from your system. Below is a list of commands which can be used to get Linux kernel version details.

You can use below 7 ways to gather info about your distribution like kernel version in CentOS, RHEL, SUSE, OEL, Ubuntu, Debian Linux. All the below outputs are from my test machine running CentOS 7.

1. By reading version process file.

This gives you running kernel version.

[root@kerneltalks1 ~]# cat /proc/version
Linux version 3.10.0-693.5.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Fri Oct 20 20:32:50 UTC 2017

3.10.0-693.5.2.el7.x86_64 is your current kernel distribution version.

2. By reading Distro release file in /etc

Almost all distributions of Linux come with a release file in /etc which contains the kernel version, release details in it. Its a text file hence cat can be used to read its content.

# cat /etc/enterprise-release OR /etc/oracle-release   ---For OEL
Enterprise Linux Enterprise Linux Server release 5.8 (Carthage)

[root@kerneltalks1 ~]# cat /etc/redhat-release         ---For RHEL/OEL
CentOS Linux release 7.4.1708 (Core)

OR simple use wildcard so that you can list the release file of any distro. All distro keeps diff filenames so using wildcard will be wise. In some distro, you will see /etc/os-release or /etc/system-release files as well. All these files will be covered when using wild cards.

[root@kerneltalks1 ~]# cat /etc/*release
CentOS Linux release 7.4.1708 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.4.1708 (Core)
CentOS Linux release 7.4.1708 (Core)

3. By listing release package

This command works for RPM-based systems like RHEL, SUSE, OEL, CentOS, etc. Search and grep for release which will show you release package. This package name convention includes release number in it.

[root@kerneltalks1 ~]# rpm -qa |grep -i release
centos-release-7-4.1708.el7.centos.x86_64

4. Using uname command

This command works on all flavors of Linux. You can use it on RHEL, SUSE, OEL, Debian, Ubuntu, etc.

[root@kerneltalks1 ~]# uname -r
3.10.0-693.5.2.el7.x86_64

This value indicates your current kernel version.

5. Using lsb_release command

lsb_release command is provided by redhat-lsb package. You need to install redhat-lsb package in order to use this command on RHEL, CentOS or Fedora systems.

[root@kerneltalks1 ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.4.1708 (Core)
Release:        7.4.1708
Codename:       Core

6. Using hostnamectl command

In newer kernels, hostnamectl command is introduced. Using this command without any argument will show you all details about your kernel. You can use it to set your hostname as well.

[root@kerneltalks1 ~]# hostnamectl
   Static hostname: kerneltalks1
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 49688f1b932a41e790254b993d419ccc
           Boot ID: 4777133835544d599a46a53ae4b584e3
    Virtualization: xen
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.5.2.el7.x86_64
      Architecture: x86-64

How to install EC2 Linux server in AWS with screenshots

Learn how to install the EC2 Linux server of your favorite distro on the Amazon Web Services cloud platform. Free Linux server for learning and practicing. 

Amazon Web Services AWS is one of the cloud platforms which offers various computing facilities online. For a free tier account, there are enough services offered for a normal user who aims for testing or learning new technologies without spending much. You can sign up for a free account (12 months free) here which will require your valid mobile number and credit card information for validation.

In this post, we will be using AWS to install the Linux server which we can use for practice/ hand-on experience at home. One of the other alternatives is to install Vmware on your desktop/laptop and then install Linux in its virtual machine. But this way requires a good hardware configuration of your laptop/desktop. Hosting your Linux on cloud is much easy and it’s not costing you anything for low usage!

AWS offers below a list of distros to install on its EC2 (server computing module) platform.

  • Redhat
  • Cent OS
  • Debian
  • Fedora
  • Gentoo
  • OpenSuse
  • Suse Linux
  • Ubuntu
  • Amazon Linux

You can have a hand on to all these distros within minutes after signing up for your account!  Of course, you will be having root administrator access on these systems! Let’s walk through steps to get your Linux server ready in minutes on AWS.

Step 1.

Login to AWS account and from landing page select “Launch a virtual machine” under ‘Build a solution’ screen.

Step 2.

You will be presented with the ‘Quick Launch EC2 Instance’ screen. Here you will be able to launch a wizard to get your task done fast or you can go through Advanced selections to decide your final virtual server config. We will be going with a normal wizard. Click the “Get Started” button here.

Step 3.

Now we will walk through wizard for creating our Linux virtual server.

Name your EC2 instance :

Your EC2 linux virtual server name of your choice.

Select your operating system. We are selecting RedHat here.

Select an instance type.

This is the type of hardware config you will be needing. For free account, you will be able to select those instances only which is tagged with “Free tier eligible”. Here we are selecting default t2.micro instance which has Single core CPU, 1 GB RAM, and 8GB of HDD.

Create a key pair.

This is an important screen. Here you will be given one Private key to download. You will require this key to authenticate yourself while logging into this EC2 Linux server when ready. Give the name of your choice and download the key file and keep it safe.

Create this instance.

Finally hit create button and your server will be ready in 2 minutes. You will see installing screen.

Once complete, click EC2 console link and you will be presented with list of servers under your account.

Step 4.

You can see below the EC2 screen with your server details like instance state, zone, DNS, etc.

Now to connect to this server from your laptop/desktop, you need to use key pair as authentication. Download putty.exe and puttygen.exe from here.

Open puttygen.exe and load your private key which you have downloaded from AWS console in step 2.

Once, successfully loaded you need to click the “Save public key” button and save the key on your desktop/laptop.

Now open putty.exe. Set your saved key file from puttygen (in the above task) as an SSH authentication. In left-hand side pane, expand SSH then select Auth and on the right-hand side, you will be able to browse your file.

Now your putty.exe is ready to connect with your AWS Linux server. Now head back to EC2 console and copy your server’s public DNS.

Use this it, in putty to connect. And you will be able to connect to the server. Once prompted for username use username from the below table as per your distro (official AMI). You won’t be prompted for a password. Your authentication will be done via key pair you configured in putty settings.

Default ssh usernames for famous Linux in EC2

Linux Distro
Username
Ubuntuubuntu
Debianadmin
Fedorafedora
CentOScentos
RHEL 6.4 & Laterec2-user
RHEL 6.3 & previousroot
SUSEroot
login as: ec2-user
Authenticating with public key "imported-openssh-key"
[ec2-user@ip-172-31-23-115 ~] $ sudo su -
[root@ip-172-31-23-115 ~] # id 
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023  

Once logged in, use sudo su - command and you will be in root account! That’s it, you have an EC2 Linux server with root account in few minutes!

You can install any distro listed above in these instances. Make sure you are not expiring your free usage according to AWS free tier policy otherwise you will be billed on your card. Practice, learn, improve! Have a happy shell!!