制作Xen Windows Server 2008(2012)模板镜像

这段时间一直在研究如何制作一个适合Xen虚拟化的Windows Server 2008(2012)镜像,中间虽然遇到了一些阻挠,不过最终还是顺利解决,成功制作出了Xen Windows Server 2008(2012) 模板镜像。这里记录下整个制作过程:

1、首先要确保服务器的VT已经打开,可以通过如下命令来查看:

[[email protected] ~]# cat /proc/cpuinfo | egrep ‘(vmx|svm)‘

如果有输出,则说明该服务器的VT已经打开。

2、创建一个将要用来安装Windows Server 2008(2012)系统的LV,命令如下:

[[email protected] ~]# lvcreate -L 15G -n windows vg0
  Logical volume "windows" created

参数说明:

1)-L:指定LV的大小。这里设置为15G,是因为Windows Server 2008(2012)系统本身安装完后,占用系统盘较大,大约在9--10G;另外官方推荐系统盘大小要在13G以上

2)vg0:这里是我测试创建的vg

3、查看已经成功创建的系统LV:

[[email protected] ~]# lvs
  LV          VG   Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  windows     vg0  -wi-a- 15.00G
[[email protected] ~]# ll /dev/vg0/windows
lrwxrwxrwx 1 root root 23 Jun  2 13:12 /dev/vg0/windows -> /dev/mapper/vg0-windows

4、系统LV 创建好后,开始准备Xen虚拟机的配置文件:

kernel = "/usr/lib/xen/boot/hvmloader"
builder=‘hvm‘
memory = 2048
name = "windows"
vif = [ ‘bridge=eth0‘ ]
disk = [ ‘phy:/dev/vg0/windows,hda,w‘,‘file:/root/cn_windows_server_2008_r2_standard_enterprise_datacenter_and_web_with_sp1_x64_dvd_617598.iso,hdc:cdrom,r‘ ]
vcpus  = 1
on_reboot = ‘restart‘
on_crash = ‘restart‘
boot = ‘d‘
sdl = 0
vnc = 1
vnclisten = ‘0.0.0.0‘
vncdisplay = 1
stdvga = 0
serial = ‘pty‘
usbdevice = ‘tablet‘
localtime = 1

注意:

1)这里使用的是全虚拟化方式安装Windows Server虚拟机,后面会安装半虚拟化驱动qplpv driver

2)要设置虚拟机从CDROM启动

5、创建并启动Windows Server虚拟机,命令如下:

[[email protected] ~]# xm create /root/windows.cfg
Using config file "/root/windows.cfg".
Started domain windows (id=442)

6、此时Windows Server虚拟机已经启动,进入到系统安装界面,下面就是按部就班地安装系统;我们通过VNC客户端连接到虚拟机上,如下所示:

7、系统安装到下面这一步时:

这里我们需要事先手动对整块磁盘进行分区并格式化,因为如果我们采用了系统默认的分区格式化方式,系统会帮我们创建一个100M的隐藏分区,后期我们在导出系统文件时会比较麻烦。

这里同时按住 Shift + F10,弹出命令提示符界面,执行如下命令进行磁盘分区并格式化:

执行命令后,关闭命令提示符,点击"刷新",发现此时磁盘分区已经创建好了,而且没有那100M的隐藏分区,如下图:

8、后面就是系统安装过程了:

9、系统安装完成后,关闭虚拟机,修改Xen虚拟机配置文件:

kernel = "/usr/lib/xen/boot/hvmloader"
builder=‘hvm‘
memory = 2048
name = "windows"
vif = [ ‘bridge=eth0‘ ]
disk = [ ‘phy:/dev/vg0/windows,hda,w‘,‘file:/root/xen-windows-driver.iso,hdc:cdrom,r‘ ]
vcpus  = 1
on_reboot = ‘restart‘
on_crash = ‘restart‘
boot = ‘c‘
sdl = 0
vnc = 1
vnclisten = ‘0.0.0.0‘
vncdisplay = 1
stdvga = 0
serial = ‘pty‘
usbdevice = ‘tablet‘
localtime = 1

