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

Wednesday, September 6, 2017

Linux Interview Questions and Answers for fresher and senior - Linvirtshell

Wednesday, September 06, 2017 0
1. what is the maximum number of partitions that can be made on a hard drive?

 In a hard disk we can create 4 primary partitions or alternatively 3 primary partitions and an extended partition. 

The primary+extended partition can be divided into 63 logical partitions  ( Also it depends on the MBR table size)



2. How to extend the lvm with physical extent?

Free PE / Size 952 / 3.72 GB
In this case use Free PE # 952 ,this will assign the entire disk 3.72 GB, use -l and + sign.


#sudo lvextend -l +952 /dev/vol_grp1/logical_vol1


Also resize the file system resize2fs after extending the lvm


3. how to pass sudo password in shell script? 

echo "password" | su - -c "cp -pr /boot/ /home/nsk/"

4. How to Update an A record from Command Line in DNS? 

 It should be run an authoritive name server.

Edit the zone file with your favorite command line editor. In this example, we use ‘vi’.


[root@host /var/named/]% vi /var/named/example.com.db
Locate the appropriate line and update the up address. You will see something like the following:
ftp IN A 192.168.1.100
Update the Zone’s Serial number.
Make BIND aware of your DNS changes by reloading the DNS zone.


[root@host /var/named/]% rndc reload example.com


Test that your changes worked correctly using ‘dig’.
[root@host /var/named/]% dig @localhost ftp.example.com


5. What are the types of DNS servers available?

a. Master
b. Slavec. 
c. Caching only DNS server
d. Forwarding only DNS server

6. DNS default & Main configuration file.

Main configuration file for dns server is named.conf. By default this file is not created in /var/named/chroot/etc/ directory. Instead of named.conf a sample file /var/named/chroot/etc/named.caching-nameserver.conf is created. This file is use to make a caching only name server. You can also do editing in this file after changing its name to named.conf to configure master dns server or you can manually create a new named.conf file

We are using bind's chroot features so all our necessary files will be located in chroot directory. Set directory location to /var/named. Further we will set the location of forward zone and reverse lookup zone files. If you cannot create this file manually then download this file and copy to /var/named/chroot/etc/

We have defined two zone files example.com.zone for forward zone and 0.168.192.in-addr.arpa for reverse zone. These files will be store in /var/named/chroot/var/named/ location. We will use two sample files for creating these files.


7. what is the difference between yum update and yum upgrade?

yum upgrade and yum update will perform the same function that update to the latest current version of package.

But the difference is Upgrade will delete obsolete packages, while update will preserve them.


8. Explain the yum erase and yum remove.


yum erase : Remove all the rpms and keep the config file
yum remove : Remove all the file.


9. How to set up a SAN boot LUN on LInux.


We can set up a SAN boot LUN to work in a Red Hat Enterprise Linux environment that is using the FC protocol.

Before you begin verify that your system setup supports SAN boot LUNs. See the Interoperability Matrix.

Steps
Create a LUN on the storage system and map it to the host. This LUN will be the SAN boot LUN.
You should ensure the following:
a. The SAN boot LUN is mapped to the host.
b. Multiple paths to the LUN are available.
c. The LUN is visible to the host during the boot process.
d. Enable the BIOS of the HBA port to which the SAN boot LUN is mapped.
For information about how to enable the HBA BIOS, see your HBA vendor-specific documentation.
e. Configure the paths to the HBA boot BIOS as primary, secondary, tertiary, and so on, on the boot device.
For more information, see your vendor-specific documentation.
f. Save and exit.
g. Reboot the host.
h. Install the operating system on the SAN boot LUN.
Note: For Red Hat Enterprise Linux 5 series, you must specify Boot Option as linux mpath during the operating system installation. When you specify linux mpath, you can see the multipath devices (/dev/mapper/mpathx) as installation devices.
i. Install the Host Utilities.
j. Configure DM-Multipath.


10. How to create GFS file system.


mkfs.gfs2 -p LockProtoName -t clustername:clusterfilesystem -j NumberJournals BlockDevice
mkfs.gfs2 -p lock_dlm -t alpha:mydata1 -j 8 /dev/vg01/lvol0


11. How to extend the GFS file system

gfs2_grow /mygfs2fs


12. How to repair GFS file system
fsck.gfs2 -y /dev/testvg/testlv


13. How to add journal to a file systemgfs2_tool journals /mnt/gfs2      : find out how many journals the GFS2 file system currently contains

gfs2_jadd -j1 /mygfs2  


14. Is my hard drive is dying?   How to check?


check hard disk for errors using smartctl command
smartctl -a /dev/sda


15. Find out the largest directories or files eating disk space on a Unix-like systesm:

#du -a /ftpusers/tmp | sort -n -r | head -n 10

#du -cks * | sort -rn | head

Explain about vpxd.cfg Configuration

Wednesday, September 06, 2017 0
vpxd.cfg is an XML formatted file which can be modified to alter the native behavior of the VMware vCenter Server.  Sparse references on the internet document the changes that can be made in this environment. 

The vpxd.cfg file is located on the VMware vCenter Server by default at %ALLUSERPROFILE%\Application Data\VMware\VMware VirtualCenter\vpxd.cfg

  • On Windows Server 2008, this would generally be C:\ProgramData\VMware\VMware VirtualCenter\vpxd.cfg
  • On Windows Server 2003, this would generally be C:\Documents and Settings\All Users\Application Data\VMware\VMware VirtualCenter\vpxd.cfg
This collection of vpxd.cfg settings has been sourced from various places.  The parameters will generally apply to a version of vCenter Server ranging from 2.0 through 4.x.  A given parameter can apply to several or even all versions.Remember to restart the VMware VirtualCenter Server service in the Server Manager for changes to vpxd.cfg to take effect.

**Disclaimer**

As with anything found on this site and much of the internet in general, information is provided “as is” without warranty.  Modify settings at your own risk.  I suggest thoroughly researching the changes first and also checking with VMware Support.

Backup and Restore ESXi Configuration with PowerCLI Commands

Wednesday, September 06, 2017 0

Now, the process of backing up and restoring the configuration of ESXi is fairly simple.

 Backup and Restore ESXi Configuration with PowerCLI, the steps:

Open PowerCLI > Connect to vCenter with Connect VI-Server command and enter this single line to backup the configuration of all the hosts that are attached to vCenter server.

  get-vmhost | get-vmhostfirmware -BackupConfiguration -DestinationPath “C:\temp\anyfolder”  all files fileswill be copied to c:\temp\any folder 

Now, if We need to restore a host’s configuration,  need to put the host into maintenance mode first and then

Enter the restore command:
Set-VMHostFirmware -VMHost <IP_or_FQDN> -Restore -Force -SourcePath
The host will reboot immediately after we hit the enter key without any prompt.

Reset the root password of an ESXi server using Host Profiles

Wednesday, September 06, 2017 0
 Here is an overview of the steps to reset the root password:
  • Select the ESXI server.
  • Put the host in Maintenance mode
  • Open the vSphere Client
  • In Host Profiles, Create a Profile from existing host and select the host, enter the Name
  • Nagivate to the security configuration, Administrator Password and select “Configure a fixed administrator password”
  • Enter the new root password twice

  • Attach the host profile to the host
  • Right-click the host and select Apply Profile
  •  Wait till the Host Profile Compliance status is Compliant. The root password is now changed!
  • Test if it is possible to SSH to the ESXi host
  • Delete the Host Profile
  • Exit maintenance mode
 Enterprise Plus is need to use Hostprofile else requested to use  a 60 day trail license of VMware vSphere.

How to change the root password for all esxi hosts in a vcenter using script

Wednesday, September 06, 2017 0

The following script will change the root password for all esxi hosts in a vcenter. We should run the script using PowerCLI.

Before We  run the script you should create a scripts folder on the root of our C:\ drive and copy the script to there. We  need to have the current root password, the new root password and the name of the vCenter.

The script uses the Set-VMHostAccount cmdlet to change the root account password.

#Change Root Password Script for all hosts in a particular cluster

Copy the below code in a text file  and rename with passwd.ps1

#Prompt user for vCenter server and connect.
$vcenter = Read-Host "Enter vCenter Server: "
$vCenterUser = Read-Host "Enter your vCenter Username: "
$vCenterPw = Read-Host "Enter your vCenter Password: "

Connect-VIServer -Server $vcenter -User $vCenterUser -Password $vCenterPw

Write-Host "Connected to vCenter Server: $vcenter"

#Prompt user for datacenter and cluster
$datacenter = Read-Host "Enter Datacenter: "
$cluster = Read-Host "Enter Cluster: "
#Gather hosts from vCenter for chosen cluster

Write-Host "Getting hosts from datacenter..."

$MyVMHosts = Get-Datacenter $datacenter | Get-Cluster $cluster | Get-VMHost
# If we want to chnage for all ESXi hosts
# $MyVMHosts =Get-VMHost

#Disconnect from vCenter
Disconnect-VIServer -Confirm:$false
Write-Host "Got the hosts.  Next..."

#Prompt user for old root password and new password

$oldpassword = Read-Host "Enter onfiguration backup utility to download a backup of this to your management server. old root password: "
$newpassword = Read-Host "Enter new root password: "
$newpassword2 = Read-Host "Enter new root password again: "

