Upgrade raspberry pi on fly

This article is for the new users whom just like me! 🙂
I got a Raspberry Pi about half years ago, I’m pretty new in Linux world, so I rebuilt my pi over and over again whenever there was a new release…it takes lot of time to do it.
Thanks Safari(a online library for IT guys). Today I found a new way to do it on fly! Just run following two commands it will upgrade system automatically.

#apt-get update
This command line updates the latest repository information.

#apt-get upgrade
It’s upgrade all older packages to latest version.

It may takes long time to complete upgrading, you’d better make sure the SSH alive during that time.

How to Delete a Pending Host from SCVMM 2012 R2

A Hyper-V host shows Pending status under VMs and Services section, the host invisible under Fabric section.

You may experience following symptoms when you re-add the Hyper-V host to SCVMM 2012 R2.

There were no computers discovered based on your inputs. Please verify the following:

  • Your Virtual Machine Manager Server service account has at least read access to the Active Directory domain you requested to discover.
  • Your Virtual Machine Manager Server has access to the computer in the discovery scope.
  • The servers you specified are powered on and running.
  • You specified valid credentials to access the servers.
  • The user account that you specified has Administrator privileges on the Windows servers to be discovered.
  • The servers you specified are already managed by Virtual Machine Manager.

You may see following error when you try to delete the Hyper-V host from SCVMM 2012 R2.

Error (2606)

Unable to perform the job because one or more of the selected objects are locked by another job.

Recommended Action

To find out which job is locking the object, in the Jobs view, group by Status, and find the running or canceling job for the object. When the job is complete, try again.

 

That’s because the Hyper-V host was not added to SCVMM 2012 R2 properly when you first time add it to SCVMM 2012 R2.

Variously reason lead to this issue. It cannot be fixed by restart 2012 R2 services, reboot Hyper-V host, reboot SCVMM 2012 R2 server or force delete by PowerShell command Remove-SCVMHost.

You have to manually delete the host record in SCVMM 2012 R2 SQL database.

HostID is unique ID correspond with each Hyper-V host in SCVMM 2012 R2 database, so basically we need to delete everything related to the target HostID.

The only article about that is How to manually remove a host from the VMM database, but it’s for VMM2008. If you take a look the tables of SCVMM 2012 R2 database, it’s more complicate. I would like to share how I did it. Since everybody may have different situation, I’m going to show you a generic way.

  1. Create a temp share folder on SQL database server. Grant READ/WRITE permission to EVERYONE.
  2. Launch SCVMM 2012 R2 console.
  3. Go to SettingsGeneralBackup.
  4. Enter the share path then click OK to backup SCVMM 2012 R2 database.
  5. Launch SQL Management Studio.
  6. Select SCVMM 2012 R2 database.
  7. Open table tbl_ADHC_Host and find out HostID of the target host.
  8. Right click the database and select New query.
  9. Run query below. (Replace ‘HostID’

    by real one)
    SELECT * FROM tbl_ADHC_Host WHERE (HostID = ‘HostID’)
  10. It returns the host records in tbl_ADHC_Host table.

You can run following query to try deleting basic information of the host. (Replace ‘HostID’
and @computername by real one)

DELETE FROM tbl_ADHC_HostNetworkAdapter WHERE (HostID = ‘HostID’)

DELETE FROM tbl_ADHC_VirtualNetwork WHERE (HostID = ‘HostID’)

DELETE FROM tbl_ADHC_HostVolume WHERE (HostID = ‘HostID’)

DELETE FROM tbl_ADHC_HostDisk WHERE (HostID = ‘HostID’)

DELETE FROM tbl_WLC_PhysicalObject WHERE (HostId = ‘HostID’)

DELETE FROM tbl_WLC_VObject WHERE (HostId = ‘HostID’)

DELETE FROM [tbl_ADHC_AgentServerRelation] WHERE AgentServerID = (select top 1 AgentServerID from tbl_ADHC_AgentServer where Computername = @computername)

