Friday, February 3, 2017

How to Shrink or reduce size of LVM partitons in RHEL/CentOS

LVM (Logical Volume Manager) is a tool for logical volume management which includes allocating disks, striping, mirroring and resizing logical volumes.With LVM, a hard drive or set of hard drives is allocated to one or more physical volumes.

LVM allows users to create partitions from more than one disk and allows them to extend the filesystem size online within few seconds.

In this post, we will see how we can shrink the size of an LVM partition without losing data.

On my linux virtual machine, the VG name is “rootvg” and LV name is “Vibhor” which has 60 GB size. I want to reduce the LV size to 4GB. Please note down the following points before proceeding with the shrinking of filesystem.

  • Make sure the current disk usage of the filesystem is less than the size to which you are going to reduce the logical volume.
  • Always take a backup of filesystem data before doing any size change in LVM as a simple mistake in command can cause filesystem corruption and hence loss of data.

Now, please find the below steps which we need to follow for reduce or shrink the partition size.

Umount the filesystem:

We will check the file system through fsck command but before running fsck on the filesystem, it should be unmounted.You can unmount the filesystem “/vibhor” as follows.

#umount /Vibhor

Performing filesystem check:
Before proceeding with reducing filesystem, “fsck” should be done in order to avoid inconsistency of filesystem data.
#e2fsck –f /dev/mapper/rootvg/rootvg_vibhor

Resizing filesystem:

Now, we will reducing the size of the Logical Volume, but before we need to reduce the filesystem in it. The command “resize2fs” can be used for this as follows.

#resize2fs –p /dev/mapper/rootvg/rootvg_vibhor 4G

This will decrease or shrink the filesystem size to 4GB.

Reducing the LV size:

After reduce or shrink the filesystem, we can reducing the LV as given below.

#lvreduce –L 4G /dev/mapper/rootvg/rootvg_vibhor

This will reduce the logical volume size to 4 GB. Now I will mount the filesystem again and check it using the command “df –h”. the file system has reduced to 4 GB without losing any data.

#mount /Vibhor
#df –h

This output will show you the reduce filesystem size.

Thursday, February 2, 2017

How to stop USB Mass Storage device in RHEL/CentOS

Hello Friends,

I’d like to disable all USB devices connected to our Red Hat Linux based workstations. I’d like to disable USB flash or hard drives, which users can use with physical access to a system to quickly copy sensitive data from it.

How do I disable USB device support under RHEL/CentOS workstation operating systems. The USB storage drive automatically detects USB flash or hard drives. You can easily force and disable USB storage devices under any Linux distribution.

The modprobe program used for automatic kernel module loading and can be configured to not load the USB storage driver upon demand. This will prevent the modprobe program from loading the usb-storage module, but will not prevent root (or another program) from using the insmod program to load the module manually.


In linux it’s even more easily done, by unloading the usb_storage module:

for disable the usb storage run the below command :-

# modprobe -r usb_storage

for enable the usb storage run the below command :-

# modprobe -i usb_storage

##############################################################################

The easiest way to disable usb storage device in linux is create following file And add following line inside the file

# touch /etc/modprobe.d/no-usb


install usb-storage /bin/true

##############################################################################

How we will block USB on linux machine.

Hello Friends,

We can block the usb drive on linux system very easily. There are several ways using this we can block or open the USB drive on machine.

Here, we will block USB using script. This script is used in any version on Linux ( Redhat, Centos).
You can create a any .sh file on your linux machine and paste this below script content.

##############################################################################

#!/bin/bash
clear ;
yum -y install sshpass &> /tmp/temp ;
apt-get install sshpass -y &> /tmp/tmp ;
echo  " Welcome $USER , *** WARNING: THIS PROGRAM WILL RESTART THE REMOTE MACHINE *** "
echo ""
echo  " 1. Block USB ports of Machine "
echo  " 2. Open USB ports of Machine "
echo ""
echo -ne " Please Select your choice : "
read choice ;
echo -ne " Please Enter the IP address of Machine : "
read ip ;
echo -ne " please Enter the password for $ip : "
read -s pass ;
case "$choice" in

1)      echo -e "\n";
        echo -ne " You are going to Block the USB ports of $ip ,Are you sure you want to continue connecting (Yes/no)? "
    read choice1 ;
        if [ "$choice1" == "no" ];
        then
                exit ;
        else
                sshpass -p $pass ssh $ip  "echo 'blacklist usb_storage' >>  /etc/modprobe.d/blacklist.conf ; echo 'modprobe -r usb_storage' >> /etc/rc.local ; "
        fi

        echo -e "\n"
        echo -ne " $ip needs a reboot, So we are going to reboot $ip machine. Press 0 to EXIT or Press Enter to reboot the Machine."

        read choice2 ;
        if [ "$choice2" == "0" ]
        then
                exit ;
        else
                 sshpass -p $pass ssh $ip reboot ;
        fi

    ;;
2)      echo -e "\n" ;
        echo -ne " You are going to Open the USB ports of $ip ,Are you sure you want to continue connecting (Yes/no)? "
        read choice3 ;
        if [ "$choice3" == "no" ]
        then
                exit ;
        else
                 sshpass -p $pass ssh $ip "sed -i 's/"blacklist usb_storage"/""/g' /etc/modprobe.d/blacklist.conf ; sed -i 's/"modprobe -r usb_storage"/""/g' /etc/rc.local ;"
        fi
    ;;
*) echo "you have not selected the right option, Try Again. Bye"
   ;;
esac

##############################################################################

When you run the script, it is asking for 2 options, first option is used for blocking the USB drive and second option is for open the block usb drive.

