Thursday, February 19, 2015

df and du showing different Size

df and du shows different Size and recovering the space without killing the process

1. From lsof we can find the big 10 files which is deleted. And the first file is around  ((2407845888 / 1024 ) /1024) = 2296 MB
       
[root@server1  fd]# lsof | grep deleted | sort -nr -k 7 | head
frmweb    21199    mislve   23u      REG      253,0 2407845888     819375 /tmp/filesvuEFz.TMP (deleted)
frmweb    28933    mislve   27u      REG      253,0    4032864     819378 /tmp/fileiTj11l.TMP (deleted)
frmweb    16365    mislve   24u      REG      253,0    2248832     819483 /tmp/file5z0oen.TMP (deleted)
frmweb    28697    mislve   27u      REG      253,0     959488     819238 /tmp/fileemrhVz.TMP (deleted)
frmweb    24794    mislve   27u      REG      253,0     906304     819492 /tmp/file4d68i0.TMP (deleted)
frmweb    25383    mislve   24u      REG      253,0     393216     819572 /tmp/file7powEH.TMP (deleted)
frmweb    25329    mislve   28u      REG      253,0     386784     819355 /tmp/filembs5IG.TMP (deleted)
frmweb    24400    mislve   28u      REG      253,0     307328     819228 /tmp/fileL8p1m7.TMP (deleted)
frmweb     2717    mislve   27u      REG      253,0     277472     819290 /tmp/fileVzblkn.TMP (deleted)
frmweb     2002    mislve   24u      REG      253,0     262784     819516 /tmp/fileUeZpzA.TMP (deleted)


2. One option is to kill the process or nullfy the File Descripter (FD).We can find the FD as shown below.

       
[root@server1 fd]# ls -l /proc/21199/fd/ | grep deleted
lrwx------ 1 mislve dba 64 Feb 19 13:00 23 -> /tmp/filesvuEFz.TMP (deleted)
       

3.Nullify the file descripter

[root@server1 fd]#  echo /dev/null >  /proc/21199/fd/23
 

4. Size of the Fileystem before and after
     

