This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Thursday, September 14, 2017

Powershell script to list the Virtual Machines in SCVMM

Thursday, September 14, 2017 0

Windows PowerShell (SCVMM)

SCVMM One-liner command 1:   Outputs the VMName, VM Configuration File path, VHDCount, VHD Location, VHDSize, MaxVHDSize, Cluster for all VMs managed by the SCVMM server connected by PowerShell (in a single line)

$report = @(); $vms = get-vm; foreach ($vm in $vms){foreach ($vhd in $vm.VirtualHardDisks){$maxvhdsize = [math]::Round($vhd.MaximumSize/1024/1024/1024,1); $vhdsize = [math]::Round($vhd.Size/1024/1024/1024,1); $row = "" | select VMName, VMCPath, VHDCount, VHDLocation, VHDSize, MaxVHDSize, VMCluster; $row.VMName = $vm.Name; $row.VMCPath = $vm.VMCPath; $row.VHDCount = $vm.VirtualHardDisks.Count; $row.VHDLocation = $vhd.Location; $row.VHDSize = $vhdSize; $row.MaxVHDSIze = $MaxVHDSize; $row.VMCluster = $vm.VMHost.HostCluster.Name; $report += $row;};};$report | export-csv C:\Temp\Hyper-V-VMs.csv -NoTypeInformation


 

Brief Introduction about Annotation/ custom attributes in Vmware

Thursday, September 14, 2017 0

What are custom attributes?

Custom Attributes are attributes that a administrator can define for all Virtual Machines and Hosts in vCenter. The attributes are then displayed in the “Annotations” box for each VM. The custom attributes are also displayed alongside the VM Name, Status, State, CPU Usage, etc, when listing virtual machines in the Datacenter, cluster, host, and resource pool views.

Why use them?

Daily, we receive lots of clone requests for VMs. Clones are very good for application development and application troubleshooting. When an application on a VM goes pear shaped, the application vendor may request a clone for a system. They can then work on the clone system to try and fix some issues while the production system (if not broken completely) may in some cases still remain partially available to the end users. Once they are confident that they have resolved the issue, they can then implement the fix in the production environment.

This is all good and well, but here’s the problem. Clones are a drain on your resources. As administrator, you should be very careful to simply hand out clones as the requests come in. Virtual Machine clones can create a nightmare for administrators as they use huge amounts of additional disk space. Some of the clones we have today are in excess of 420GB. When creating clones, we need to make sure that the following information is recorded somewhere in vCenter:

·         Who requested the clone;

·         The requestor’s contact number/email address

·         The date that the clone was made;

·         The size of the clone on disk (all vDisk sizes combined + the amount of RAM  assigned to the VM);

·         Does it need to be backed up (Yes / No);

·         Reason for the clone;


Specifying your own Custom Attributes

Creating custom attributes is very simple. In the VI (or vSphere) client on the menu bar, click “Administration” >> “Custom Attributes...”

You’ll now be presented with the Custom Attributes dialog: You can file them b editing them manually once created.


Image

Getting ESXi Network driver firmware details by using Script.

Thursday, September 14, 2017 0
Find the script as follows.

$ExportFilePath = "C:\Users\user\Desktop\esxi.txt"
$PuttyUser = "root"
$PuttyPwd = "w2k8the$"
$HostNic = "vmnic0,vmnic1"
$Plink = "C:\Users\user\Desktop\plink.exe"
$PlinkOptions = " -v -batch -pw $PuttyPwd"
$RCommand = '"' + "ethtool -i " + $HostNic + '"'
$ESXHosts = Get-VMHost | where {$_.Model -match "ProLiant BL*"} | Sort Name
$Report = @()
ForEach ($ESXHost in $ESXHosts) {
        $Message = ""
        $HostInfo = {} | Select HostName,ESXVersion,Cluster,pNic,DriverName,DriverVersion,DriverFirmware
        $HostInfo.HostName = $ESXHost.Name
        $HostInfo.ESXVersion = $ESXHost.Version
        $HostInfo.Cluster = (Get-Cluster -VMHost $ESXHost.Name).Name
        $HostInfo.pNic = $HostNic
        Write-Host "Connecting to: " $ESXHost.Name -ForegroundColor Green
        $Command = $Plink + " " + $PlinkOptions + " " + $PuttyUser + "@" + $ESXHost.Name + " " + $rcommand
        $Message = Invoke-Expression -command $command
        $HostInfo.DriverName = ($Message[0] -split"driver:")[1]
        $HostInfo.DriverVersion = ($Message[1] -split"version:")[1]
        $HostInfo.DriverFirmware = ($Message[2] -split"firmware-version:")[1]
        $Report += $HostInfo
}