Please read the script carefully and please let me know if you have any doubt in your mind. I will try to resolve your query as earliest.

Tuesday, January 24, 2017

How to add a fake dummy null printer in centos 7

Please find the below step by step simple method to add tge fake , dummy or Null printer on Centos7

1. Install the rpm packages for configuration of printer
#yum install system-config-printer*

2. Install cups printer packages
#yum install cups*

3. start the cups services on the centos 7

# systemctl status cups
cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
   Active: inactive (dead)

# systemctl restart cups

# systemctl status cups
cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2017-01-23 09:23:11 GMT; 4s ago
 Main PID: 6121 (cupsd)
   CGroup: /system.slice/cups.service
           └─6121 /usr/sbin/cupsd -f

Jan 23 09:23:11 linux systemd[1]: Started CUPS Printing Service.
Jan 23 09:23:11 linux systemd[1]: Starting CUPS Printing Service...

Please add below line in cupsd.conf if doesn't exist.

# vi /etc/cups/cupsd.conf
FileDevice yes

Command to add a printer-

# lpadmin -p myprinter -E -v file:///dev/null

To check the default printer status-

# lpstat -s
no system default destination
device for myprinter: ///dev/null

Monday, January 23, 2017

XSCF sun solaris command

In order to login into console from XSCF you must know in which domain you want to login into.

1. To show all the domains on a server.

XSCF> showdomainstatus -a
DID         Domain Status
00          Running
01          Running
02          -
03          -

2. To check the status of server.
XSCF> showstatus
No failures found in System Initialization.
Note: Currently on the server no hardware fault. this command clearly show the current status.

3. To login in domain-

XSCF> console -d 00
Console contents may be logged.
Connect to DomainID 0?[y|n] :y

if the console is not appear then you can run the below command to take a console forcefully.
XSCF> console -d 00 -f
Console contents may be logged.
Connect to DomainID 0?[y|n] :y

4. To check the complete hardware status from XSCF.
XSCF> showhardconf


5. To return to XSCF from domain , type
#.

6. To power-on & power-off the domain
XSCF> poweroff -d 00

XSCF>poweron -d 00

Note: if domain 00 is not power off , you can use "-f" with command to shutdown forcefully.

7. To check the error & power logs from SXCF

XSCF> showlogs error
Date: Nov 02 11:15:03 UTC 2016     Code: 40000200-cfffd701-0300003200000000
    Status: Information            Occurred: Nov 02 11:15:02.536 UTC 2016
    FRU: /HDD#0,/IOU#0
    Msg: Boot process failed

XSCF> showlogs power
Date                          Event            Cause          DID  Switch
Jan 01 00:29:36 UTC 2001      SCF Reset        Power On       --   Locked
Jan 01 01:43:31 UTC 2001      SCF Reset        Self Reset     --   Locked

8. To check the hostname of XSCF server

XSCF> showhostname -a

9. To view the fault management logs

XSCF> fmdump -v
TIME                 UUID                                 MSG-ID
Nov 02 11:15:03.3078 b121fe1b-a418-4b9e-8a23-474dda80891f SCF-8001-KC
   66%  upset.chassis.SPARC-Enterprise.io.disk.boot

10. To reboot the XSCF

XSCF>rebootsxcf

11. To display complete network information

XSCF> shownetwork  -a

xscf#0-lan#0
          Link encap:Ethernet  HWaddr 00:21:28:6E:C4:AA
          inet addr:192.168.0.1  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:240177064 errors:419 dropped:0 overruns:0 frame:0
          TX packets:75330 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3346969538 (3.1 GiB)  TX bytes:12900961 (12.3 MiB)
          Base address:0xe000

xscf#0-lan#1
          Link encap:Ethernet  HWaddr 00:21:28:6E:C4:AB
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Base address:0xc000






Friday, January 20, 2017

Sun Solaris useful commands

1. to check the storage size useful

dipso

2. to check the product model

prtconf -b

3.Display system information

cat /etc/release

4.How to display a system phycial processor type

psrinfo -pv

5. to check the SUN powerpath

/etc/powermt version

or

pkginfo -l EMCpower


6. To check the sun server system configuration

#prtdiag

Thursday, January 19, 2017

Solaris failed connect to studio repo connection refused error

Generally when user trying to install the packages from Solaris studio repo, he/she is getting below error as described in the Yellow text

1. Here i am trying to install the X11 client on solaris machine.

root@solaris:~# pkg install pkg://solaris/x11/diagnostic/x11-info-clients

pkg: 1/3 catalogs successfully updated:
Unable to contact valid package repository
Encountered the following error(s):
Unable to contact any configured publishers.
This is likely a network configuration problem.
Framework error: code: 7 reason: Failed connect to studio-repo.oracle.com:1008; Connection refused
URL: 'http://studio-repo.oracle.com' (happened 6 times)


Framework error: code: 7 reason: Failed connect to solaris-repo.oracle.com:1008; Connection refused
URL: 'http://solaris-repo.oracle.com/versions/0/'
any suggestion ??

Solution:

Please check which services is not running on the server , due to which server is not ready to download the packages.

To check the status of service please run the below commnad.

root@solaris:~# svcs \*pkg\*
STATE          STIME    FMRI
disabled       Jan_29   svc:/application/pkg/dynamic-mirror:default
disabled       Jan_29   svc:/application/pkg/mirror:default
disabled       Jan_29   svc:/application/pkg/server:default
online         12:53:49 svc:/system/pkgserv:default
online         12:54:00 svc:/application/pkg/zones-proxy-client:default
online         12:54:09 svc:/application/pkg/repositories-setup:default

Now restart the all enable service then after again start to install the package.