Tuesday, 16 October 2012

Reset the root password of VMware ESXi 4.1 and 5.0

Work on ESXi5.0 with Centos Live cd.
I used a CentOS 5.6 x86_64 LiveCD to boot the ESXi server into, then to find state.tgz, I had to mount the following:

# mount /dev/sdc5 /a
At that point, the file was located at /mnt/state.tgz, and I could continue the rest of the instructions above. To figure out which device to mount, I looked in '/dev/disk/by-label' and saw a link called 'ESXi' that pointed to /dev/sdc. From there, I mounted the partitions (sdc1, sdc2, sdc3, etc) and checked the contents until I found the partition with state.tgz in it (in my case it was /dev/sdc5 as indicated above).


The files containing the password hashes are called "shadow". It is contained in  a nested structure of archives:
You cannot read the password of the root account, as it is one-way-hashed, but you can replace it with a known one or remove it altogether.
Here's a step-by-step guide how change the password file:
1.    First of all, you need to boot your ESXi server with a Linux live CD. I prefer GRML, but any live CD will do. Of course, you can also boot from a USB stick.
 
2.    Find the partition containing a file named "state.tgz. You might need to mount it manually with the command
#mkdir /a
#mount /dev/sdc5 /a
 
3.    Unpack the "state.tgz" file somewhere. It contains exactly one file, which is another archive named "local.tgz".
#cd /a
#cp state.tgz state.tgz.bkup
#tar xzf state.tgz

 
4.    Unpack the "local.tgz", and find an "etc" directory containing several configuration files.
#tar xzf local.tgz
5.    Edit the file etc/shadow to change the password.
#vi etc/shadow
Probably the easiest way is to replace the line starting with "root" with the line of another user account of which you know the password. You only need to change the name at the beginning of the line (before the first colon) to "root". You've then set the root password to a password you know.
Alternatively, you can just remove the hash altogether (everything between the first and the second colon) and login to the service console as root with no password at all.
 
6.    Re-pack the files and move the modified state.tgz back to the VFAT partition. Probably it is a good idea to make a backup copy of the original state.tgz in case something goes wrong:
#rm local.tgz
#rm state.tgz
#tar czf local.tgz etc
#tar czf state.tgz local.tgz

 
7.    Reboot back into ESXi and you're done.

Wednesday, 10 October 2012

ILOM Basic Configuration Commands

 Bring the ok prompt from os

#shutdown –y –g0 –i0
Or
# init 0
OK

 Bring the ILOM prompt from ok prompt
Ok #.
è      

Shutdown the server from ILOM prompts
è    Stop /SYS

Start the server from ILOM prompt
à   Start /SYS

Getting the OK prompt
à set /HOST/bootmode script=”setenv auto-boot? =false”

Reset the SP to default value
à set /SP reset_to_defaults=value
all – removes all of the SP configuration data
factory – removes all the configuration data as well as all log files

power off and restart the host to complete the setting  change

 à stop /SYS
à reset /SP


Display the network properties

-> show /SP/network
/SP/network
Targets:
Interconnect
   ipv6
   test


Properties:
commitpending = (Cannot show property)
dhcp_server_ip = 10.8.31.5 <--- DHCP server
ipaddress = 10.8.31.188
ipdiscovery = dhcp
ipgateway = 10.8.31.248
ipnetmask = 255.255.252.0
macaddress = 00:14:4F:7E:83:4F
managementport = /SYS/MB/SP/NETMGMT
outofbandmacaddress = 00:21:28:8F:13:5F
pendingipaddress = 10.8.31.188
pendingipdiscovery = dhcp
pendingipgateway = 10.8.31.248
pendingipnetmask = 255.255.252.0
sidebandmacaddress = 00:21:28:8F:13:5E
state = enabled


Commands:
cd
set
show

Assign the network values
è    Set /SP/network state =enabled commitpending=true
è    Set /SP/network pendingipdiscovery=static commitpending=true
è    Set /SP/network pendingipaddress = <ip addr> pendingipsubnet=<netmask addr> pendingipgateway=<gatewaysddr>  commitpending =true

