我这的实验环境原本是用了2台XenServer6.0(xenserver1 - 192.168.1.233, xenserver2 -192.168.1.232),1台 CentOS 做NFS ISO SR 和 NFS SR存储虚拟硬盘文件,同时兼Linux 远程安装服务器(含 apache,dhcp,tftp和Centos安装文件)。为了省一台服务器,打算在其中的一台XenServer(xenserver1)上安装NFS和远程安装服务。实际过程是先试验的NFS,但结果发现分区是首先要解决的问题,所以先介绍分区部分。


首先确保xenserver1是独立服务器。如果xenserver1在某个XenServer资源池(pool)中,就必须脱离出来。脱离pool之前,确保export所有的虚拟机,fileformat建议选xva。

[root@xenserver1 ~]# df
Filesystem          1K-blocks     Used Available Use% Mounted on
/dev/sda1             4127440  1774972  2142804  46% /
none                   388584        0   388584   0% /dev/shm
/opt/xensource/packages/iso/XenCenter.iso
                        44414    44414        0 100% /var/xen/xc-install
[root@xenserver1 ~]#

主分区只剩下2G的空间,这就必须删除XenServer6安装时创建的虚拟机存储空间。(折腾了一番后发现,其实还是重装系统简单。)

[root@xenserver1 ~]# xe sr-list type=lvm

uuid (RO)               :0ff3d613-2a48-2173-328b-4ff6bd746fa1   【复制这个本地存储SR的UUID】
         name-label ( RW): Local storage
   name-description ( RW):
               host ( RO): xenserver1
               type ( RO): lvm
       content-type ( RO): user

[root@xenserver1 ~]#
[root@xenserver1 ~]# xe pbd-listsr-uuid=0ff3d613-2a48-2173-328b-4ff6bd746fa1   【本地存储SR的UUID】

uuid (RO)                 :d6ff6d4d-6e2b-bc69-fdd0-512d7c5e23ed                【物理存储块pbd的UUID】
            host-uuid ( RO): cacddab0-b05c-42ea-b324-131ca428f914
              sr-uuid ( RO): 0ff3d613-2a48-2173-328b-4ff6bd746fa1
        device-config (MRO): device:/dev/disk/by-id/scsi-SATA_WDC_WD3200AAKS-_WD-WMAV2W528467-part3
   currently-attached ( RO): true


[root@xenserver1 ~]#
[root@xenserver1 ~]# xe pbd-unpluguuid=d6ff6d4d-6e2b-bc69-fdd0-512d7c5e23ed   【断开本地存储的SR】
[root@xenserver1 ~]#
[root@xenserver1 ~]# xe sr-destroyuuid=0ff3d613-2a48-2173-328b-4ff6bd746fa1   【移除本地存储的SR】
[root@xenserver1 ~]#
[root@xenserver1 ~]# xe sr-list type=lvm
[root@xenserver1 ~]# 【已经没有结果输出了。】
[root@xenserver1 ~]#
[root@xenserver1 ~]# fdisk -l

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! Theutil fdisk doesn't support GPT. Use GNU Parted.

Disk /dev/sda: 320.0 GB, 320072933376 bytes
256 heads, 63 sectors/track, 38761 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes

   DeviceBoot     Start        End     Blocks   Id System
/dev/sda1  *          1      38762  312571223+  ee  EFI GPT
[root@xenserver1 ~]#

这段意思是fdisk无法修改此系统的分区表,应该用 Parted。系统内没有parted软件包,yum install parted 提示No package parted available. 看来还需要解决yum.repos,以便以后方便安装其他软件包。这样:

[root@xenserver1-NEW ~]# ls /etc/yum.repos.d
CentOS-Base.repo CentOS-Media.repo  Citrix.repo
[root@xenserver1-NEW ~]#
[root@xenserver1-NEW ~]# vi /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the clientand the
# update status of each mirror to pick mirrors that are updated toand
# geographically close to the client.  You shoulduse this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you cantry the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
exclude=kernel-xen*, *xen*
enabled=0

#released updates
.......
.......

将[base]段内的 enabled=0 改为 enabled=1,然后安装parted。


但是,接着用yum install parted能找到软件包,却无法下载。DNS设置不知道跑哪去了,临时改一下DNS:

[root@xenserver1 ~]# vi /etc/resolv.conf
nameserver 202.106.196.115

[root@xenserver1 ~]# yum install parted
.........
Installed:
  parted.i3860:1.8.1-28.el5                                                   
Complete!

parted安装好了,试着改分区。 * * *注意:以下操作不可模仿,结果是灾难性的!! * * *

[root@xenserver1 ~]# parted
GNU Parted 1.8.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list ofcommands.
(parted) print     【查看分区】

Model: ATA WDC WD3200AAKS-7 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End    Size    Filesystem  Name  Flags
 1     1049kB  4295MB 4294MB ext3                   
 2     4296MB  8590MB 4294MB                         
 3     8591MB  320GB  311GB                     lvm  

(parted) mkfs      【制作文件系统】
Warning: The existing file system will be destroyed and all data onthe   
partition will be lost. Do you want to continue?
Yes/No? y
Partition number?3    【输入3】                                                 
File system?  [ext2]? 【回车】
(parted) print        【再次查看分区】        

Model: ATA WDC WD3200AAKS-7 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End    Size    Filesystem  Name  Flags
 1     1049kB  4295MB 4294MB ext3                   
 2     4296MB  8590MB 4294MB                         
 3     8591MB  320GB  311GB  ext2              lvm  

(parted) quit      【退出】   

【修改 /etc/fstab 】
[root@xenserver1 ~]# vi /etc/fstab
/dev/sda3  /nfs     ext2  defaults   0 0

结果,系统无法启动了,分区3是不能轻易破坏的。或许是不会用parted,哪位大侠了解parted请不吝赐教。


* * *注意:以上操作不可模仿,结果是灾难性的!! * * *



现在重新安装XenServer,并且选择不创建VM的存储空间,有进展了。见图,在 Virtual Machine Storage 设置里,敲空格去掉sda前面的*号



(博客注册时间还不够一周,上不了图




重新安装好了,hostname是 xenserver1-NEW ,再下载Parted,看看分区:


[root@xenserver1-NEW /]# parted /dev/sda print

Model: ATA WDC WD3200AAKS-7 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End    Size    Filesystem  Name  Flags
 1     1049kB  4295MB 4294MB ext3                   
 2     4296MB  8590MB 4294MB                         
 3     8591MB  320GB  311GB  ext2              lvm  

Information: Don't forget to update /etc/fstab, ifnecessary.

可以看到,分区默认就是ext2了,挂载一下试试。

[root@xenserver1-NEW /]# mkdir /newvol
[root@xenserver1-NEW /]# mount -t auto /dev/sda3 /newvol
[root@xenserver1-NEW /]# ls -l -a /newvol
total 56
drwxr-xr-x  3 root root  4096 Dec20 19:25 .
drwxr-xr-x 23 root root  4096 Dec 20 19:47..
drwxr-xr-x  2 root root 49152 Dec 20 19:25lost+found
[root@xenserver1-NEW /]#

挂载成功了!

修改 /etc/fstab,添加这一行:


[root@xenserver1-NEW ~]# vi /etc/fstab
/dev/sda3 /newvol   ext2  defaults   0 0

重启:


[root@xenserver1-NEW ~]# shutdown -r now



准备NFS要用的目录:


[root@xenserver1-NEW /]# mkdir/newvol/iso   #做ISO SR
[root@xenserver1-NEW /]# mkdir/newvol/vm    #保存虚拟硬盘文件
[root@xenserver1-NEW ~]# ls -l -a /newvol
total 64
drwxr-xr-x  5 root root  4096 Dec20 20:39 .
drwxr-xr-x 25 root root  4096 Dec 20 20:46..
drwxr-xr-x  2 root root  4096 Dec20 20:39 iso
drwxr-xr-x  2 root root 49152 Dec 20 19:25lost+found
drwxr-xr-x  2 root root  4096 Dec20 20:39 vm

大功告成!下面可以安装NFS了。



顺便比较一下xenserver2 能不能挂载sda3:


[root@xenserver2 ~]# mount -t auto /dev/sda3 /mnt
mount: you must specify the filesystem type

失败!带有Virtual Machine Storage的