DELETE FROM [tbl_ADHC_AgentServer] WHERE AgentServerID = (select top 1 AgentServerID from tbl_ADHC_AgentServer where Computername = @computername)

DELETE FROM tbl_ADHC_AgentServer WHERE (ComputerName = @computername)

DELETE FROM tbl_ADHC_ISCSIHbaToTargetMapping where ISCSIHbaID in (select HbaID from tbl_ADHC_HostBusAdapter where(HostID = ‘HostID’))

DELETE FROM tbl_ADHC_HostInternetSCSIHba where ISCSIHbaID in (select HbaID from tbl_ADHC_HostBusAdapter where(HostID = ‘HostID’))

DELETE FROM tbl_ADHC_HostBusAdapter where (HostID = ‘HostID’)

DELETE FROM tbl_ADHC_Host WHERE (HostID = ‘HostID’)

Since a Hyper-V host has lot of hardware, such as network adapter, HBA, virtual network, logical network, WWPN…etc. The query above may not able to delete all related information in database, it returns similar error below:

Msg 547, Level 16, State 0, Line 1

The DELETE statement conflicted with the REFERENCE constraint “fk__NetMan_LogicalNetworkDefinitionToHostGroup__ADHC_HostNetworkAdapter”. The conflict occurred in database “VirtualManagerDB”, table “dbo.tbl_NetMan_HostNetworkAdapterToLogicalNetwork”, column ‘HostNetworkAdapterID’.

Then you have to chase down related key from table NetMan_LogicalNetworkDefinitionToHostGroup and delete the related information first.

I’m not a DB expert, so I have to chase down the error message one by one and manually delete records from tables, you may have better idea. J

Finally DELETE FROM tbl_ADHC_Host WHERE (HostID = ‘HostID’) should be able to execute successfully, then restart SCVMM 2012 R2 service and login console. You will see the pending Hyper-V host disappeared.

****************************************************************************

Updated – 7/22/2014

A script can completely delete a host from SQL DB.

Please backup database before run it!!!!!

+++++++++++++++++++++++++++++++++++++++++++++++

USE VirtualManagerDB;                           // VirtualManagerDB is your database name.

DECLARE @DeleteHostId GUID;

SET @DeleteHostId = ‘<HostID>’            //HostID is the one you want to delete.

PRINT N’Deleting host with GUID ‘ + RTRIM(CAST(@DeleteHostID AS nvarchar(50)))

PRINT N’Getting host cluster GUID’

DECLARE @HostClusterID GUID;

SET @HostClusterID =

(

SELECT HostClusterID FROM [dbo].[tbl_ADHC_Host]

WHERE HostID = @DeleteHostId

)

IF (@HostClusterID IS NOT NULL)

PRINT N’Retreived host cluster GUID ‘ + RTRIM(CAST(@HostClusterID AS nvarchar(50)))

ELSE

PRINT N’This host does not belong to a cluster’

PRINT N’Deleteing physical objects’

DELETE FROM [dbo].[tbl_WLC_PhysicalObject]

WHERE HostId = @DeleteHostId

PRINT N’Deleteing virtual objects’

DELETE FROM [dbo].[tbl_WLC_VObject]

WHERE HostId = @DeleteHostId

PRINT N’Prepairing to delete host network adapters’

DECLARE @HostNetworkAdapterCursor CURSOR;

DECLARE @HostNetworkAdapterID GUID;

SET @HostNetworkAdapterCursor = CURSOR FOR

(SELECT NetworkAdapterID FROM [dbo].[tbl_ADHC_HostNetworkAdapter])

OPEN @HostNetworkAdapterCursor

FETCH NEXT FROM @HostNetworkAdapterCursor INTO @HostNetworkAdapterID

WHILE (@@FETCH_STATUS = 0)

BEGIN

PRINT N’Prepairing to delete host network adapter with GUID ‘ + RTRIM(CAST(@HostNetworkAdapterID AS nvarchar(50)))