Before
[root@server1 ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       11G  5.8G  4.3G  58% /

After
[root@server1 ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       11G  3.6G  6.5G  36% /

Sunday, January 11, 2015

Enabling Virtualization option in Lenovo G50

Enabling Virtualization option in BIOS 
1. I bought Lenovo G50 AMD A8 / 8GB RAM / 1TB HDD and my plan is to install some Hypervisor virtually using VMWare workstation and run some VM in that, but I was not able to see the option in BIOS to enable Virtualization
3.You can enable  Virtualization option by updating BIOS using this link.
4.After installing this BIOS update you can see option to enable Virtualization option.
Installing VMWare vSphere client in Windows 8.1
Next issue I was facing is installing vSphere Client in Windows 8.1. It keeps crashing.
The installation of file,VMware-viclient.exe, keeps crashing during installation on Windows 8.1.  This was caused by not having the .NET Framework x3.5 installed.
The cause of issue is that the .NET framework v3.5 is not installed in Windows 8 by default, and is a required component for the vSphere client.  I assume that the redistributable is packaged with the vSphere client installer, but it doesn’t work in Windows 8.1.
“The .NET Framework v3.5 is easy to install, just issue the following command from an elevated/administrator command prompt:
Dism /online /enable-feature /featurename:NetFx3 /All /Source:F:\sources\sxs /LimitAccess
(replace F:\ with the DVD drive where your Windows 8.1 is located.  If your DVD drive is as slow as mine, just copy the ISO to your hard drive, mount it with daemon-tools, and use that location instead.)
After that, the vSphere client happily installed and I’m off to play with Windows 8.1 now.”
Issue in Installing VM in ESXi server
After Installing vSphere client I was able to connect to ESXi Server which was installed in VMWare workstation 10, but I was not able to install VM in that.
When I created VM and started it gives the error "VMware ESX unrecoverable error: (vcpu-0) vcpu-0:NOT_IMPLEMENTED vmcore/vmm/cpu/fpu.c:452"
To solve this issue you need to add the following line in /etc/vmware/config in ESXi Server

featMask.mockup.cpuid.NUMLEVELS = Val:0xb
featMask.mockup.cpuid.AVX = Val:0
featMask.mockup.cpuid.XSAVE = Val:0

Note: This option disable AVX (Advanced Vector Extensions)

Reference :
https://communities.vmware.com/thread/476180?start=0&tstart=0
http://www.brianwilliams.pro/installing-vsphere-client-on-windows-8-1/

Friday, May 23, 2014

Vyatta Firewall Configuration backup

Vyatta Firewall Automated Backup 


1. Script to backup the vyatta configuration thorugh ssh. Save this file as /home/vyatta/backup_expect.sh.
Modify User name ,Password and IP address details.

#!/usr/bin/expect 
set timeout 1
spawn $env(SHELL)
send "configure\r"
expect -re  ".*# $"
sleep 5
send "save scp://vyatta:password@[ip-address]/home/vyatta/R1-config.boot.`date +%Y%m%d-%H%M`\r"
expect -re  ".*# $"
send "exit\r"
exit
expect eof

2.Enable the crontab entry for vyatta user

SHELL=/bin/vbash
0 20 * * * /home/vyatta/backup_expect.sh > /tmp/backup-out 

Monday, April 28, 2014

SSH Proxy command

SSH Proxy command Diagram
Note: Refer http://blog.tjll.net/ssh-kung-fu/ for more info

Friday, April 25, 2014

iSCSI Administration

iSCSI Target and Initiator configuration


Summary:

                 In this article we will see about how to configure RedHat server as iSCSI Target and iSCSI Initiator. 

iSCSI Target (Server) configuration

  • Installing the required Package for target configuration.
    [root@iscsi-target yum.repos.d]# yum groupinstall "Network Storage Server"
    ....... 
    Dependencies Resolved
    
    =============================================================================================================
     Package                                      Arch            Version            Repository         Size
    =============================================================================================================
    Installing:
     scsi-target-utils                            x86_64          1.0.24-2.el6        RHEL-CD          170 k
    Installing for dependencies:
     libibverbs                                   x86_64          1.1.6-4.el6         RHEL-CD           45 k
     librdmacm                                    x86_64          1.0.15-2.el6        RHEL-CD           29 k
     perl-Config-General                          noarch          2.44-1.el6          RHEL-CD           68 k
     sg3_utils                                    x86_64          1.28-4.el6          RHEL-CD          471 k
     sg3_utils-libs                               x86_64          1.28-4.el6          RHEL-CD           51 k
    
    Transaction Summary
    ===============================================================================================================
    Install       6 Package(s)
    
    Total download size: 833 k
    Installed size: 2.1 M
    Is this ok [y/N]: y
    
    
     
  • We have a logical Volume "/dev/vg_iscsidisk/lv_lun1" which will be used in the iSCSI Target configuration as a lun.
  • [root@iscsi-target yum.repos.d]# cat /etc/tgt/targets.conf
    default-driver iscsi
    <target iqn.2014-04.com.example:iscsi-target:storage>
            backing-store /dev/vg_iscsidisk/lv_lun1 
    </target>

  • Restart the tgtd service and make it persistent after reboot.  
  • [root@iscsi-target yum.repos.d]# /etc/init.d/tgtd restart
    Stopping SCSI target daemon:                               [  OK  ]
    Starting SCSI target daemon:                               [  OK  ]
    [root@iscsi-target yum.repos.d]# chkconfig tgtd on 

  • Listing the Lun details.
  • [root@iscsi-target yum.repos.d]# tgt-admin -s
    Target 1: iqn.2014-04.com.example:iscsi-target:storage
        System information:
            Driver: iscsi
            State: ready
        I_T nexus information:
        LUN information:
            LUN: 0
                Type: controller
                SCSI ID: IET     00010000
                SCSI SN: beaf10
                Size: 0 MB, Block size: 1
                Online: Yes
                Removable media: No
                Prevent removal: No
                Readonly: No
                Backing store type: null
                Backing store path: None
                Backing store flags: 
            LUN: 1
                Type: disk
                SCSI ID: IET     00010001
                SCSI SN: beaf11
                Size: 4295 MB, Block size: 512
                Online: Yes
                Removable media: No
                Prevent removal: No
                Readonly: No
                Backing store type: rdwr
                Backing store path: /dev/vg_iscsidisk/lv_lun1
                Backing store flags: 
        Account information:
        ACL information:
            ALL
    

iSCSI Initiator (Client) Configuration 

  •  Installing the required package for initiator
  • [root@iscsi-initiator ~]# yum groupinstall "iSCSI Storage Client"
    ......
    Resolving Dependencies
    --> Running transaction check
    ---> Package iscsi-initiator-utils.x86_64 0:6.2.0.872-41.el6 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ================================================================================
     Package                   Arch       Version                 Repository   Size
    ================================================================================
    Installing:
     iscsi-initiator-utils     x86_64     6.2.0.872-41.el6        RHEL-CD     654 k
    
    Transaction Summary
    ================================================================================
    Install       1 Package(s)
    
    Total download size: 654 k
    Installed size: 2.2 M
    Is this ok [y/N]: y
    

  • iSCSI Qualified Name (IQN) configuration
  • [root@iscsi-initiator ~]# cat /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.2014-04.com.example:iscsi-initiator       
    

  • iSCSI initiator consist of 2 services iscsi and iscsid. We will start the service and make it persistent.
  • [root@iscsi-initiator ~]# service iscsi restart
    Stopping iscsi:                                            [  OK  ]
    [root@iscsi-initiator ~]# service iscsid restart
    Stopping iscsid: 
    Starting iscsid:                                           [  OK  ]
    [root@iscsi-initiator ~]# chkconfig iscsi on
    [root@iscsi-initiator ~]# chkconfig iscsid on
  • Discovering the the presented LUN using iscsiadm command.
  • [root@iscsi-initiator ~]# iscsiadm  -m discovery -t sendtargets -p 192.168.122.101
    192.168.122.101:3260,1 iqn.2014-04.com.example:iscsi-target:storage

  • Login to the lun. Once you login you can see the disk in "fdisk -l" command
  • [root@iscsi-initiator ~]# iscsiadm --mode node --targetname iqn.2014-04.com.example:iscsi-target:storage --portal 192.168.122.101:3260 --login
    Logging in to [iface: default, target: iqn.2014-04.com.example:iscsi-target:storage, portal: 192.168.122.101,3260] (multiple)
    Login to [iface: default, target: iqn.2014-04.com.example:iscsi-target:storage, portal: 192.168.122.101,3260] successful.
    

  • Seeing the newly discovered LUN details in "fdis-l -l" command
  • [root@iscsi-initiator ~]# fdisk -l
    
    Disk /dev/vda: 8589 MB, 8589934592 bytes
    16 heads, 63 sectors/track, 16644 cylinders
    Units = cylinders of 1008 * 512 = 516096 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0004fd53
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *           3        1017      512000   83  Linux
    /dev/vda2            1018       16645     7875584   8e  Linux LVM
    
    Disk /dev/sda: 4294 MB, 4294967296 bytes
    133 heads, 62 sectors/track, 1017 cylinders
    Units = cylinders of 8246 * 512 = 4221952 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000
    

  • Now we can create a partition and use it as normal disk
  • [root@iscsi-initiator ~]# fdisk /dev/sda 
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0x305c97fa.
    Changes will remain in memory only, until you decide to write them.
    After that, of course, the previous content won't be recoverable.
    
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-1017, default 1): 
    Using default value 1
    Last cylinder, +cylinders or +size{K,M,G} (1-1017, default 1017): 
    Using default value 1017
    
    Command (m for help): p
    
    Disk /dev/sda: 4294 MB, 4294967296 bytes
    133 heads, 62 sectors/track, 1017 cylinders
    Units = cylinders of 8246 * 512 = 4221952 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x305c97fa
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1        1017     4193060   83  Linux
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@iscsi-initiator ~]# partprobe /dev/sda
    [root@iscsi-initiator ~]# pvcreate /dev/sda1 
      Writing physical volume data to disk "/dev/sda1"
      Physical volume "/dev/sda1" successfully created
    [root@iscsi-initiator ~]# vgcreate vg_iscsi /dev/sda1 
      Volume group "vg_iscsi" successfully created
    [root@iscsi-initiator ~]# lvcreate -l 100%FREE -n lv_lun1 vg_iscsi
      Logical volume "lv_lun1" created
    [root@iscsi-initiator ~]# vgs
      VG                #PV #LV #SN Attr   VSize VFree
      vg_iscsi            1   1   0 wz--n- 4.00g    0 
      vg_iscsiinitiator   1   2   0 wz--n- 7.51g    0 
    [root@iscsi-initiator ~]# lvs
      LV      VG                Attr     LSize Pool Origin Data%  Move Log Copy%  Convert
      lv_lun1 vg_iscsi          -wi-a--- 4.00g                                           
      lv_root vg_iscsiinitiator -wi-ao-- 5.54g                                           
      lv_swap vg_iscsiinitiator -wi-ao-- 1.97g  
    [root@iscsi-initiator ~]# mkfs.ext3 /dev/vg_iscsi/lv_lun1 
    
    

  • Adding fstab entry. _netdev option is important.If you donot provide that we will have issue when we reboot the system. Provide UUID instead of device file name
  • [root@iscsi-initiator ~]# blkid /dev/vg_iscsi/lv_lun1 
    /dev/vg_iscsi/lv_lun1: UUID="f9b2d5e1-f10b-4aa2-9367-64cda002bbc7" TYPE="ext3"
    [root@iscsi-initiator ~]# cat /etc/fstab | grep net
    UUID=f9b2d5e1-f10b-4aa2-9367-64cda002bbc7 /iscsi   ext3 _netdev  0 0
    [root@iscsi-initiator ~]# mkdir /iscsi
    [root@iscsi-initiator ~]# mount /iscsi
    [root@iscsi-initiator ~]# df -hT /iscsi
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/mapper/vg_iscsi-lv_lun1
                  ext3    4.0G   73M  3.7G   2% /iscsi
    
  • You can use iscsiadm command to find which disk is iSCSI disk.
  • [root@iscsi-initiator ~]# iscsiadm -m session -P 3 | grep Atta
      Attached SCSI devices:
       Attached scsi disk sda  State: running