$Report = $Report | Sort-Object HostName
IF ($Report -ne "") {
$Report | Export-Csv $ExportFilePath -NoTypeInformation
}
Invoke-Item $ExportFilePath

Wednesday, September 13, 2017

Collecting diagnostic information of all ESXi By using PowerCLi Script

Wednesday, September 13, 2017 0
VMware Technical Support routinely requests diagnostic information from you when a support request is handled. This diagnostic information contains product specific logs, configuration files, and data appropriate to the situation. The information is gathered using a specific script or tool for each product and can include a host support bundle from the ESXi host and vCenter Server support bundle. Data collected in a host support bundle may be considered sensitive.



This article provides the procedures for obtaining this diagnostic information of all ESX/ESXi hosts using VMware vSphere PowerCLI.

 #Variable declaration
$vCenterIPorFQDN="VCName"
$vCenterUsername="domain\user" #Any User name who has access to Vcenter.
$vCenterPassword="xxxx"
$destination ="C:\Users\user\Desktop\naga\" #Location where to download support bundles
 
Write-Host "Connecting to vCenter" -foregroundcolor "magenta"
Connect-VIServer -Server $vCenterIPorFQDN -User $vCenterUsername -Password $vCenterPassword
 
$hosts = Get-VMHost #Retrieve all hosts from vCenter
 
Write-Host "Downloading vCenter support bundle" -foregroundcolor "magenta"
Get-Log -Bundle -DestinationPath $destination
 
foreach ($esxihost in $hosts){
Write-Host "Downloading support bundle for ESXi host $($esxihost.Name)" -foregroundcolor "magenta"
Get-Log -VMHost (Get-VMHost -Name $esxihost.Name) -Bundle -DestinationPath $destination
}


/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

Wednesday, September 13, 2017 0
When we encounter this error /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory this is how you can fix it:

This will happen only on 64 bit systems, the cause is the fact that 32 bit libraries are missing from the system, so we can easily fix this issue by installing the 32 bit libraries on our system.

In RHEL

yum -y install glibc.i686


If the issue happen in  Debian/Ubuntu/Mint

apt-get update
apt-get install ia32-libs

That's it.

How to Clone the LVM2 Volume Groups?

Wednesday, September 13, 2017 0
These instructions describe the steps required to clone an LVM2 volume
group by creating a duplicate copy of the physical storage (PVs). This
requires the VG be deactivated while the clone is created and
re-named.

The volume group being cloned, CloneVG consists of two PVs originally present
on /dev/testpv0 and /dev/testpv1. A new volume group named CloneVG-clone will
be created on devices /dev/testpv2 and /dev/testpv3.

1. Deactivate the VG

       # vgchange -an CloneVG

2. Create the cloned PV(s)

       E.g., dd, clone LUNs on storage, break mirror etc.

       # dd if=/dev/testpv0 of=/dev/testpv2
       # dd if=/dev/testpv1 of=/dev/testpv3

3. For each original PV, create a filter entry in /etc/lvm/lvm.conf to
temporarily mask the PV from the LVM tools.

Preserve a copy of the original filtering rules so that it can be
restored at the end of the process, for example:

       # cp /etc/lvm/lvm.conf /etc/lvm/lvm.conf.orig

To exclude the original loopback devices /dev/testpv0 and /dev/testpv1, the
filter line could look like this:

       filter = [ "r|/dev/testpv0|", "r|/dev/testpv1|", "a|.*|" ]

