There is a procedure given by Amazon to make a volume available for use that has been attached as a block device. Given that I am attaching an EBS volume that is already ready to be used, is there a way in Windows Server 2008 R2 to either automatically mount or follow the procedure beforehand linked through the commandline rather than the GUI so that it can be automated?
3 Answers
You can use diskpart to do this. Open up cmd.exe and run diskpart. This allows you to execute commands. First, run san policy=onlineall
. Then, type list disk
. Because of the nature of EC2, you should consistently be able to mount the same disk. It appears it should be disk 1. Then, type select disk 1
and online disk
.
To script this, make a file called diskpart.txt and add these lines:
san policy=onlineall
select disk 1
online disk
Then you can execute DISKPART /s diskpart.txt
to automatically mount the drive.
-
Is there a way to run in line as a single command, if I am not able to store a text file?– JakeCommented Sep 9, 2014 at 20:12
-
can't thank you enough :) - please also add to the answer - in DISKPART do
ATTRIBUTE DISK CLEAR READONLY
Commented Oct 22, 2016 at 20:52
You could consider changing the disk policy to "OnlineAll":
DISKPART> san policy=OnlineAll
-
I tried running the command, but it did not appear to cause the disk to mount. Here is a screenshot where I first ran the command and then opened disk manager and explorer: i.imgur.com/brayXa7.png– JakeCommented Sep 9, 2014 at 19:39
-
You have to enter diskpart first, then issue the san command.– anonCommented Sep 9, 2014 at 19:41
-
Although I now get feedback about the SAN policy changing, it still does not cause the drive to mount: i.imgur.com/aM7zJCh.png– JakeCommented Sep 9, 2014 at 19:49
You can use the Set-Disk
cmdlet to make the disk online:
NAME
Set-Disk
SYNOPSIS
Takes a Disk object or unique disk identifiers and a set of attributes, and updates
the physical disk on the system.
To get a list of all disks:
Get-Disk
To enable disk #2:
Set-Disk -Number 2 -IsOffline $False
To enable all offline disks:
Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False
-
1It seems get-disk and set-disk are not available under Windows Server 2008 R2 (only 2012 and newer include the disk module according to this SO question )– JakeCommented Sep 9, 2014 at 18:45
-
Correct. You might need to consider installing PowerShell 4.0 in that case. Or using the workaround proposed in the SO question you link (diskpart script).– anonCommented Sep 9, 2014 at 19:02