设为首页 收藏本站
查看: 797|回复: 0

[经验分享] [转] How to create Windows OpenStack images

[复制链接]

尚未签到

发表于 2015-4-12 07:23:38 | 显示全部楼层 |阅读模式
  http://www.cloudbase.it/create-windows-openstack-images/
  We get regularly a lot of requests about how to generate Windows OpenStack images, especially for KVM, where the proper VirtIO drivers need to be installed.
  This article provides all the step required to build one, as we did for the official OpenStack Windows Server 2012 R2 Evaluation images
  All the scripts are publicly available on Github.
  For people familiar with Linux unattended deployment solutions like kickstart or preseed files, Windows has a roughly similar model based on XML files which can be automatically generated with a freely available tool currently called Windows Assessment and Deployment Kit (ADK in short). The ADK is not necessary if you’re fine with tweaking XML files manually as we usually do.
  Kickstart and Preseed files in Linux provide a “post” script where you can do some more advanced provisioning by running your own scripts. That’s also what we do here. The difference is that we split the work in 3 specific areas:

  • SynchronousCommands during the Specialize step. This is the earliest moment in which we can run some custom actions. Scripts will be executed with the SYSTEM credentials and won’t be able to access some OS features that are not yet available, for example WMI. This is the best place where to place your script, especially if you expect a reboot to load your features.
  • SynchronousCommands during the first logon. These commands get executed when the setup is basically done with the Administrator’s credentials (or whatever is specified in the XML file), just before the user can log in. As a comparison, this is the closest thing to a “post” script in a Kickstart file.
  • AsysncronousCommands during logon. These commands are executed after the setup and are really useful if you need to execute work that requires an unspecified number of additional reboots. We use it mainly to execute Windows updates.
  To make things simpler, during each of the above steps we download and execute a Powershell script from the Github repository instead of adding every single action that we want to run into the XML file. This way we have a lot more flexibility and troubleshooting issues while writing those scripts becomes a cakewalk, especially using virtual machine snapshots.
  Here are the actions that are performed in detail:
Specialize

  • The most important feature: setting the Cloudbase Solutions wallpaper. DSC0000.gif
  • Enabling ping response in the firewall (Note: RDP access is enabled in the XML file).
  • Downloading the FirstLogon script.
FirstLogon

  • Detecting what platform we are running on (KVM, Hyper-V, ESXi, etc). This requires WMI and is the reason why this and the next step are not executed during the Specialize phase.
  • Installing the relevant platform drivers and tools: VirtIO drivers on KVM and VMWare tools on ESXi. Nothing is needed on Hyper-V, as the relevant tools are already included starting with Windows Server 2008. Note: the VirtIO drivers are unsigned, so we use a trick to get the job done in a fully unattended way. DSC0001.gif   Important note: The Fedora VirtIO drivers version 0.1-65 generate a blue screen when you attach a volume. Use the stable version instead.
  • Downloading the logon script.
Logon

  • Installing PSWindowsUpdate, a Powershell module to handle, well, Windows Updates.
  • Installing the updates. At the end of each updates round a reboot is performed if needed and after reboot the same step is repeated until the system is up to date. Please note that this might take a while, mostly depending on your Internet connection speed.
  • Downloading and installing the latest Cloudbase-Init version.
  • Finally running Sysprep, using Cloudbase-Init’s Unattended.xml and rebooting.
  All you have to do to prepare an image, is to start a VM with the Autounattend.xml file on a virtual floppy, the Windows Server ISO connected on the first DVDRom drive and the optional platform tools (VirtIO drivers, VMWare tools, etc) on the second  DVDRom drive.
  When the image is done, it will shut down automatically, ready to be put in Glance.
  Fairly easy, no?
How to automate the image creation on KVM
  Shell
  IMAGE=windows-server-2012-r2.qcow2 FLOPPY=Autounattend.vfd VIRTIO_ISO=virtio-win-0.1-52.iso ISO=9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO KVM=/usr/libexec/qemu-kvm if [ ! -f "$KVM" ]; then KVM=/usr/bin/kvm fi qemu-img create -f qcow2 -o preallocation=metadata $IMAGE 16G $KVM -m 2048 -smp 2 -cdrom $ISO -drive file=$VIRTIO_ISO,index=3,media=cdrom -fda $FLOPPY $IMAGE \ -boot d -vga std -k en-us -vnc :1
  IMAGE=windows-server-2012-r2.qcow2
  FLOPPY=Autounattend.vfd
  VIRTIO_ISO=virtio-win-0.1-52.iso
  ISO=9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO
  KVM=/usr/libexec/qemu-kvm
  if [ ! -f "$KVM" ]; then
  KVM=/usr/bin/kvm
  fi
  qemu-img create -f qcow2 -o preallocation=metadata $IMAGE 16G
  $KVM -m 2048 -smp 2 -cdrom $ISO -drive file=$VIRTIO_ISO,index=3,media=cdrom -fda $FLOPPY $IMAGE \
  -boot d -vga std -k en-us -vnc :1
  Note: don’t forget to open the VNC port on the hypervisor’s firewall if you want to check of things are going (5901 in the example). It’s very important not to interact with the OS while the scripts run, but it’s a great way to see how things progress.
How to automate the image creation on Hyper-V
  PowerShell
  $vmname = "OpenStack WS 2012 R2 Standard Evaluation" # Set the extension to VHD instead of VHDX only if you plan to deploy # this image on Grizzly or on Windows / Hyper-V Server 2008 R2 $vhdpath = "C:\VM\windows-server-2012-r2.vhdx" $isoPath = "C:\your\path\9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO" $floppyPath = "C:\your\path\Autounattend.vfd" # Set the vswitch accordingly with your configuration $vmSwitch = "external" New-VHD $vhdpath -Dynamic -SizeBytes (16 * 1024 * 1024 * 1024) $vm = New-VM $vmname -MemoryStartupBytes (2048 * 1024 *1024) $vm | Set-VM -ProcessorCount 2 $vm.NetworkAdapters | Connect-VMNetworkAdapter -SwitchName $vmSwitch $vm | Add-VMHardDiskDrive -ControllerType IDE -Path $vhdpath $vm | Add-VMDvdDrive -Path $isopath $vm | Set-VMFloppyDiskDrive -Path $floppyPath $vm | Start-Vm
  $vmname = "OpenStack WS 2012 R2 Standard Evaluation"
  # Set the extension to VHD instead of VHDX only if you plan to deploy
  # this image on Grizzly or on Windows / Hyper-V Server 2008 R2
  $vhdpath = "C:\VM\windows-server-2012-r2.vhdx"
  $isoPath = "C:\your\path\9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO"
  $floppyPath = "C:\your\path\Autounattend.vfd"
  # Set the vswitch accordingly with your configuration
  $vmSwitch = "external"
  New-VHD $vhdpath -Dynamic -SizeBytes (16 * 1024 * 1024 * 1024)
  $vm = New-VM $vmname -MemoryStartupBytes (2048 * 1024 *1024)
  $vm | Set-VM -ProcessorCount 2
  $vm.NetworkAdapters | Connect-VMNetworkAdapter -SwitchName $vmSwitch
  $vm | Add-VMHardDiskDrive -ControllerType IDE -Path $vhdpath
  $vm | Add-VMDvdDrive -Path $isopath
  $vm | Set-VMFloppyDiskDrive -Path $floppyPath
  $vm | Start-Vm
  Check the README file of the project for updates, we’re definitely going to add more hypervisor options!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-56133-1-1.html 上篇帖子: OpenStack配置解析库oslo.config的使用方法 下篇帖子: HK Openstack Summit 归来有感
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表