Friday, 5 October 2012

Solaris Sparc Servers ALOM Commands

To create the user in ALOM
SC> useradd <username>

To set the passwd for ALOM user
Sc>userpassword <username>

To Set the permission for ALOM user
Sc>userperm <username> cuar

To list ALOM user
Sc> usershow

To create the user in ALOM using scadm utility
#scadm useradd <username>

To set password for ALOM user using scadm utility
#scadm user password <username>

To  set the permission for ALOM user using scadm utility
#scadm userperm <username> cuar

To  list  ALOM user using scadm utility
#scadm usershow

To view the platform
Sc>showplatform
To set the Network properties
Sc>shownetwork

sc> setsc if_network true
sc> setsc netsc_ipaddr 123.123.123.123
sc> setsc if_connection ssh

# scadm set if_network true
# scadm set netsc_ipaddr 123.123.123.123
# scadm set if_connection ssh

To display the ALOM version
Sc>showsc version




 

VMware ESXi commands

To find ESXi software version & build
# vmware -v
VMware ESXi 5.0.0 build-469512
# vmware -l
VMware ESXi 5.0.0 GA

To see the running process
 # esxtop
To list the network cards properties
# esxcfg-vmknic -l
Interface  Port Group/DVPort   IP Family IP Address      Netmask         Broadcast       MAC Address       MTU     TSO MSS   Enabled Type     
vmk0       Management Network  IPv4     10.78.203.72 255.255.255.0   10.78.203.255   00:10:18:a7:76:88 1500    65535     true    STATIC #

#esxcfg-nics -l
Name    PCI           Driver      Link Speed     Duplex MAC Address       MTU    Description
vmnic0  0000:0b:00.00 bnx2        Up   1000Mbps  Full   00:10:18:a7:76:88 1500   Broadcom Corporation Broadcom NetXtreme II BCM5709 1000Base-T
vmnic1  0000:0b:00.01 bnx2        Up   1000Mbps  Full   00:10:18:a7:76:8a 1500   Broadcom Corporation Broadcom NetXtreme II BCM5709 1000Base-T
vmnic2  0000:0c:00.00 bnx2        Up   1000Mbps  Full   00:10:18:a7:76:8c 1500   Broadcom Corporation Broadcom NetXtreme II BCM5709 1000Base-T

# esxcfg-vswitch -l
Switch Name      Num Ports   Used Ports  Configured Ports  MTU     Uplinks
vSwitch0         128         3           128               1500    vmnic0
  PortGroup Name        VLAN ID  Used Ports  Uplinks
  VM Network            0        0           vmnic0
  Management Network    0        1           vmnic0

