BOULA73
Enthusiast
Enthusiast

How to umount cd drive after cloudinit completed

Jump to solution

Hi everybody,

In vRA after the deployment with cloudinit or cloudbase-init is completed the cdrom stay mounted with a ISO.

You can unmounted the CDROM by the OS but if you power-off and start the VM the ISO is mounted again by vRA.

How can unmounted definitely the ISO ?

the only solution for me is to delete cd rom object of the VM maybe with a vRO Workflow

Thanks

Labels (2)
0 Kudos
1 Solution

Accepted Solutions
caduncan
Enthusiast
Enthusiast

Hello,

Not sure this helps, but we chose to delete the CDROM. In part to remove the iso, and in part our security standards require that VMs don't have CDROMs. I used an ABX action with a subscription that runs "Compute post provision" . Sample of code below. You have power down, hence the sleep commands to ensure the correct state. However, you could check for power state too, I am sure.

# Checking for CDROM and removing if it exists.
$cd = Get-CDDrive -VM $vmname
if ($cd -ne $Null) {
    Write-Host "Shutting down and removing CDROM from $($vmname)"
    Stop-VMGuest -VM $vmname -confirm:$false
    Start-Sleep -s 60
    Write-Host "Removing CDROM from $($vmname)"
    Remove-CDDrive -CD $cd -confirm:$false
    Write-Host "CDROM removed from $($vmname)"
    Start-Sleep -s 30
    Write-Host "Starting $($vmname)"
    Start-VM $vmname
    Start-Sleep -s 30
    Write-Host "CDROM removed from VM."
}

View solution in original post

14 Replies
caduncan
Enthusiast
Enthusiast

Hello,

Not sure this helps, but we chose to delete the CDROM. In part to remove the iso, and in part our security standards require that VMs don't have CDROMs. I used an ABX action with a subscription that runs "Compute post provision" . Sample of code below. You have power down, hence the sleep commands to ensure the correct state. However, you could check for power state too, I am sure.

# Checking for CDROM and removing if it exists.
$cd = Get-CDDrive -VM $vmname
if ($cd -ne $Null) {
    Write-Host "Shutting down and removing CDROM from $($vmname)"
    Stop-VMGuest -VM $vmname -confirm:$false
    Start-Sleep -s 60
    Write-Host "Removing CDROM from $($vmname)"
    Remove-CDDrive -CD $cd -confirm:$false
    Write-Host "CDROM removed from $($vmname)"
    Start-Sleep -s 30
    Write-Host "Starting $($vmname)"
    Start-VM $vmname
    Start-Sleep -s 30
    Write-Host "CDROM removed from VM."
}
BOULA73
Enthusiast
Enthusiast

That work perfectly with ABX action

thank you so much

 

0 Kudos
caduncan
Enthusiast
Enthusiast

Great! I am glad to help!

0 Kudos
velezr
Contributor
Contributor

We are trying to find a solution for this but it doesn't matter what we try it seems the ISO is coming back mounted every time the VM powers off and powers back on.  If we remove the CD ROM like this and we want to use the CD ROM again later adding a new one it will be back with the ISO mounted.  If we try to disconnect the CD ROM it will be OK until power off and power on, ISO mounted again.  We also tried removing that ISO from the datastore but the ISO disappears when the VM is off. 

0 Kudos
luisdavidhu
Contributor
Contributor

Hi!

I'm using the same code, but I'm still getting the error atach. Any ideas?

Thank you 

0 Kudos
caduncan
Enthusiast
Enthusiast

Hi,

I see in your attached image you ran this as a test, yes? I would suggest deploy a test VM. I find that running an ABX test doesn't always work because there is at time no data (hence the null error). If you still get the error, please post an image or output from the logs.

 

Thank you,

0 Kudos
ronaldod
Enthusiast
Enthusiast

Why do you use the cd drive ?

For the cloudinit meta data ?

You can send that with a few tweaks directly to cloudinit.

 

0 Kudos
caduncan
Enthusiast
Enthusiast

Hi Ronaldod,

yes, per VMware documentation anyway, you need the CDROM to mount an ova file created by vRA. What other options have you used? I would be very interested to know.

 

Thank you,

 

0 Kudos
ronaldod
Enthusiast
Enthusiast

Global howto not done to the details but i think you will get there.

I did a tweak based on a popular one but that only handles the user data.

https://blog.v12n.io/cloud-init-with-vrealize-automation-and-vsphere-no-cd-drive/ 

It refers that you need install a script to activate guestinfo.userdata. But in the latest release of cloud-init( 21.3) it is already there just need to enable it in the cloud config. And disable vmware customisation. Not sure but the Linux OS admins checked that for me.

In the link above is also a workflow but that needs some editing.

That workflow you link to the event  poweron vm.

In the workflow it pushes also the meta data to the vm at poweron time.

Fix is of course make a second variable in the yaml file with just the network config. This one is needs a "|" and the #cloud-config. Else it will json serialize that and ignore the #cloud-config. That will give you multipart errors.

The variable with the meta data you base64encode and put it in the meta variable.

And with this you do not use a cd-rom for configuring network or send commands.

 

ronaldod
Enthusiast
Enthusiast

--double--

0 Kudos
caduncan
Enthusiast
Enthusiast

Thank you for the information. I will put it to a test when my schedule allows.

0 Kudos
AlexNTTA
Contributor
Contributor

I ran into this problem as well. I created a powershell ABX that would find the VM and change it back to "Client" :

 

function handler($context, $inputs) {
  $vmname = $inputs.resourceNames[0]
  Connect-VIServer -Server VCENTER.MYDOMAIN.COM -User USER -Password PASSWORD -Protocol https -Force
  get-vm $vmname | Get-CDDrive| Set-CDDrive -NoMedia -Confirm:$false
  Disconnect-VIServer VCENTER.MYDOMAIN.COM -Confirm:$false
}

 

This works fine, but I found that if someone updates the deployment (for example, to change the network and have a new IP assigned), vRA will heed the original cloud template and mount an ISO to the VM for cloud-init.

First, I'd like to control when cloud-init is initiated (I only use it on first run). Second, I'd like to run an ABX to fix the CDROM again, however, I'm not sure how. Maybe run the ABX action on a "Deployment resource completed" subscription? This does not provide the VM name as far as I know.

0 Kudos
ronaldod
Enthusiast
Enthusiast

As soon you have it working you will never want that CD support again. Just it is a such undocumented option. No idea why vmWare have their docs not updated for this.

0 Kudos
AlexNTTA
Contributor
Contributor

If you remove the CD-ROM and vRA tries to update the VM via an update of the deployment where you change the network, I believe it will fail. I can experiment...

EDIT - I just tried it. When updating the network via "Update" of a deployment, it goes through a typical customization spec, and gets a new IP on there. No reinstall (as expected), and no errors! I guess I'm going with CD-ROM removal with my ABX instead of changing to Client.

0 Kudos