Windows Server® 2008 R2 Hyper-V ™ Insiders Guide to Microsoft’s Hypervisor John Kelbley Mike Sterling Acquisitions Editor: Agatha Kim Development Editor: Stef Jones Technical Editor: Manjnath Ajjampur Production Editor: Elizabeth Ginns Britten Copy Editor: Kim Wimpsett Editorial Manager: Pete Gaughan Production Manager: Tim Tate Vice President and Executive Group Publisher: Richard Swadley Vice President and Publisher: Neil Edde Book Designer: Maureen Forys, Happenstance Type-O-Rama; Judy Fung Compositor: Craig Woods, Happenstance Type-O-Rama Proofreader: Word One, New York Indexer: Ted Laux Project Coordinator, Cover: Lynsey Stanford Cover Designer: Ryan Sneed Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-62700-6 ISBN 978-0-470-88033-3 (ebk) ISBN 978-0-470-88035-7 (ebk) ISBN 978-0-470-88034-0 (ebk) No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at (cid:72)(cid:84)(cid:84)(cid:80)(cid:26)(cid:15)(cid:15)(cid:87)(cid:87)(cid:87)(cid:14)(cid:87)(cid:73)(cid:76)(cid:69)(cid:89)(cid:14)(cid:67)(cid:79)(cid:77)(cid:15)(cid:71)(cid:79)(cid:15)(cid:80)(cid:69)(cid:82)(cid:77)(cid:73)(cid:83)(cid:83)(cid:73)(cid:79)(cid:78)(cid:83). Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation war- ranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommen- dations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Cataloging-in-Publication Data is available from the publisher. TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Windows Server and Hyper-V are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book. 10 9 8 7 6 5 4 3 2 1 Dear Reader, Thank you for choosing Windows Server 2008 R2 Hyper-V: Insiders Guide to Microsoft’s Hypervisor. This book is part of a family of premium-quality Sybex books, all of which are written by outstanding authors who combine practical experience with a gift for teaching. Sybex was founded in 1976. More than 30 years later, we’re still committed to producing con- sistently exceptional books. With each of our titles, we’re working hard to set a new standard for the industry. From the paper we print on, to the authors we work with, our goal is to bring you the best books available. I hope you see all that reflected in these pages. I’d be very interested to hear your com- ments and get your feedback on how we’re doing. Feel free to let me know what you think about this or any other Sybex book by sending me an email at (cid:78)(cid:69)(cid:68)(cid:68)(cid:69)(cid:32)(cid:87)(cid:73)(cid:76)(cid:69)(cid:89)(cid:14)(cid:67)(cid:79)(cid:77). If you think you’ve found a technical error in this book, please visit (cid:72)(cid:84)(cid:84)(cid:80)(cid:26)(cid:15)(cid:15)(cid:83)(cid:89)(cid:66)(cid:69)(cid:88)(cid:14)(cid:67)(cid:85)(cid:83)(cid:84)(cid:72)(cid:69)(cid:76)(cid:80)(cid:14)(cid:67)(cid:79)(cid:77). Customer feedback is critical to our efforts at Sybex. Best regards, Neil Edde Vice President and Publisher Sybex, an Imprint of Wiley Acknowledgments Writing a book about a new technology is a complex task, and like most such labors, it has been a team effort. As the front cover notes, this book has (at least) two authors, with contributions from many others. Sincere thanks go out to everyone involved and their families (who suffered much like mine!). Dividing the book into separate sections allowed us to, we hope, produce a better book more quickly than either of us could have on our own. Writing a book sounds like a great idea before you start (and it is), but it takes far longer to complete and requires a great deal more effort than I ever would have imagined. My wife, Sylvia, and my sons, Andrew and Alexander, have been more than patient with me the last few years while I put off other commit- ments and borrowed computer capacity from the infrastructure at home. Many co-workers and friends helped out (including many members of the Virtualization Nation), but I am most grateful for the feedback from the technical titans who were willing to read, critique, or contribute to my chapters (Manjnath Ajjampur, Jason Buffington, Arno Mihm, Alexander Lash, James O’Neill, Ben Herman, Alex Kibkalo, Matt Lavallee, and a guy named Bob). The dialogues with James and Ben in particular on the scripting chapters were great for the book (and for me), with my regret being that we didn’t write an entire book about Hyper-V scripting. There just isn’t enough space in two chapters for all the suggestions from James, Ben, and Alex. Thanks to the patient, professional editors for the first and second editions (Agatha Kim, Stef Jones, and Liz Britten), as well as others at Wiley who turned our ideas, sentences, and cocktail-napkin class diagrams into things more intelligible. The editorial process is still largely a mystery to me—a testament to the quality of their work! —John Kelbley When I sat down with John for dinner in Houston, I had no idea what I was getting myself into. “Hey Mike, want to help me write a book?” After a couple glasses of wine, he had convinced me that writing a book was a great idea. Now that the book is complete, I can heartily agree. Having worked with virtualization since the beginnings of Virtual PC for the Macintosh, I’ve seen huge advancements made with the usage of virtualization. No longer is it just a fun tool for your friends on your Mac—we’ve moved on to server virtualization and even more wide-scale adoption of what was previously a niche technology. This book is a way for me to try to get some of the information that has sat in my head for the last 13 years onto paper. No acknowledgments section would be complete without a list of people I need to thank. First and foremost, I need to thank my wife, Nancy, and my son, Maxwell—the reasons why I had enough time to write my portions of the book. Thank you for supporting me through the late nights that were necessary to get this done. My co-author, John, was immensely helpful in making sure we covered everything. Our technical reviewers, Manjnath and James, did a great job of keeping us honest. My team members, off whom I bounced countless ideas and who veri- fied many of my thoughts, deserve many of my thanks. Last, I need to thank the editorial staff— Agatha, Stef, and Liz—who have done an exceptional job of taking our words and crafting them into something that people want to read. —Mike Sterling About the Authors John Kelbley is a senior technical product manager with Microsoft’s Platform Tech Strategy team based in the Northeastern United States. He joined Microsoft in 2002 after working at a number of large enterprises as a management consultant, IT manager, and infrastructure archi- tect. John has more than 20 years of computing industry experience with a focus on infrastruc- ture architecture. This is the first book he has authored since leaving grade school. Mike Sterling is a program manager in the Windows Server team at Microsoft, focused exclusively on virtualization. Prior to this role, Mike spent 10 years in software testing, working on products such as Virtual PC, Virtual Server, and Hyper-V. When he’s not working, he can be found playing World of Warcraft or taking photographs. Contents at a Glance Introduction .........................................................................xix Chapter 1(cid:0)(cid:115)(cid:0)Introducing Hyper-V.............................................1 Chapter 2(cid:0)(cid:115)(cid:0)Installing Hyper-V and Server Core............................... 17 Chapter 3(cid:0)(cid:115)(cid:0)Configuring Hyper-V ........................................... 35 Chapter 4(cid:0)(cid:115)(cid:0)Virtualization Best Practices......................................63 Chapter 5(cid:0)(cid:115)(cid:0)Hyper-V Security ............................................... 79 Chapter 6(cid:0)(cid:115)(cid:0)Virtual Machine Migration....................................... 95 Chapter 7(cid:0)(cid:115)(cid:0)Backing Up and Recovering VMs ................................ 127 Chapter 8(cid:0)(cid:115)(cid:0)High Availability .............................................. 159 Chapter 9(cid:0)(cid:115)(cid:0)Understanding WMI, Scripting, andHyper-V ..................... 187 Chapter 10(cid:0)(cid:115)(cid:0)Automating Tasks.............................................225 Chapter 11(cid:0)(cid:115)(cid:0)Using System Center Virtual Machine Manager 2008 .............. 269 Chapter 12(cid:0)(cid:115)(cid:0)(cid:0)Protecting Virtualized Environments with System Center Data Protection Manager ...........................................305 Chapter 13(cid:0)(cid:115)(cid:0)Using System Center Operations Manager 2007................... 339 Index..............................................................................359 Contents Introduction.........................................................................xix Chapter 1(cid:21) (cid:153)(cid:21) Introducing Hyper-V......................................1 Scenarios for Hyper-V........................................................1 Server Consolidation ......................................................1 Testing and Development..................................................2 Business Continuity and Disaster Recovery ..................................2 Dynamic IT ..............................................................3 Architecture of Hyper-V......................................................3 Parent Partition...........................................................4 Virtual Machine ..........................................................7 Features of Hyper-V......................................................... 11 General Features......................................................... 11 New Features in Windows Server 2008 R2................................... 13 Hardware and Software Requirements for Hyper-V............................. 13 Hardware Requirements and Best Practices ................................. 13 Software Requirements................................................... 15 Summary.................................................................. 16 Chapter 2(cid:21) (cid:153)(cid:21) Installing Hyper-V and Server Core.........................17 Performing a Clean Installation of Hyper-V.................................... 17 Meeting the Installation Requirements...................................... 18 Installing the Hyper-V Role ............................................... 19 Adding the Hyper-V Role................................................. 20 Updating from the Beta Version to theFinalVersionofHyper-V..................22 Performing the Pre-update Configuration...................................22 Performing the Post-update Configuration ..................................23 Upgrading Hyper-V from Windows Server 2008 toWindowsServer 2008 R2.......23 Installing Windows Server Core.............................................. 24 Exploring the Windows Server Core Architecture............................ 24 Managing Windows Server Core........................................... 26 Installing Windows Server 2008 as a Core Installation........................... 27 Installation Considerations and Requirements............................... 27 Performing a Core Installation............................................. 27 Doing the Initial Configuration............................................ 28 Installing Hyper-V Under Windows Server 2008 Server Core ..................30 New in Windows Server 2008 R2: Introducing sconfig ........................ 32 Summary..................................................................33 | XII CONTENTS Chapter 3(cid:21) (cid:153)(cid:21) Configuring Hyper-V.....................................35 Getting Started: The Hyper-V MMC........................................... 35 Creating a New Virtual Machine ............................................. 37 Virtual Machine Settings ....................................................42 Hardware...............................................................42 Virtual Machine Management............................................. 51 New Virtual Hard Disk Wizard .............................................. 55 Exploring Types of Virtual Hard Disks ..................................... 55 Using the Wizard to Create Virtual Hard Disks.............................. 57 Virtual Network Manager ................................................... 58 Hyper-V Settings ........................................................... 59 Summary.................................................................. 61 Chapter 4(cid:21) (cid:153)(cid:21) Virtualization Best Practices..............................63 Host Best Practices..........................................................63 Choosing a Processor.....................................................63 How Much Memory Is Enough? ...........................................68 Storage: How Many Drives Do I Need? ..................................... 69 Networking............................................................. 70 Host Operating System Best Practices....................................... 74 Virtual Machine Best Practices ............................................... 75 Integration Services: Guest Drivers......................................... 76 Sysprep: Creating a Master Base Image .....................................77 Offline Patching ......................................................... 78 Summary.................................................................. 78 Chapter 5(cid:21) (cid:153)(cid:21) Hyper-V Security........................................79 The Hyper-V Security Model................................................. 79 Hypervisor Security......................................................80 Virtualization Stack Security .............................................. 81 The Virtual Machine Access Security Model ................................... 81 Working with the Authorization Manager ..................................... 82 Understanding the Terminology........................................... 82 Using the Authorization Manager for Hyper-V Security....................... 82 Using Alternative Tools................................................... 94 Storing the AzMan Store in Active Directory ................................ 94 Summary.................................................................. 94 Chapter 6(cid:21) (cid:153)(cid:21) Virtual Machine Migration ...............................95 Migration Challenges and Drivers ............................................ 95 Physical to Virtual (P2V) Migration......................................... 97 Virtual to Virtual (V2V) Migration ......................................... 97 Virtual to Physical (V2P).................................................. 98 Migration Considerations.................................................... 98 | CONTENTS XIII Capturing the Configuration.................................................99 Creating a Manual Inventory..............................................99 Using the MAP Toolkit .................................................. 100 Preparing a System for Migration............................................ 104 Capturing and Deploying Disk Images....................................... 104 Manual Migration with Image-Capture Tools............................... 104 Using Traditional Backup and Recovery Tools: SCVMM andWindowsHomeServer............................................. 105 Common Dedicated P2V Tools............................................ 106 Updating Images .......................................................... 107 Walking through a Physical-to-Virtual Migration.............................. 108 Traditional Imaging: Collecting and Creating Your Imaging Toolkit........... 108 Easy Image Capture: Disk2VHD.......................................... 116 Firing Up: Performing System Updates .................................... 117 Exporting and Importing in Hyper-V ........................................ 120 Exporting a Virtual Machine Locally...................................... 120 Exporting Over the Network ............................................. 121 Importing a Virtual Machine............................................. 123 Summary................................................................. 125 Chapter 7(cid:21) (cid:153)(cid:21) Backing Up and Recovering VMs..........................127 Virtual Machine Backup Considerations...................................... 127 Using the Volume Shadow Copy Services .................................. 128 Using VSS Backups and Saving State ...................................... 130 Hyper-V Snapshots Are Not Backups! ..................................... 132 Host-Based Backup Approaches............................................. 133 Export/Import.......................................................... 133 Physical to Virtual Conversion............................................ 134 Manual VHD Backup and Recovery....................................... 134 Windows Server Backup................................................. 135 Enterprise Backup Tools and Solutions..................................... 135 Agent Multiplexing...................................................... 135 Backup Encapsulation Benefits............................................ 135 Beware of Bloat in Host Backups.......................................... 136 Child Backup: Backing Up from Within ...................................... 137 VM Backup Driven by Storage ............................................ 137 VM Backup Driven by Applications ....................................... 138 Cluster-Shared Volumes and Backup ...................................... 138 Manually Backing Up and Recovering a Virtual Machine....................... 138 Performing a Windows Server Backup..................................... 138 Performing a Manual Backup............................................. 149 Summary................................................................. 158 | XIV CONTENTS Chapter 8(cid:21) (cid:153)(cid:21) High Availability.......................................159 Windows Server 2008 Failover Clustering..................................... 159 Failover Clustering Basics................................................ 161 Quick Migration vs. Live Migration ....................................... 163 Configuring a Cluster ................................................... 163 Protecting the VM vs. Protecting the Application............................ 163 Required Components for Failover Clustering .............................. 164 Storage Considerations for Clustering........................................ 167 Using Pass-Through Disk to Improve Performance.......................... 167 Clustering with GUIDs and Mount Points.................................. 168 Configuring Multiple VMs on a Single Physical Volume...................... 168 Clustered Shared Volumes in R2.......................................... 169 Backup and Recovery of a VM’s Host CSV.................................. 169 Building a Failover Cluster for Hyper-V ...................................... 170 Setting Up a Failover Cluster ............................................. 171 Hyper-V Server 2008 R2 and Server Core................................... 181 Configuring iSCSI from the Command Line................................ 183 Clustered Virtual Machine Management...................................... 185 Summary................................................................. 186 Chapter 9(cid:21) (cid:153)(cid:21) Understanding WMI, Scripting, andHyper-V ...............187 Common Management Tasks................................................ 187 WMI Overview............................................................ 189 Accessing WMI............................................................ 191 WMI Security .......................................................... 192 Accessing the Virtualization Namespace................................... 192 WMI Scripting Tools and Resources ....................................... 192 Browsing the Virtualization Namespace ................................... 192 Scripting Technology Overview ............................................. 195 Visual Basic Script....................................................... 196 JScript................................................................. 196 Perl, Python, and Others................................................. 196 Command-Line Tools.................................................... 197 Windows PowerShell.................................................... 197 PowerShell for Newcomers.................................................. 198 PowerShell Installation and Setup......................................... 198 Finding Your Way Around PowerShell..................................... 201 Making Things Work in PowerShell....................................... 203 Common Elements of WMI Scripts........................................... 213 WMI and VBScript...................................................... 213 WMI and PowerShell.................................................... 215 Virtualization Classes...................................................... 216 Useful WMI Virtualization Classes to Know................................ 216 The Msvm_ComputerSystem Class....................................... 219 Summary.................................................................223