Switch Name      Num Ports   Used Ports  Configured Ports  MTU     Uplinks
vSwitch1         128         3           128               1500    vmnic1
  PortGroup Name        VLAN ID  Used Ports  Uplinks
  Ted Network           0        1           vmnic1
 # vsish -e get net/pNics/vmnic0/propertiesproperties {
   Driver Name:bnx2
   Driver Version:2.0.15g.v50.11-5vmw
   Driver Firmware Version:bc 5.2.3
   System Device Name:vmnic0
   Module Interface Used By The Driver:vmklinux
   Device Hardware Cap Supported:: 0x483c032b -> VMNET_CAP_SG VMNET_CAP_IP4_CSUM VMNET_CAP_HIGH_DMA VMNET_CAP_TSO VMNET_CAP_HW_TX_VLAN VMNET_CAP_HW_RX_VLAN VMNET_CAP_SG_SPAN_PAGES VMNET_CAP_IPV6_CSUM VMNET_CAP_TSO6 VMNET_CAP_TSO256k VMNET_CAP_OFFLOAD_16OFFSET VMNET_CAP_SCHED
   Device Hardware Cap Activated:: 0x83c032b -> VMNET_CAP_SG VMNET_CAP_IP4_CSUM VMNET_CAP_HIGH_DMA VMNET_CAP_TSO VMNET_CAP_HW_TX_VLAN VMNET_CAP_HW_RX_VLAN VMNET_CAP_SG_SPAN_PAGES VMNET_CAP_IPV6_CSUM VMNET_CAP_TSO6 VMNET_CAP_TSO256k VMNET_CAP_OFFLOAD_16OFFSET
   Device Software Cap Activated:: 0x34800000 -> VMNET_CAP_RDONLY_INETHDRS VMNET_CAP_OFFLOAD_8OFFSET
   PCI Bus:11
   PCI Slot:0
   PCI Fn:0
   PCI Vendor:0x14e4
   PCI Device ID:0x1639
   Interrupt Vector:0xc0
   Link Up:1
   Speed (Mb/s):1000
   Full Duplex:1
   Uplink Port ID:0x01000002
   Flags:: 0x1a0e -> DEVICE_PRESENT DEVICE_OPENED DEVICE_EVENT_NOTIFIED DEVICE_SCHED_CONNECTED DEVICE_RESPOOLS_SCHED_ALLOWED DEVICE_RESPOOLS_SCHED_SUPPORTED
   Network Hint:0 10.78.203.128/255.255.255.128
   MAC address:00:10:18:a7:76:88
   VLanHwTxAccel:1
   VLanHwRxAccel:1
   Queue Stopped:8
   Pseudo Device:0
   Respools sched allowed:1
   Respools sched supported:1
To view the ESXi host console interface
#dcui
1.      To power on a virtual machine from the command line:#vim-cmd vmsvc/getallvms
/sbin # vim-cmd vmsvc/getallvms
Vmid   Name          File             Guest OS      Version   Annotation
2      VM2    [nfs] VM2_1/VM2.vmx   winXPProGuest   vmx-08
4      VM1    [nfs] VM1/VM1.vmx     winXPProGuest   vmx-08
#vim-cmd vmsvc/getallvms | grep VM1
Vmid   Name          File             Guest OS      Version   Annotation
4      VM1    [nfs] VM1/VM1.vmx     winXPProGuest   vmx-08
Note: The first column of the output shows the vmid.
2.      Check the power state of the virtual machine with the command:#vim-cmd vmsvc/power.getstate <vmid>
    #  vim-cmd vmsvc/power.getstate 4
      Retrieved runtime info
Powered off
  1. Power-on the virtual machine with the command:vim-cmd vmsvc/power.on <vmid>
#  vim-cmd vmsvc/power.on 4
Powering on VM:
 #  vim-cmd vmsvc/power.getstate 4
Retrieved runtime info
Powered on

ESXi 4.1
To power on a virtual machine from the command line:
  1. List the inventory ID of the virtual machine with the command:vim-cmd vmsvc/getallvms |grep <vm name>
    Note: The first column of the output shows the vmid.
  2. Check the power state of the virtual machine with the command:vim-cmd vmsvc/power.getstate <vmid>
  3. Power-on the virtual machine with the command:vim-cmd vmsvc/power.on <vmid>
To view the vms guest os
#  vim-cmd vmsvc/get.guest 4
Guest information:

(vim.vm.GuestInfo) {
   dynamicType = <unset>,
   toolsStatus = "toolsOk",
   toolsVersionStatus = "guestToolsCurrent",
   toolsVersionStatus2 = "guestToolsCurrent",
   toolsRunningStatus = "guestToolsRunning",
   toolsVersion = "8384",
   guestId = "winXPProGuest",
   guestFamily = "windowsGuest",
   guestFullName = "Microsoft Windows XP Professional (32-bit)",
   hostName = "ciscovm1",
   ipAddress = "169.254.44.229",
   net = (vim.vm.GuestInfo.NicInfo) [
      (vim.vm.GuestInfo.NicInfo) {
         dynamicType = <unset>,
         network = "VM Network",
         ipAddress = (string) [
            "169.254.44.229"
         ],
         macAddress = "00:50:56:a7:34:5c",
         connected = true,
         deviceConfigId = 4001,
         dnsConfig = (vim.net.DnsConfigInfo) {
            dynamicType = <unset>,
            dhcp = false,
            hostName = "",
            domainName = "",
         },
         ipConfig = (vim.net.IpConfigInfo) {
            dynamicType = <unset>,
            ipAddress = (vim.net.IpConfigInfo.IpAddress) [
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  ipAddress = "169.254.44.229",
                  prefixLength = 16,
                  origin = "random",
                  state = "preferred",
                  lifetime = <unset>,
               }
            ],
            dhcp = (vim.net.DhcpConfigInfo) null,
            autoConfigurationEnabled = <unset>,
         },
         netBIOSConfig = (vim.net.NetBIOSConfigInfo) null,
      },
      (vim.vm.GuestInfo.NicInfo) {
         dynamicType = <unset>,
         network = "VM Network",
         ipAddress = (string) [
            "169.254.7.162"
         ],
         macAddress = "00:0c:29:61:59:32",
         connected = true,
         deviceConfigId = 4000,
         dnsConfig = (vim.net.DnsConfigInfo) {
            dynamicType = <unset>,
            dhcp = false,
            hostName = "",
            domainName = "",
         },
         ipConfig = (vim.net.IpConfigInfo) {
            dynamicType = <unset>,
            ipAddress = (vim.net.IpConfigInfo.IpAddress) [
               (vim.net.IpConfigInfo.IpAddress) {
                  dynamicType = <unset>,
                  ipAddress = "169.254.7.162",
                  prefixLength = 16,
                  origin = "random",
                  state = "preferred",
                  lifetime = <unset>,
               }
            ],
            dhcp = (vim.net.DhcpConfigInfo) null,
            autoConfigurationEnabled = <unset>,
         },
         netBIOSConfig = (vim.net.NetBIOSConfigInfo) null,
      }
   ],
   ipStack = (vim.vm.GuestInfo.StackInfo) [
      (vim.vm.GuestInfo.StackInfo) {
         dynamicType = <unset>,
         dnsConfig = (vim.net.DnsConfigInfo) null,
         ipRouteConfig = (vim.net.IpRouteConfigInfo) {
            dynamicType = <unset>,
            ipRoute = (vim.net.IpRouteConfigInfo.IpRoute) [
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "169.254.0.0",
                  prefixLength = 16,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.44.229",
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "169.254.0.0",
                  prefixLength = 16,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.7.162",
                     device = "1",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "169.254.255.255",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.44.229",
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "169.254.255.255",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.7.162",
                     device = "1",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "224.0.0.0",
                  prefixLength = 4,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.44.229",
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "224.0.0.0",
                  prefixLength = 4,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.7.162",
                     device = "1",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "255.255.255.255",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.44.229",
                     device = "0",
                  },
               },
               (vim.net.IpRouteConfigInfo.IpRoute) {
                  dynamicType = <unset>,
                  network = "255.255.255.255",
                  prefixLength = 32,
                  gateway = (vim.net.IpRouteConfigInfo.Gateway) {
                     dynamicType = <unset>,
                     ipAddress = "169.254.7.162",
                     device = "1",
                  },
               }
            ],
         },
         dhcpConfig = (vim.net.DhcpConfigInfo) null,
      }
   ],
   disk = (vim.vm.GuestInfo.DiskInfo) [
      (vim.vm.GuestInfo.DiskInfo) {
         dynamicType = <unset>,
         diskPath = "C:\",
         capacity = 10725732352,
         freeSpace = 7530975232,
      }
   ],
   screen = (vim.vm.GuestInfo.ScreenInfo) {
      dynamicType = <unset>,
      width = 640,
      height = 480,
   },
   guestState = "running",
   powerPolicy = (vim.vm.PowerPolicy) null,
   appHeartbeatStatus = "appStatusGray",
   guestOperationsReady = true,
   interactiveGuestOperationsReady = false,
}