Tuesday, May 31, 2011

VMware Virtual Disk Hot Add for Linux guests



With VMware ESX 3.0 it is possible to hot add a new virtual disk to a running guest. I want to show what to do to use it with a linux guest without a reboot:
  1. add a new disk to the running guest via VI-Client
  2. scan for new hard disk in the guest
3.    echo "- - -" > /sys/class/scsi_host/host0/scan
for reference the output of
cat /proc/scsi/scsi
before
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware   Model: Virtual disk     Rev: 1.0
  Type:   Direct-Access                    ANSI SCSI revision: 02
and after the scan
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
  Vendor: VMware   Model: Virtual disk     Rev: 1.0
  Type:   Direct-Access                    ANSI SCSI revision: 02
Attached devices:
Host: scsi0 Channel: 00 Id: 01 Lun: 00
  Vendor: VMware   Model: Virtual disk     Rev: 1.0
  Type:   Direct-Access                    ANSI SCSI revision: 02
  1. find out the device of the new hard disk (/dev/sdb in the example above)
  2. check if there is really no partition on the device
6.    fdisk -l /dev/sdb
7.     
8.    Disk /dev/sdb: 1073 MB, 1073741824 bytes
9.    255 heads, 63 sectors/track, 130 cylinders
10. Units = cylinders of 16065 * 512 = 8225280 bytes
11.  
12. Disk /dev/sdb doesn't contain a valid partition table
  1. create new partition on the device (with fdisk)
  2. create new filesystem on the partition created above
15. mkfs.ext3 /dev/sdb1
  1. add line to /etc/fstab to automount partition after next reboot
17. /dev/sdb1       /mountpoint       ext3    defaults        0       2

How to add SCSI disk on RHEL 5 in VMWare


1)    Once Newly created LUN is presented to the RHEL5 server, run the c  ommand to scan the SCSI bus:
# echo "- - -" >/sys/class/scsi_host/host#/scan
The “- – -” is used for Bus Channel , for Target id and Lun .

2.Check the /var/log/messages file to find the device name , in example the secondary disk device name is sdb
# tail -f /var/log/messages
# fdisk -l /dev/sdb
 
Partitioning
Assuming that you are using fdisk to partition your disk, and that the disk is identified by your system as sdb (the second scsi device), then the following steps should allow you to create the necessary partition:
1.    fdisk /dev/sdb
this will launch the fdisk application. As with all usage of the fdisk command, I must remind you that any changes you make here will remove access to data you have on the
disk you pass as the parameter to this command.
  1. type n for new
  2. type p for primary partition
  3. type 1 for the first partition
  4. accept the defaults for the start and end blocks (ie maximum size)
  5. type t to change the type
  6. enter the code 8e for Linux LVM
  7. enter w to write the changes to disk and exit the application
  8. partprobe
LVM Physical Volume Creation

Whether or not you chose to partition the new disk, you will need to add it to the LVM configuration as a PV. To do this issue the command
pvcreate /dev/sdb1
(or pvcreate /dev/sdb if not partitioned)
If you want to see the before and after effects issue the command pvscan and pvdisplay before and after the pvcreate command shown above

Volume Groups

use of this command depends on whether or not you wish to add the new PV to an existing LVM Volume Group (VG) or a new VG.
To create a new VG: <<<TBD>>>(notes about different VG's in the same LV)<<<TBD>>>
vgcreate VolGroupXX /dev/sdb1
 
(or /dev/sdb if not partitioned), where the parameter VolGroupXX is the usual format for Volume Group named in RedHat, but any name meaningful to you as the system administrator can be used, with the XX being a 2 digit number.
To extend an existing VG:
vgextend VolGroupXX /dev/sdb1
 vgextend vgname  /dev/sdb1
(or /dev/sdb if not partitioned), where the paremeter VolGroupXX is the name of the existing Volume Group.
as above, before and after changes can be observed by running the vgscan and vgdisplay commands before and after the create or extend commands

Logical Volumes

To increase the size of the (or create a new) LVM Logical Volume (LV)
To create a new LV:
lvcreate -l 100%FREE -n /dev/VolGroupXX/LogVolYY /dev/VolGroup00
 
Alternative way
lvcreate -l 6335 -n /dev/vgname/lvname ( Specify the full space)
 
 
where the following parameters are used:
-l 100%FREE - uses all the available space in the Volume Group. Can be changed for -L nn[KMGTPE] for nn Kilo, Mega, Giga, Tera, Peta, Exa bytes -n /dev/VolGroupXX/LogVolYY - this is the name of the Logical Volume expressed as a path. With XX & YY as 2 digit numbers. This naming convention can be changed to suit your own needs but follows the default RedHat configuration. /dev/VolGroupXX - is the VG to take extents from for this LV.
To extend an existing LV:
lvextend -l +100%FREE /dev/VolGroupXX/LogVolYY /dev/sdb1
 
where the following parameters are used:
-l +100%FREE - extends the LV by all the available space in the VG. Can be changed as before for absolute values using -L. The preceding + means extend the current value by this much. Omitting the + means set the value to this much - if you pick the wrong value, you can actually shrink the LV!, which would be fatal if the file system has not yet been resized. /dev/VolGroupXX/LogVolYY - this is the LV you wish to extend /dev/sdb1 - this is teh PV you wish to use to extend the LV.

mkfs.ext3 /dev/vgname/lvname
Mount the partition wherever you want to map it.
mount /dev/vgname/lvname /path/tomap
Add it in fstab entries for permanent Access.



Tuesday, May 17, 2011

Find out Last reboot / shutdown time in Linux


Here is the method:
There are actually three ways of displaying the last system boot.


The command called LAST will provide the last reboot or shutdown time and date.


Using the LAST command to show last shutdown/reboot time and date:


# last reboot
 wtmp begins Fri Apr  15 12:39:32 2011

# last shutdown
 wtmp begins Fri Apr 15 12:39:32 2011

The LAST command also lists the sessions of users logged in at a specific date and time as well.



Using the WHO command and the “-b” option:


$ who -b
 system boot  2011-04-15 12:39


You can also use "uptime" command to know the server uptime.