#Connect to hosts and change root password, then disconnect.

if ($newpassword -eq $newpassword2){
    foreach ($line in $MyVMHosts) {
        Connect-VIServer -Server "$line" -User "root" -Password "$oldpassword" -WarningAction SilentlyContinue
        Set-VMHostAccount -UserAccount "root" -Password "$newpassword"
        Disconnect-VIServer -Confirm:$false
        Write-Host "$line...done."
}
}else{
 Write-Host "New passwords do not match!"
}

Tuesday, September 5, 2017

How to backup ESXi configuration using VMA

Tuesday, September 05, 2017 0
vMA -vSphere Management Assistant it’s free download and it comes with your VMware vSphere.

    First  we need to open a console session on vMA with vi-admin as a user.
    Then enter this command with an -s switch (S  is for save…)
    vicfg-cfgbackup -s -server 195.168.0.10 /tmp/esxi5

To restore the same its quite easy, we can use the same command with -l as a switch (jusyt like “load” configuration). The  ESXi server needs to reboot after the loading the configuration from backup and so we must reply YES to complete the command. The ESXi host will reboot.

vicfg-cfgbackup -l -server  195.168.0.10 /tmp/esxi5

After rebooting the ESXi server finds it’s configuration files restored.

ENABLE Copy Paste operation between a Virtual Machine and your local machine Via Powershell

Tuesday, September 05, 2017 0
Below steps allows you to ENABLE Copy Paste operation between a Virtual Machine and your local computer. 

However VMware does not recommend this manipulation to avoid and limit Exposure of Sensitive Data Copied to the Clipboard section.

Enable-VMCopyPaste function allows you to enable copy Paste operation between a Virtual Machine and your local machine.

When using PowerCli, this setting can be applied without powering off the VM. However you'll need to do a stun/unstun operation (i.e. power on/off, suspend/resume, create/delete snapshot/storage VMotion) to achieve the same thing.

Enable-VMCopyPaste -VM "test"

  This will enable the copy paste of the server/Computer name test.

Friday, October 21, 2016

Reset the Root Password of RHEL-7 - Linvirtshell

Friday, October 21, 2016 0
Here is the procedure of what needs to be done in order to recover a forgotten root password on Redhat 7 Linux:
  1. We need to edit GRUB2 boot menu and enter user single mode
  2. Next, we need to remount / partition to allow read and write
  3. Reset the actual root password
  4. Set entire system for SElinux relabeling after first reboot
  5. Reboot the system from a single mode
Now that we understand the procedure we can proceed with Redhat 7 password recovery.

1. Edit GRUB2 boot menu

Start your system and once you see your GRUB2 boot menu use e key to edit your default boot item. Usually it is the first line:
Edit boot menu to initiate RHEL7 root password recovery
Once you hit e key you will see a screen similar to the one below:
Editing RHEL7 boot menu to enter single mode
Depending on you terminal screen size you may see more or less information. In case you have a small terminal screen size note the little down pointing arrow on the right edge of your screen. The arrow means that more text is available when scrolling down. Scroll down and locate a line with rhgb quiet keywords:
RHEL 7 boot line locate - edit
Move your cursor ( HINT: move to end of the line with CTRL+E ) on rhgb quiet keywords and replace them with init=/bin/bash as show below:
Edit grub to enter single mode to reset root password Redhat 7
Once you edit the boot line as show above press CTRL + x to start booting your RHEL 7 system into a single mode. At the end of the system boot you will enter a single mode:
RHEL 7 - entering single mode after system reboot

2. Read&Write root partition remount

Once you enter a single your root partition is mounted as Read Only ro. You ca confirm it with the following command:
# mount | grep root
In order to mount our partition with Read/Write flag we use mount with a remount option as follows:
# mount -o remount,rw /
Next, confirm that the root file system is mounted Read/Write rw:
# mount | grep root
All the above steps are show below:
Remount root filesystem as read&write on redhat 7 Linux server

3. Change root's password

Still in the single mode we can proceed with the actual root password recovery. To do this we use passwd command:
# passwd
You will need to enter your password twice as shown below:
Recover a forgotten root password on RHEL7 linux server

4. SELinux relabeling

The additional step which needs to be taken on SELinux enables Linux system is to relabel SELinux context. If this step is ommited you will not be able to login with your new root password. The following command will ensure that the SELinux context for entire system is relabeled after reboot:
# touch /.autorelabel
SELinux relabel system after reboot - Redhat 7 Server

5. Reboot System

The final step when resetting your lost root password on RHEL 7 linux system is to reboot. This can be done with a following command:
# exec /sbin/init

After reboot you will be able to use your new root password.