注意:

1)设置系统从硬盘启动

2)修改CDROM为xen-windows-driver.iso

PS:这里的xen-windows-driver.iso是本人通过 mkisofs 命令制作的,里面仅仅包含了qplpv drvier及agent,你同样可以制作你自己需要的iso文件

10、下面就是根据需要修改一些Windows Server系统配置的工作,具体如下:

1)关闭防火墙

2)开启远程桌面

3)设置新磁盘自动联机,具体命令如下:

4)安装半虚拟化驱动qplpv driver

安装完重启后,我们发现"设备管理器"里的驱动变为Xen的了

11、至此,系统配置修改已经完成了,下面关闭虚拟机,备份磁盘MBR启动扇区,命令如下:

[[email protected] ~]# dd if=/dev/vg0/windows of=windows_mbr bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.010009 seconds, 51.2 kB/s[[email protected] ~]# ll windows_mbr -rw-r--r-- 1 root root 512 Jun  2 15:49 windows_mbr

12、创建磁盘分区映射,将所有分区映射到/dev/mapper下:

[[email protected] ~]# kpartx -av /dev/vg0/windows
add map windows1 : 0 31453184 linear /dev/vg0/windows 2048
[[email protected] ~]# ll /dev/mapper/
total 0
crw------- 1 root root  10, 62 May  5 17:18 control
brw-rw---- 1 root disk 253,  5 Jun  2 15:34 vg0-windows
brw-rw---- 1 root disk 253,  4 Jun  2 15:54 windows1
[[email protected] ~]# 

因为前面我们安装系统时只创建了一个分区,因此这里就只有一个windows分区,即windows1

13、mount windows分区到mnt下:

[[email protected] ~]# mount -t ntfs-3g /dev/mapper/windows1 /mnt/
[[email protected]alhost ~]# ll /mnt/
total 2097184
drwxrwxrwx 1 root root       4096 Jun  2 14:17 Boot
-rwxrwxrwx 1 root root     383786 Nov 21  2010 bootmgr
-rwxrwxrwx 1 root root       8192 Jun  2 14:17 BOOTSECT.BAK
lrwxrwxrwx 2 root root         60 Jul 14  2009 Documents and Settings -> /mnt//Users
-rwxrwxrwx 1 root root 2147082240 Jun  2 15:32 pagefile.sys
drwxrwxrwx 1 root root          0 Jul 14  2009 PerfLogs
drwxrwxrwx 1 root root       4096 Jun  2 14:20 ProgramData
drwxrwxrwx 1 root root       4096 Jun  2 15:31 Program Files
drwxrwxrwx 1 root root       4096 Jun  2 15:31 Program Files (x86)
drwxrwxrwx 1 root root          0 Jun  2 14:20 Recovery
drwxrwxrwx 1 root root          0 Jul 14  2009 $Recycle.Bin
drwxrwxrwx 1 root root       4096 Jun  2 14:18 System Volume Information
drwxrwxrwx 1 root root       4096 Jun  2 14:41 Users
drwxrwxrwx 1 root root      16384 Jun  2 15:29 Windows
[[email protected] ~]# 

因为windows文件系统是NTFS格式的,所以这里类型要设置为ntfs-3g

14、删除文件 pagefile.sys:

[[email protected] ~]# rm -f /mnt/pagefile.sys
[[email protected] ~]# ll /mnt/
total 424
drwxrwxrwx 1 root root   4096 Jun  2 14:17 Boot
-rwxrwxrwx 1 root root 383786 Nov 21  2010 bootmgr
-rwxrwxrwx 1 root root   8192 Jun  2 14:17 BOOTSECT.BAK
lrwxrwxrwx 2 root root     60 Jul 14  2009 Documents and Settings -> /mnt//Users
drwxrwxrwx 1 root root      0 Jul 14  2009 PerfLogs
drwxrwxrwx 1 root root   4096 Jun  2 14:20 ProgramData
drwxrwxrwx 1 root root   4096 Jun  2 15:31 Program Files
drwxrwxrwx 1 root root   4096 Jun  2 15:31 Program Files (x86)
drwxrwxrwx 1 root root      0 Jun  2 14:20 Recovery
drwxrwxrwx 1 root root      0 Jul 14  2009 $Recycle.Bin
drwxrwxrwx 1 root root   4096 Jun  2 14:18 System Volume Information
drwxrwxrwx 1 root root   4096 Jun  2 14:41 Users
drwxrwxrwx 1 root root  16384 Jun  2 15:29 Windows
[[email protected] ~]# 

15、unmount windows分区:

[[email protected] ~]# umount /mnt/
[[email protected] ~]# ll /mnt/
total 0
[[email protected] ~]# 

16、打包并压缩windows1分区里的系统文件:

[[email protected] ~]# ntfsclone --save-image --output - /dev/mapper/windows1 | gzip -c > windows_img
ntfsclone v1.13.1 (libntfs 9:0:0)
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 16104026112 bytes (16105 MB)
Current device size: 16104030208 bytes (16105 MB)
Scanning volume ...
100.00 percent completed
Accounting clusters ...
Space in use       : 7274 MB (45.2%)
Saving NTFS to image ...
100.00 percent completed
Syncing ...
[[email protected] ~]# ll windows_img
-rw-r--r-- 1 root root 3073945978 Jun  2 16:14 windows_img

17、删除磁盘分区映射:

[[email protected] ~]# kpartx -d /dev/vg0/windows
[[email protected] ~]# ll /dev/mapper/
total 0
crw------- 1 root root  10, 62 May  5 17:18 control
brw-rw---- 1 root disk 253,  5 Jun  2 15:34 vg0-windows
[[email protected] ~]# 

18、至此,我们需要的Xen Windows Server模版镜像就制作好了,下面两个文件就是我们需要的:

[[email protected] ~]# ll windows_*
-rw-r--r-- 1 root root 3073945978 Jun  2 16:14 windows_img
-rw-r--r-- 1 root root        512 Jun  2 15:49 windows_mbr
[[email protected] ~]# 

PS:这里虽然是Windows Server 2008示例说明,但2012过程同上。

时间: 2024-08-02 15:17:40

制作Xen Windows Server 2008(2012)模板镜像的相关文章

Xen虚拟机磁盘镜像模板制作(二)—Windows Server 2008(2012)

在<Xen虚拟机磁盘镜像模板制作(一)—Windows Server 2008(2012)>一文中,我们已经成功制作出了Windows Server磁盘镜像.下面我们说明下如何通过它来生成目标虚拟机,同时测试下之前制作好的虚拟机磁盘镜像模版是否有问题.具体流程如下文所述: 1.创建目标虚拟机的系统盘: [[email protected] ~]# lvcreate -L 15G -n windows_vm vg0 Logical volume "windows_vm" cr

Windows Server 2008 R2模板机制作(VMware Workstation)

本文主要是针对于VMware Workstation平台制作Windows Server 2008 R2模板机的,制作模板机前需要在VMware Workstation中安装好了windows server 2008 r2后再操作如下步骤: 1安装vmware tools 选择虚拟机--安装vmware tools根据提示打开光盘驱动器,选择典型安装即可.一路点击下一步完成后重启即可. 2.关闭防火墙 开始--控制面板--系统和安全--防火墙--打开或关闭防火墙--关闭所有防火墙 3.网卡设置中

【定时任务|开机启动】Windows Server 2008/2012 计划任务配置(任务计划程序)每分钟执行BAT

