Jump to content

Recommended Posts

Posted

Apologies for what is probably a basic question, but my limited access to the machine in common means that I need a high chance of getting it right first time.

 

I wish to ensure that a virtual disk is mounted automatically on system startup.

 

The virtual disk is on an external USB drive and will be used for Microsoft backup purposes. Performance is adequate when manually mounted.

 

As the server mounting this drive is a Hyper-V server, it does not have USB access, so the virtual disk is also accessed via a file share.

 

We need to use this method as to allow Microsoft backup on the virtual machine to use incremental backups, it needs to have a whole disc available and not just a partition.

 

Thanks

 

Ian

Posted (edited)

If you kept it mounted using MagicDisc it holds it mounted after reboot - I use it myself on my home servers (and it's freeware).

 

Re-read, now I see what you mean... but, you can connect to a 'local device' on the machine and it creates one of those... if you see what I'm getting at?

Edited by dwhyte85
  • 1 month later...
Posted

I have setup two files which perform what I intend, but I cannot get these to run when using the server scheduler functionality.

 

I created a folder on the C drive called startup. This has full control, mod, r/e, r, w, list permissions for system and administrator and r/e,r for leo\users. Likewise, the following two files have the same:

 

attach_vhd.cmd

diskpart /s c:\startup\attach_vhd.txt

 

attach_vhd.txt

select vdisk file="\\griffin\daily backups\leo-backup.vhd"
attach vdisk

 

The server that I wish to mount this on is called 'LEO' and the server where the vhd is on is 'griffin'. Leo is a virtual machine, griffin is its host. 'Daily backups' is an external USB disc hosted on griffin and not directly accessible from leo, other than through a share.

 

When I run attach.cmd directly, the disc mounts fine, but when I setup a scheduled task from the windows scheduler to run 'when the computer starts', it does not work, even if I run it now. I'm not sure where to look for any errors - could not see any in the event log.

 

The scheduled task is set to run as administrator, whether or not the user is logged in or not. The admin password is set at time scheduled task is created. There are a couple of other options which I have tried the obvious.

 

The command just sees to be always running in the scheduler until I stop and disable it.

 

Thanks

 

Ian

Posted
Why not just mount the vhd as another HDD in HyperV?

To be honest, until you had said about a second VHD being mounted in hyper-V, I had not realised that it could be done. However, after giving it more thought...

 

I don't think that a hyper-v machine will start if a virtual disc is missing, so because the external disc is on a removerable USB drive this may occur for a number of reasons.

 

Also, I would rather have the flexibility to mount and dismount the disk while the virtual machine is running. If the disc is mounted on the fly, I believe that it would be simpler to detach and attach another, if it was attached outside hyper-V in the first place.

Posted

Hi Ian,

 

I don't use HyperV myself so I'm only drawing on my ESX knowledge. Could you perhaps mount the drive using PowerShell once the machine has booted?

i.e. PseudoCode (bears no resemblance to real HyperV commands because I don't know them):

$vm = Get-VM "Server1"
if ($vm.PowerState -eq "Running") {
   if (Test-Path "F:\DiskToattach.vhd") {
       $vm.MountDisk("F:\DiskToAttach.vhd")
   }
}

Theoretically you'd go:

Is the machine on? (Yes). Is the vhd path accessible? (Yes). Mount the VHD.

 

After Google: PowerShell Management Library for Hyper-V

 

 

After re-reading this it makes little sense, so I'm really just spitballing. Home this helps in some way and doesn't just confuse you like it did me.

  • Thanks 1
Posted

Hi Chris

 

Thanks for your help. The code that I have above does actually work, but only if I manually run attach_vhd.cmd. The problem that I have is getting it to run on system boot or manually from the windows scheduler. I may then modify it to detect if disc is unmounted so that I can run it automatically just before the backup kicks off.

 

-Ian

Posted

Chris

 

That is exactly what I am using, but for whatever reason, it does not execute when invoked from the scheduler, either at startup, or manually triggered. It constantly goes into the running state until it is pre-empted and cancelled.

 

I cannot see anything obvious log wise to see why it is not running. Not sure if/where the scheduler puts any log files.

Posted

The Scheduler will dump into your event viewer, you can see this on the "History" tab in Task Scheduler. If you're using PowerShell to do this, I'd recommend throwing this command at the start of your script, it will log everything out to file:

 

Start-Transcript C:\mylog.txt

Posted
I don't think that a Hyper-V machine will start if a virtual disk is missing, so because the external disk is on a removable USB drive this may occur for a number of reasons.

Would it not be a lot easier to store the VHD you backup to on your host (or SAN), permanently mount it within the guest (Leo) and then robocopy the files which are created/modified by Windows Server Backup over the network to a folder on the USB HDD connected to the host (Griffin)? This way, you don't have to mess around with attaching and detaching VHDs?

 

When I run attach.cmd directly, the disk mounts fine, but when I setup a scheduled task from the windows scheduler to run 'when the computer starts', it does not work, even if I run it now. I'm not sure where to look for any errors - could not see any in the event log.

When the scheduled task runs the diskpart script, perhaps the volume inside the VHD is off-line and read-only? :confused:

 

In fact when Hyper-V mounts the disk it doesn’t bring it on-line and flags it read only, so the PowerShell code I wrote not only had to call the WMI functions provided by Hyper-V's Image Management Service, but it also needed to invoke DiskPart.exe with a script to get the disk to a useful state. (Source)
Posted

I know this of no help what's so ever!

 

but you would think that it would just be as simple as storing the VHD on the Hard Disk, Mounting the Volume and then editing the Boot.INI file so that it knew what to do.

 

I've had a play with this before, never really picked it up since #fail

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...