PRINT N’Deleting logical network mapping for host network adapter with GUID ‘ + RTRIM(CAST(@HostNetworkAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_NetMan_HostNetworkAdapterToLogicalNetwork]

WHERE HostNetworkAdapterID = @HostNetworkAdapterID

PRINT N’Deleting IP subnet VLAN mapping for host network adapter with GUID ‘ + RTRIM(CAST(@HostNetworkAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_NetMan_HostNetworkAdapterToIPSubnetVLan]

WHERE HostNetworkAdapterID = @HostNetworkAdapterID

FETCH NEXT FROM @HostNetworkAdapterCursor INTO @HostNetworkAdapterID

END

CLOSE @HostNetworkAdapterCursor

DEALLOCATE @HostNetworkAdapterCursor

PRINT N’Completing host network adapters deletion’

DELETE FROM [dbo].[tbl_ADHC_HostNetworkAdapter]

WHERE HostID = @DeleteHostId

PRINT N’Deleting virtual networks’

DELETE FROM [dbo].[tbl_ADHC_VirtualNetwork]

WHERE HostID = @DeleteHostId

PRINT N’Deleting virtual switch extensions’

DELETE FROM [dbo].[tbl_NetMan_InstalledVirtualSwitchExtension]

WHERE HostID = @DeleteHostId

PRINT N’Deleting host volumes’

DELETE FROM [dbo].[tbl_ADHC_HostVolume]

WHERE HostID = @DeleteHostId

PRINT N’Deleting pass through disks’

DELETE FROM [dbo].[tbl_WLC_VDrive]

WHERE HostDiskId IN (SELECT DiskID FROM [dbo].[tbl_ADHC_HostDisk] WHERE HostID IN (SELECT HostID FROM [dbo].[tbl_ADHC_Host] WHERE HostID = @DeleteHostId))

PRINT N’Deleting host disks’

DELETE FROM [dbo].[tbl_ADHC_HostDisk]

WHERE HostID = @DeleteHostId

PRINT N’Prepairing to delete host bus adapters’

DECLARE @HostBusAdapterCursor CURSOR;

DECLARE @HostBusAdapterID GUID;

SET @HostBusAdapterCursor = CURSOR FOR

(SELECT HbaID FROM [dbo].[tbl_ADHC_HostBusAdapter])

OPEN @HostBusAdapterCursor

FETCH NEXT FROM @HostBusAdapterCursor INTO @HostBusAdapterID

WHILE (@@FETCH_STATUS = 0)

BEGIN

PRINT N’Prepairing to delete host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

PRINT N’Deleting fiber port mapping for host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DECLARE @FiberPortID GUID;

SET @FiberPortID =

(

SELECT PortID FROM [dbo].[tbl_ADHC_FCHbaToFibrePortMapping]

WHERE FCHbaID = @HostBusAdapterID

)

DELETE FROM [dbo].[tbl_ADHC_FCHbaToFibrePortMapping]

WHERE FCHbaID = @HostBusAdapterID

PRINT N’Deleting fiber port with GUID ‘ + RTRIM(CAST(@FiberPortID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_FibrePort]

WHERE PortID = @FiberPortID

PRINT N’Deleting fiber channel mapping for host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_HostFibreChannelHba]

WHERE FCHbaID = @HostBusAdapterID

PRINT N’Deleting any iSCSI entries for host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DECLARE @iSCSITargets TABLE

(

TargetID GUID

)

INSERT INTO @iSCSITargets (TargetID)

SELECT TargetID FROM [dbo].[tbl_ADHC_ISCSIHbaToTargetMapping]

WHERE ISCSIHbaID = @HostBusAdapterID

PRINT N’Deleting iSCSI host bus adapter to target mapping for mapping for host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

PRINT N’Deleting iSCSI host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_ISCSIHbaToPortalMapping]

WHERE ISCSIHbaID = @HostBusAdapterID 

DELETE FROM [dbo].[tbl_ADHC_ISCSIHbaToTargetMapping]

WHERE ISCSIHbaID = @HostBusAdapterID 

DELETE FROM [dbo].[tbl_ADHC_HostInternetSCSIHba]

WHERE ISCSIHbaID = @HostBusAdapterID

PRINT N’Deleting iSCSI targets for host bus adapter with GUID ‘ + RTRIM(CAST(@HostBusAdapterID AS nvarchar(50)))

DECLARE @iSCSITargetIDCursor CURSOR;

DECLARE @iSCSITargetID GUID;

SET @iSCSITargetIDCursor = CURSOR FOR

(SELECT TargetID FROM @iSCSITargets)

OPEN @iSCSITargetIDCursor

FETCH NEXT FROM @iSCSITargetIDCursor INTO @iSCSITargetID

WHILE (@@FETCH_STATUS = 0)

BEGIN

PRINT N’Deleting iSCSI targets with GUID ‘ + RTRIM(CAST(@iSCSITargetID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_ISCSIHbaToTargetMapping]

WHERE TargetID = @iSCSITargetID

DELETE FROM [dbo].[tbl_ADHC_ISCSITarget]

WHERE TargetID = @iSCSITargetID

FETCH NEXT FROM @iSCSITargetIDCursor INTO @iSCSITargetID

END

CLOSE @iSCSITargetIDCursor

DEALLOCATE @iSCSITargetIDCursor

FETCH NEXT FROM @HostBusAdapterCursor INTO @HostBusAdapterID

END

CLOSE @HostBusAdapterCursor

DEALLOCATE @HostBusAdapterCursor

PRINT N’Completing host bus adapters deletion’

DELETE FROM [dbo].[tbl_ADHC_HostBusAdapter]

WHERE HostID = @DeleteHostId

PRINT N’Prepairing to delete agent servers’

DECLARE @AgentServerID  GUID;

SET @AgentServerID =

(

SELECT AgentServerID FROM [dbo].[tbl_ADHC_AgentServerRelation]

WHERE HostLibraryServerID = @DeleteHostID

)

PRINT N’Deleting agent server relations’

DELETE FROM [dbo].[tbl_ADHC_AgentServerRelation]

WHERE HostLibraryServerID = @DeleteHostID

PRINT N’Deleting health monitor data for agent server with GUID ‘ + RTRIM(CAST(@AgentServerID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_HealthMonitor]

WHERE AgentServerID = @AgentServerID

PRINT N’Deleting agent server with GUID ‘ + RTRIM(CAST(@AgentServerID AS nvarchar(50)))

DELETE FROM [dbo].[tbl_ADHC_AgentServer]

WHERE AgentServerID = @AgentServerID

PRINT N’Deleting host GPUs’

DELETE FROM [dbo].[tbl_ADHC_HostGPU]

WHERE HostID = @DeleteHostId

PRINT N’Deleting host’

DELETE FROM [dbo].[tbl_ADHC_Host]

WHERE HostID = @DeleteHostId

IF (@HostClusterID IS NOT NULL)

BEGIN

PRINT N’Checking to see if any other hosts are joined to the same cluster’

DECLARE @HostCount INT;

SET @HostCount =

(

SELECT COUNT(*) FROM [dbo].[tbl_ADHC_Host]

WHERE HostClusterID = @HostClusterID

)

PRINT N’There are ‘ + RTRIM(CAST(@HostCount AS nvarchar(50))) + N’ currently joined to the same cluster’

IF (@HostCount = 0)

BEGIN

PRINT N’Deleting cluster disks’

DELETE FROM [dbo].[tbl_ADHC_ClusterDisk]

WHERE ClusterID = @HostClusterID

PRINT N’Deleting cluster’

DELETE FROM [dbo].[tbl_ADHC_HostCluster]

WHERE ClusterID = @HostClusterID

END

ELSE

PRINT N’This host is not the last host in the cluster, the cluster will be deleted upon the deletion of the last host.’

END

ELSE

PRINT N’This host does not belong to a cluster, no clusters will be deleted’

GO

 

PortChannel does not work on Cisco UCS Fabric Interconnect

Whatever  you configure on MDS, whatever you configure on Cisco UCS FIs, whatever you do for port channel on both side, the Cisco UCS uplink ports always down with error message Initilize failed, or Error disabled.

Congratulation! your device hit MDS firmware bug…https://tools.cisco.com/bugsearch/bug/CSCtr01652/?reffering_site=dumpcr.

 

Domain account locked out on vCenter Server

That’s a very small problem but it struggles you if you are enterprise datacenter administrator. As you may know the best practices to run application is by service account. But sometimes  you may testing applications by your own domain account and forget remove it.

Few days ago, my domain account locked out on domain controller. The audit report indicated it locked out by vCenter Server every 5 seconds. Then I logged in the vCenter Server, checked out Task SchedulerServicesTask Manager…etc. Nothing was running under my domain account. I stopped applications one by one on the vCenter Server and related plugin services. No help, I felt so frustrated!!!

Here is how I figured it out eventually.

  1. Download TCPView from Microsoft website.
  2. Run it on the vCenter Server.
  3. Sort by Local Address.
  4. See which foreign address is connecting the vCenter Server.

After the steps above I finally figured out that root cause was my VMware View LAB VM tried to authenticate on vCenter Server by my domain account and stored old password. I powered up the old VM few days ago.

这可能是一个很小的问题,但如果你是企业级数据中心管理员,这个问题可能会很困扰你。如你所知在日常使用中最好用Service Account来运行应用程序。但是有时候你可能和我一样需要用自己的域帐号做一些测试但之后又忘记删除了。

几天前,我的域帐号被域控制器锁定了。域报告显示我的帐号每5秒钟就会被vCenter服务器锁定一次。我在vCenter服务器上检查了任务管理器、服务、计划任务等等,并没有发现任何东西使用我的帐号。然后我将vCenter服务器上的所有服务、应用程序都停了,还是不行!

最终我找到了问题原因,以下是方法:

  1. 从微软网站下载TCPView
  2. 在vCenter服务器上运行。
  3. 选择以Local Address本地地址)排序。
  4. 查看连接到vCenter服务器的Foreign Address外部地址)。

最终原因是我几天前把一台旧的VM开机了,这台VM上是当时以我的域帐号安装的VMware View做测试用。

Extremely slow when run PowerShell script by scheduled taks

I like automition/programming as much as I like Windows, my first offical training in University was VB, then I learned PHP and HTML after graduated. I can’t believe my first PHP program was welcomed in internel. But I stopped develop the skill.

I got lot of special request for virtual environment. Some people want to monitor snapshot, some want to check space status, and some request to create backup for VM…etc. Regular operation cannot satisify the requests, most of the requests are time consuming operation. Automation can save my ass. 🙂

You may know PowerCLI – VMware automation product for PowerShell. If you put PowerCLI scripts as scheduled task, you will be able to do any workflow you want by schedule.

But there is a problem stuggled me for a long time. The scheduled PowerCLI script is instable, sometimes script ran very well, sometimes script ran extremely slow, sometimes script hung, or sometimes script unexpected stopped. In troubelshooting I noticed it need a long waiting time (maybe  5 – 10 mintues) till execute first line of script when I ran it on Scheduled Task Window. Initially I thought it’s a bug of PowerShell 2.0. I upgraded to 3.0 but no lucky. I also suspected loading PowerCLI Snap-in may slow down the script exectue time, or bugs on PowerCLI components, tried to google but nothing was found.

Finally my colleague Amnon gave my some idea, he asked me change the scheduled taks priority. I figured out the trick after did some testing:

  1. Create a task as usual.
  2. Export the taks to a xml file.
  3. Open the xml file by editor.
  4. Search keyword priority.
  5. Change the default value 7 to 3. ( More detail about priority of Scheduled Task )
  6. Save the xml file and delete created task.
  7. Import the xml as a task.

It signaficantly improved the executive time! Same script was 2 hours, now only 10 minutes!

Here is my another post ($array.count does not show anything in PowerCLI) regarding a bug of PowerShell, it may helpful for your PowerCLI script.

$array.count does not show anything in PowerCLI

I developed a script to take snapshot on VM and delete older snapshot regularly. I  used  variable $snapshots to receive data from Get-Snapshot command, then determine how many existing snapshots according to return of $snapshots.count. Somehow the script always ran incorrect behavior. When I deep looked into $snapshots, I found a interesting things.

Computer A, $snapshots.count return nothing if no, or one snapshot received.

Computer B, $snapshots.count returned 0 if no, or returned 1 if one snapshots received.

Then I checked out $PSVersionTable, found computer A powershell version is 2.0, B is 3.0, looks like this is a bug in 2.0.

The issue got fixed after upgrade to 3.0, one more benefit is I got performance improve to load PowerCLI components after upgrading.

You could install Widnows Management Framework 3.0 to upgrade PowerShell. I tested it on PowerCLI 5.5 Update1.

Device or Resource Busy

You may read my post How to find which ESXi 5.1 host lock the VM, it’s a solution to figure out which host lock down a file.

But sometimes you may face similar problem but different solution.

You are able to browse the file by CLI or GUI, but cannot delete by either way. It returns you device or resource busy or similar error messages.

You could try following command to delete the file/folders:

rm [File or folder name] -rf

Virtual Machine Disappeared on vCenter Inventory

Just googled this issue, some of people got similar problem, following was my problem and solution, hope it’s useful for you.

Virtual machine maybe lost on vCenter Server inventory for some reason, it’s also disappeared on ESXi inventory when you connect to the individual host directly. You are able to find the VM process by esxcli vm process list, but not able to get it by vim-cmd vmsvc/getallvms.

If you try load the VM manually by commeand vim-cmd vmsvc/reload [vmid], it back you error:

(vim.fault.NotFound) {
dynamicType = <unset>,
faultCause = (vmodl.MethodFault) null,
msg = “Unable to find a VM corresponding to “vmid””,
}

You can also find the VM process by esxtop command.

My solution was remove the ESXi host from vCenter Server, then restart management services, and then browse the VM folder, add the VM back to inventory, then join the host back to vCenter Server.

 

How to get HBA WWPN of ESXi hosts

It’s busy month, I haven’t update my blog since I back from Phuket with my wife. I’m running into multiple projects, a little overload.

Just a quick share, my storage team ask me provide WWPN of all hosts to do a health check. it’s nightmare to pull out the data from vSphere client or web client. Just found a way to get it.

Get-VMHost -Location | Get-VMHostHBA -type fibrechannel | select VMHost,Device,@{N=”WWPN”;E={“{0:X}” -f $_.PortWorldWideName}}

Especially “{0:X}” -f $_.PortWorldWideName}