打开计划任务快捷方式(在 “管理工具”内): C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\Task Scheduler.lnk 很多人在问我: 1.Windows Server 2008 计划任务在哪里配置? 2.Windows Server 2008 可以配置每分钟或是每小时执行我的任务吗? 答案是:可以! 首先Windows Server 2008不同于其他服务器操作系统和Windows

使用 UltraISO 将 Windows Server 2008 R2 ISO 镜像文件烧录到 U 盘

准备材料:1 一个 8-16G 的 U 盘,并将 U 盘格式化成 NTFS 格式. (注意,不能用 FAT 格式化 U 盘,因为后续使用时 install.wim 文件会超过 2G,导致无法注入对应 USB 3.0 的驱动)U 盘用 USB 2.0 的 U 盘.注意最好不要用 USB 3.0 的 U 盘,可能造成无法正常识别或者加载驱动不正常.在服务器上也要接 USB 2.0 的接口,不要用 USB 3.0 的接口.(2.0 的接口是白色或者黑色的或者标注通用 USB 接口图案,3.0 的接口是

Lenovo system X3650 M5安装Windows Server 2008 R2简易教程

目标:在Lenovo System X3650上安装Windows Server 2008 R2. (建议安装windows server 2012 R2) 准备工具:U盘和空白光盘,DVD刻录机. 准备软件:rufus,ultraiso. 准备镜像:windows server 2008 r2 iso和server Guide iso. 准备知识:X3650 M5默认是UEFI引导方式,GPT分区格式.UEFI引导的GPT分区格式的U盘,需要用rufus制作. Windows Server 2

VM10.0上创建Windows server 2008 SP2,并且,安装loadrunner11

用了一天的时间在VM10.0上创建了一台Windows server 2008 standard SP2的虚拟机,然后,在该虚拟机上安装了loadrunner11.0,过程中遇到最大的麻烦就是找安装包.补丁,不过网络真是一个大的知识园地,它才不会嫌弃你是否问题太多,哈哈~ 一.创建Windows server 2008 standard SP2: 首先,在网上找到一个Windows server 2008 standard 操作系统的镜像文件(即:6001.18000.080118-1840_x

使用kvm制作Eucalyptus镜像(Windows Server 2008为例)

1.前言 Elastic Utility Computing Architecture for Linking Your Programs To Useful Systems (Eucalyptus) 是一种开源的软件基础结构,用来通过计算集群或工作站群实现弹性的.实用的云计算.它最初是美国加利福尼亚大学 Santa Barbara 计算机科学学院的一个研究项目,现在已经商业化,发展成为了 Eucalyptus Systems Inc.不过,Eucalyptus 仍然按开源项目那样维护和开发.

WINDOWS服务器安全加固实战(适用于WINDOWS SERVER 2008 R2和WINDOWS SERVER 2012)

最近我们立方技术工作室在使用阿里云的过程中,发现服务器安全性也不是很高,而服务端的安全软件都很贵.为了为朋友们提供更加有效的解决方案,我们决定身体力行,高筑墙,大幅度提升服务器的安全防护级别! 主机安全 启用防火墙 阿里云windows Server 2008 R2默认居然没有启用防火墙.2012可能也是这样的,不过这个一定要检查! 补丁更新 启用windows更新服务,设置为自动更新状态,以便及时打补丁. 阿里云windows Server 2008 R2默认为自动更新状态,2012可能也是这

制作Windows Server 2008安装启动U盘

昨天刚下了Windows server 2008因为没有刻录机,所以我就用2G U盘把Windows server 2008光盘镜像做成U盘安装效果和光盘安装一样. 下面就是制作方法: UltraISO 7.6.6.1308 ME 1. 2G U盘一个 昨天刚下了Windows server 2008因为没有刻录机,所以我就用2G U盘把Windows server 2008光盘镜像做成U盘安装效果和光盘安装一样. 下面就是制作方法: 1. 2G U盘一个. UltraISO软件(下面有下载)