XenServerに物理ハードディスクを追加してみた

サブの方のサーバが死んだ。
起動中に強制終了しちゃった自分のせいだけど。
サブサーバはオープンソースXen使ってたけど、今回XenServerにした。
KVMとかも使ってみたかったけど、完全仮想に対応してないから断念。
 

インストール

今回は、ホストOS用にSSD(32GB)、ゲストOS用にHDD(500GB)を使う。
ホストOSインストール時に、SRとして2つとも選択してしまうとSSDとHDDをLVMで繋げてしまう。
高速に動いて欲しいマシンと低速で大容量のマシンを作り分けるために、SRを分けたい。
インストール時はSSDのみを選択して、インストールが終わったあとでHDDをSRにする。
 

HDDを初期化する

fdiskでパーティションを1つ作る。

[root@xenserver2 ~]# fdisk -l

Disk /dev/sda: 32.0 GB, 32044482560 bytes
255 heads, 63 sectors/track, 3895 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         499     4008186   83  Linux
/dev/sda2             500         998     4008217+  83  Linux
/dev/sda3             999        3895    23270152+  83  Linux

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
[root@xenserver2 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 60801.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-60801, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801):
Using default value 60801

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@xenserver2 ~]# fdisk -l

Disk /dev/sda: 32.0 GB, 32044482560 bytes
255 heads, 63 sectors/track, 3895 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         499     4008186   83  Linux
/dev/sda2             500         998     4008217+  83  Linux
/dev/sda3             999        3895    23270152+  83  Linux

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60801   488384001   83  Linux

 

HDDをSRにする

[root@xenserver2 ~]# xe sr-create type=lvm content-type=user device-config:device=/dev/sdb1 name-label="Local storage 2"
d35e4dda-bc15-9050-da42-9a633140e686

 

仮想マシンをインストールした際にまずやったらよさそうな事

CentOS用。
これをやって、テンプレートに変換しとく。

# XenTool
mount /dev/xvdd /mnt/
yes | /mnt/Linux/install.sh
umount /mnt/

# SELinux
setenforce 0
sed -i "s/^SELINUX=.*$/SELINUX=disabled/i" /etc/sysconfig/selinux

# chkconfig
for SERVICE in `chkconfig --list | awk '{print $1}'`
do
	chkconfig --level 0123456 $SERVICE off
done
for SERVICE in network sshd syslog xe-linux-distribution
do
	chkconfig --level 2345 $SERVICE on
done

# Network
cat <<-'MACGENPY' > /usr/local/bin/macgen.py
	#! /usr/bin/python
	# macgen.py script generates a MAC address for Xen guests
	#
	import random
	mac = [ 0x00, 0x16, 0x3e,
	random.randint(0x00, 0x7f),
	random.randint(0x00, 0xff),
	random.randint(0x00, 0xff) ]
	print ':'.join(map(lambda x: "%02x" % x, mac))
MACGENPY
chmod +x /usr/local/bin/macgen.py

cat <<-'CHANGEMAC' > /usr/local/bin/changemac.sh
	#!/bin/bash

	if [ $# -ne 1  ]; then
	    echo "Usage: changemac.sh interface"
	    exit 1
	fi
	INTERFACE=$1
	IFCFG=/etc/sysconfig/network-scripts/ifcfg-$INTERFACE
	if [ ! -f $IFCFG ]; then
	    echo "Not found interface config"
	    exit 1
	fi
	sed -i '/^\(MAC\|HW\)ADDR/d' $IFCFG
	MAC=`/usr/local/bin/macgen.py`
	echo "MACADDR=$MAC" >> $IFCFG
	echo "$INTERFACE $MAC"
CHANGEMAC
chmod +x /usr/local/bin/changemac.sh

cat <<-'CHANGEMACALL' > /usr/local/bin/changemacall.sh
	#!/bin/bash

	for IFCFG in `find /etc/sysconfig/network-scripts/ | grep ifcfg-eth`
	do
	    INTERFACE=${IFCFG#[./]*ifcfg-}
	    /usr/local/bin/changemac.sh $INTERFACE
	done
CHANGEMACALL
chmod +x /usr/local/bin/changemacall.sh

/usr/local/bin/changemacall.sh

# Delete history
echo -n > ~/.bash_history
HISTFILESIZE=0

# shutdown
init 0

 
テンプレートから仮想マシンを作ったら、これだけはやり直す。

/usr/local/bin/changemacall.sh

 

参考リンク

SRについてはこの辺が詳しかった。
 
Citrix XenServer無償版 を使ってみた - tkkochanの日記
http://d.hatena.ne.jp/tkkochan/20090407/1239070236
 
XenServerを導入してみた: 出張デコパパ日記
http://fragment.moe-nifty.com/dekopa/2009/04/xenserver-3b9b.html