Or, using a regex to match both devices with a single rule:

       filter = [ "r|/dev/loop[01]|", "a|.*|" ]

Once the filters are set up, remove the LVM persistent cache:

       # rm -f /etc/lvm/.cache [versions before 2.02.23]
OR
       # rm -f /etc/lvm/cache/.cache [version 2.02.23 or later]

Verify that the filtering is correct by running pvscan:

       # pvscan
         PV /dev/testpv2   VG CloneVG         lvm2 [60.00 MB / 40.00 MB free]
         PV /dev/testpv3   VG CloneVG         lvm2 [60.00 MB / 40.00 MB free]
         Total: 2 [120.00 MB] / in use: 2 [120.00 MB] / in no VG: 0 [0   ]

Only the cloned PVs should be displayed. If the original PVs appear,
check the syntax of the filtering rule and clear the persistent cache
again.

4. Modify the cloned volume group name, ID and physical volume IDs to
avoid name and UUID clashes between the original and cloned devices:

For each cloned physical volume, run:

       # pvchange --uuid /path/to/physical/volume

This will generate a new random UUID for the specified physical volume
and update the volume group metadata to reflect the changed identity.

For example:

       # pvchange --uuid /dev/testpv2
         Physical volume "/dev/testpv2" changed
         1 physical volume changed / 0 physical volumes not changed
       # pvchange --uuid /dev/testpv3
         Physical volume "/dev/testpv3" changed
         1 physical volume changed / 0 physical volumes not changed

Generate a new UUID for the entire volume group using vgchange:

       # vgchange --uuid CloneVG
         Volume group "CloneVG" successfully changed

Finally, rename the cloned VG:

       # vgrename CloneVG CloneVG-clone

5. Remove filtering rules & verify both VGs co-exist correctly

Restore the original filtering configuration and wipe the persistent cache:

       # cp /etc/lvm/lvm.conf.orig /etc/lvm/lvm.conf
       cp: overwrite `/etc/lvm/lvm.conf'? y
       # rm -f /etc/lvm/.cache

Run pvscan to verify the new and old VGs are correctly displayed:

       # pvscan
         PV /dev/testpv0   VG CloneVG         lvm2 [60.00 MB / 40.00 MB free]
         PV /dev/testpv1   VG CloneVG         lvm2 [60.00 MB / 40.00 MB free]

         PV /dev/testpv2   VG CloneVG-clone   lvm2 [60.00 MB / 40.00 MB free]
         PV /dev/testpv3   VG CloneVG-clone   lvm2 [60.00 MB / 40.00 MB free]
         Total: 4 [240.00 MB] / in use: 4 [240.00 MB] / in no VG: 0 [0  ]

6. Activate volume groups

Both the original and cloned VGs can now be activated simultaneously:

       # vgchange -ay CloneVG
         1 logical volume(s) in volume group "CloneVG" now active

       # vgchange -ay CloneVG-clone
         1 logical volume(s) in volume group "CloneVG-clone" now active

Friday, September 8, 2017

How to setup passwordless `sudo` on Linux Easily

Friday, September 08, 2017 0
To allow  all users to set-up password-less sudo
Edit the visudo file by simply typing

ALL     ALL = (ALL) NOPASSWD: ALL

to allow all users to run all commands without a password.
Add the following line for a user called username alone  to setup password-less sudo

username ALL=(ALL) NOPASSWD: ALL

Add the following line for a group called wheel to set-up password-less sudo

# %wheel        ALL=(ALL)       NOPASSWD: ALL

Adding a user to Sudoers in simple way

Friday, September 08, 2017 0
Login as root to server. The root user are the only one who has privilege to add new user.

Once you logged-in, you may now try the following commands below:

    Create a new user.
    useradd  [username]
    Add password to user
    passwd [username]
    Grant root privileges to user Edit the visudo file by simply typing
    enter code here

Find the following line of code: 

root ALL=(ALL) ALL
Then add this code below:
[username] ALL=(ALL) ALL
In Otherway
 su - root
and enter your password, then :
echo 'USERNAME ALL=(ALL:ALL) ALL' >> /etc/sudoers

  to add the user in sudoers file