martedì 26 novembre 2013

Red Hat: How to check and repair your root-filesystem in rescue mode

Problem resolution:

Take a Linux installation media of your distribution and boot into linux rescue mode by typing the following command when asked for boot options:
linux rescue



Select your language and keyboard layout:






Network configuration is not necessary and can be skipped:





A very important step is to SKIP the mount of your Linux installation. Do not use MOUNT or READ-ONLY. For a filesystem check it is required that the filesystem is unmounted. Once mounted it is nearly unpossible to unmount your root-filesystem in rescue mode.





If you are not using a Logical Volume Manager for your filesystems you can directly jump to execute the “fsck” command. Otherwise you will have to first scan for your Physical Volumes and review them:
lvm pvscan
lvm pvdisplay




If your Physical Volumes were listed correctly continue to review the detected Volume Groups:
lvm vgdisplay

Now continue to activate your Volume Groups in order to create your Logical Volume devices in the “/dev” filesystem. In this example a Volume Group with the name “VolGroup00″ has to be activated:
lvm vgchange -a y VolGroup00




After activating your Volume Group(s), you will be able to perform a filesystem check and correct problems:
fsck /dev/VolGroup00/LogVol00




Once the filesystem check finishes successfully, you should be able to reboot without any further complication.


giovedì 14 novembre 2013

Redhat CentOS partition management (LVM)

 15  echo "- - -" >/sys/class/scsi_host/host0/scan
Questo comando forza un rescan del controller SCSI
This command forces the system to rescan the SCSI controller.

   16  fdisk -l
   17  fdisk /dev/sdb
Ho creato una partizione primaria di tipo 8e (LVM)

Created a primary partition type 8e (LVM partition)

   19  man fdisk
   20  fdisk -u /dev/sdb
   21  fdisk -l
   22  pvcreate /dev/sdb1
 Questo comando collega il disco al sistema LVM
This command is adding the phisical volume to the volume group

   23  vgs
Volume Group Show

   24  pvadd
   25  vgextend
   26  vgextend --help
   27  vgs
   28  vgextend smosvg /dev/sdb1

Aggiunto nuovo disco al Volume Group

Added the new partiton created to the volume group I want to expand

   29  vgs
   30  lvextend
   31  lvextend --help
   32  lvs
Logical Volume show

   33  lvextend -l +100%FREE /dev/mapper/smosvg-optvol

QUesto comando allarga il volume "optvol" con tutto lo spazio libero nel Volume Group

This command will expand the "optvol" with all the available space (+100%) in the volume group
   34  lvs
   35  resize2fs /dev/mapper/smosvg-optvol
Rircostruisce il file system con le nuove dimensioni
Rebuilds the file system with the new dimentions

   36  df -h

lunedì 11 novembre 2013

RedHat CentOS setting Date and Time

Date and Time Setup
The date command allows the superuser to set the system date and time manually:
Change the current date. Type the command in the following form at a shell prompt, replacing the YYYY with a four-digit year, MM with a two-digit month, and DD with a two-digit day of the month:

~]# date +%D -s YYYY-MM-DD

For example, to set the date to 2 June 2010, type:
~]# date +%D -s 2010-06-02

Change the current time. Use the following command, where HH stands for an hour, MM is a minute, and SS is a second, all typed in a two-digit form:

~]# date +%T -s HH:MM:SS

If your system clock is set to use UTC (Coordinated Universal Time), add the following option:
~]# date +%T -s HH:MM:SS -u
For instance, to set the system clock to 11:26 PM using the UTC, type:
~]# date +%T -s 23:26:00 -u

Change TimeZone Using /etc/localtime File

For this example, assume that your current timezone is UTC as shown below. You would like to change this to Pacific Time.
# date
Mon Sep 17 22:59:24 UTC 2010
On some distributions (for example, CentOS), the timezone is controlled by /etc/localtime file.
Delete the current localtime file under /etc/ directory
# cd /etc
# rm localtime
All US timezones are located under under the /usr/share/zoneinfo/US directory as shown below.
# ls /usr/share/zoneinfo/US/
Alaska          Arizona         Eastern         Hawaii          Michigan        Pacific
Aleutian        Central         East-Indiana    Indiana-Starke  Mountain        Samoa
Note: For other country timezones, browse the /usr/share/zoneinfo directory
Link the Pacific file from the above US directory to the /etc/localtime directory as shown below.
# cd /etc
# ln -s /usr/share/zoneinfo/US/Pacific localtime
Now the timezone on your Linux system is changed to US Pacific time as shown below.
# date
Mon Sep 17 23:10:14 PDT 2010

Redhat CentOS disable iptables Firewall

How Do I Disable Firewall?

First login as the root user.






Check if firewall is running



#service iptables status

Next enter the following three commands to disable firewall.

# service iptables save
# service iptables stop
# chkconfig iptables off


If you are using IPv6 firewall, enter:

# service ip6tables save
# service ip6tables stop
# chkconfig ip6tables off

Redhat CentOS mount USB key

TO MOUNT A USB KEY
insert key
dmesg to see the device name that can be any sb-b-c-d depending on your system.

mount /dev/sdb1 /

Remember the "1" after sdb

RedHat CentOS mounting virtual-phisical cdrom-dvdrom

When you plug the external USB drive in you should see messages like these from 'dmesg'

usb 1-2.3: USB disconnect, address 8
usb 1-2.3: new high speed USB device using ehci_hcd and address 9
scsi6 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 9
usb-storage: waiting for device to settle before scanning
Vendor: LITE-ON Model: DVDRW SHW-1635S Rev: YS0J?
Type: CD-ROM ANSI SCSI revision: 00
sr0: scsi3-mmc drive: 48x/48x writer cd/rw xa/form2 cdda tray
Attached scsi CD-ROM sr0 at scsi6, channel 0, id 0, lun 0
usb-storage: device scan complete

If you don't see the 'Vendor' stuff there's nothing that can be done. Your drive/enclusure combination do not work together. This isn't a Linux issue but a Firmware/BIOS issue between the drive and enclosure. Try another drive/enclosure combination, or give up.

If you seen the 'Vendor' stuff and the message regarding 'Attached scsi CD-ROM sr0' then you may be in luck! Linux recognised the drive and has attached it.

Put a CDROM or DVDROM in the drive and attempt to mount it.

    mount -t iso9660 -o ro /dev/sr0 /mnt

(you may have another device name. I have seen /dev/scd0)

No returned errors will mean that you have successfully mounted the CDROM under /mnt.

Any error about missing block device will mean that you need to install and load some kernel modules.

RedHat Centos Network configuration (CLI)

Set Default gateway:
insert in /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=
GATEWAY=

##############################################################################
Backup existing static configuration

First backup existing network configuration file using cp command:
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak

Configuring a DHCP Client

Setting up a Linux for dhcp can be done by editing file using a text editor such as vi:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Following is sample static configuration:
DEVICE=eth0
BOOTPROTO=static
HWADDR=00:19:D1:2A:BA:A8
IPADDR=10.10.10.10
NETMASK=255.255.255.0
ONBOOT=yes

Replace static configuration with DHCP:
DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=00:19:D1:2A:BA:A8
ONBOOT=yes

Save and close the file. Just restart network service:
# /etc/init.d/network restart

Please note that you need a configuration file for each device that you want to configure to use DHCP.Backup existing static configuration

First backup existing network configuration file using cp command:
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /root/ifcfg-eth0.bak


Save and close the file. Just restart network service:
# /etc/init.d/network restart

Please note that you need a configuration file for each device that you want to configure to use DHCP.