I want to try out the new iSCSI target feature of Windows Server 2012. This feature only works with virtual disks however, not physical disks, so I’ll have to create a VHD file in the machine and use that as a target. No problemo, just that the server itself is running from a virtual disk (as it’s a VM running on VMware Workstation) and it kind of feels odd to have a virtual disk inside another virtual disk – all that overhead is going to make it slow! So I decided to pass a physical disk instead, to the server, and let it create the VHD file on that.
First, decide if you are going to allocate a disk or a partition to the virtual machine. I was going to allocate a partition, so I cleared up some space, made an empty partition on it, edited the settings of the virtual machine, and added this partition as a physical disk. One thing to keep in mind is to NOT choose the “Independent disks” mode in settings. I selected this mode initially as I didn’t want the disk to be used when making snapshots, but this had the unintended effect of making the disk read-only to the guest. I am guessing this is a bug. Independent mode doesn’t really apply to physical disks anyway as they bypass the hypervisor and so can’t be snapshotted.
After adding the disk, power on the virtual machine. The disk will be present, but you’ll have to get it ready before being able to use it, so here’s what I did. Note that I am using Windows Server 2012 Core so diskpart
is all I have.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# list the disks - note that disk 1 is present but offline DISKPART> list disk Disk ### Status Size Free Dyn Gpt -------- ------------- ------- ------- --- --- Disk 0 Online 60 GB 0 B Disk 1 Offline 931 GB 67 GB DISKPART> select disk 1 Disk 1 is now the selected disk. DISKPART> online disk DiskPart successfully onlined the selected disk. # list the volumes - note E: which is RAW DISKPART> list volume Volume ### Ltr Label Fs Type Size Status Info ---------- --- ----------- ----- ---------- ------- --------- -------- Volume 0 D DVD-ROM 0 B No Media Volume 1 C NTFS Partition 59 GB Healthy System Volume 2 E RAW Partition 67 GB Healthy # select the volume and try to format it DISKPART> select volume E Volume 2 is the selected volume. DISKPART> format fs=NTFS LABEL="WIN-DATA01" QUICK 0 percent completed Virtual Disk Service error: The media is write protected. |
The formatting fails! This is because the disk is shown as read-only for some reason so we have to tell diskpart
to clear that attribute. Do the following –
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
DISKPART> select disk 1 Disk 1 is now the selected disk. # view the current attributes; note it's read only DISKPART> attributes disk Current Read-only State : Yes Read-only : Yes Boot Disk : No Pagefile Disk : No Hibernation File Disk : No Crashdump Disk : No Clustered Disk : No # clear the read-only attribute DISKPART> attribute disk clear readonly Disk attributes cleared successfully. DISKPART> select volume E Volume 2 is the selected volume. DISKPART> format fs=NTFS LABEL="WIN-DATA01" QUICK 100 percent completed DiskPart successfully formatted the volume. |
And now it formats and we can use the disk! Thanks to this KB article where I read about clearing disk attributes.