diskpart to deal with driver letter changed after reboot in Virtual Machine

 Drive letter will changed after roboot VM managed by hyper-v in win server 2k8 in when disk is not fixed size.

 Try parse diskpart output info genereated by detail disk as following to build a script to change drive letter. 

 

DISKPART>

DISKPART> List disk

  Disk ###  Status      Size     Free     Dyn  Gpt
  --------  ----------  -------  -------  ---  ---
  Disk 0    Online       127 GB      0 B
  Disk 1    Online       127 GB      0 B
  Disk 2    Online       100 GB      0 B
  Disk 3    Online       127 GB      0 B

DISKPART> list volume

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 0     J   Zjian        NTFS   Partition    127 GB  Healthy
  Volume 1     K   Hru         NTFS   Partition    127 GB  Healthy
  Volume 2     C   System       NTFS   Partition    100 GB  Healthy    System
  Volume 3     I   L26      NTFS   Partition    127 GB  Healthy

DISKPART> select disk 1

Disk 1 is now the selected disk.

DISKPART> detail disk

Virtual HD ATA Device
Disk ID: 28340798
Type   : ATA
Bus    : 1
Target : 1
LUN ID : 0
Read-only  : No
Boot Disk  : No
Pagefile Disk  : No
Hibernation File Disk  : No
Crashdump Disk  : No

  Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
  ----------  ---  -----------  -----  ----------  -------  ---------  --------
  Volume 1     K   Hru         NTFS   Partition    127 GB  Healthy

DISKPART>

 

script for diskpart:

compare disk label and pick up the disk and volume value.

 

SELECT DISK 2 <<replace by result parsed
SELECT VOLUME 1 <<replace by result parsed
ASSIGN LETTER=D 

SELECT DISK 3
SELECT VOLUME 2
ASSIGN LETTER=E

SELECT DISK 1
SELECT VOLUME 3
ASSIGN LETTER=F

 

 

 

http://support.microsoft.com/kb/300415/zh-cn

http://support.microsoft.com/default.aspx?scid=kb;zh-cn;325590

http://bbs.pcbeta.com/archiver/tid-290417.html

posted @ 2009-12-21 19:34  Zhongjian Zhang  阅读(425)  评论(0编辑  收藏  举报