Now we completed the iSCSI Initiator configuration.

Removing iSCSI Disk

Now we will see how to Delete or remove the iSCSI disk from the Initiator.
  • Disable or logout from an iSCSI Target.
  • [root@iscsi-initiator ~]# iscsiadm -m node -T iqn.2014-04.com.example:iscsi-target:storage --portal 192.168.122.101:3260 --logout
    Logging out of session [sid: 4, target: iqn.2014-04.com.example:iscsi-target:storage, portal: 192.168.122.101,3260]
    Logout of [sid: 4, target: iqn.2014-04.com.example:iscsi-target:storage, portal: 192.168.122.101,3260] successful.Delete the target record
  • Delete the iSCSI target record
  • [root@iscsi-initiator ~]# iscsiadm -m node -o delete -T iqn.2014-04.com.example:iscsi-target:storage --portal 192.168.122.101:3260
    
  • Stop the iscsi and iscsid service.
  • [root@iscsi-initiator ~]# chkconfig iscsi off
    [root@iscsi-initiator ~]# chkconfig iscsid off
    [root@iscsi-initiator ~]# service iscsi stop
    Stopping iscsi:                                            [  OK  ]
    [root@iscsi-initiator ~]# service iscsid stop
    Stopping iscsid:                                           [  OK  ]
    

Sunday, April 26, 2009

Linux Boot Process

In this section we will see about Booting Process of a Linux Machine.

6 Stages of Linux Machine Boot process

Booting Sequence

1. BIOS

  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks
  • Searches, loads, and executes the boot loader program.
  • It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
  • So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is less than 512 bytes in size. This has three components 
    1. Primary boot loader info in 1st 446 bytes 
    2. Partition table info in next 64 bytes 
    3. MBR validation check in last 2 bytes.
  • It contains information about GRUB (or LILO in old systems).
  • So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB

  • GRUB stands for Grand Unified Bootloader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-194.el5PAE)
          root (hd0,0)
          kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
          initrd /boot/initrd-2.6.18-194.el5PAE.img 
  • As you notice from the above info, it contains kernel and initrd image.
  • So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel


  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels
    • 0 – halt
    • 1 – Single user mode
    • 2 – Multiuser, without NFS
    • 3 – Full multiuser mode
    • 4 – unused
    • 5 – X11
    • 6 – reboot
  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
  • Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
  • If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
  • Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

  • When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
  • Depending on your default init level setting, the system will execute the programs from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/
  • Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
  • Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
  • For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
There you have it. That is what happens during the Linux boot process.

Note: Thanks to theeekstuff.com for the content.