{0:X} is format, check out here  to find more.

-f is kind of pipeline.

$_.PortWorldWideName is the value you want to convert.

 

Receive Side Scaling on UCS Blades

To implement enterprise application like SAP, Oracle or SQL on UCS virtualization environment. Default setting of UCS blades may not suitable for the application. We always expect highest performance by optimize hardware and ESXi. In my UCS training session, I noticed one “hidden” parameter may helpful for performance.

Receive Side Scaling – So called RSS, it’s a feature that allows you to utilize multiple CPUs and multiple cores per CPU to process the receiving network load. Without RSS, all of the receive network traffic is processed by one CPU and by only one core of the CPU. Essentially, RSS distributes receiving network load to all of the CPUs and their cores.

The parameter is an option in BIOS, but it’s not under BIOS policy in UCS Manager. You should go to Servers tab, extend Policies node, and check an Eth Adapter Policy under Adapter Policy node, Receive Side Scaling (RSS) is available in Options section of right frame. Blade should be rebooted to leverage the option.

Please keep in mind that do not enable RSS if your adapters more than your CPUs, it will cause unexpected network transmit failed. RSS option must be enabled on UCS policy before enable it on OS layer (I confirmed with Cisco TAC, is that true?). Regarding OS layer, please refer to those articles.

Receive side scaling on Intel® Network Adapters

How to enable Receive Side Scaling on Microsoft Windows Server 2008 R2

You don’t have to enable the option if network traffic is not a concern.