Anda di halaman 1dari 5

Creating a Raid On A Xenserver 6.

2
The command below display basic partition summary data. This includes
partition
numbers, starting and ending sector numbers, partition sizes,
sgdisks

partition

types codes, and partition names.

[root@flock /]# sgdisk -p /dev/sda


Disk /dev/sda: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 5091FFD8-6EE9-433B-8173-04181CEFFAA8
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 6042 sectors (3.0 MiB)

Number

Start (sector)

End (sector)

Size

Code

2048

8388641

4.0 GiB

0700

8390656

16777249

4.0 GiB

0700

16779264

1953525134

923.5 GiB

8E00

Name

The command below --zap-all (destroy) the GPT and MBR data structures
then exit.
This option works much like -z, but as it wipes the MBR as well

and

as the GPT, its more suitable if you want to repartition a disk


after

using

this

option,

and completely unsuitable if youve

already repartitioned the disk.


sgdisk --zap-all /dev/sdb
The command below convert an MBR or BSD disklabel disk to a GPT disk. As a
safety
measure, use of this option is required on MBR or BSD disklabel
disks

if

you

intend to save your changes, in order to prevent

accidentally damaging such disks.


sgdisk --mbrtogpt --clear /dev/sdb

sgdisk -p /dev/sdb
[root@flock /]# sgdisk -p /dev/sdb
Disk /dev/sdb: 1953525168 sectors, 931.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): C8C73907-8167-4AAC-AF48-6C75A0F666D0
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 1953525134
Partitions will be aligned on 2048-sector boundaries
Total free space is 1953525101 sectors (931.5 GiB)

Below I create

new partition. You enter a partition number, starting

sector, and an ending sector. Both start and end sectors can
specified

in

absolute

be

terms as sector numbers or as positions

measured in kilobytes (K), megabytes (M), gigabytes (G), or terabytes

(T);

for

instance, 40M specifies a position 40MiB from

the start of the disk. You can specify locations relative to the
start

or

end

of

the specified default range by preceding the

number by a + or - symbol, as in +2G to specify a point 2GiB


after

the

default

start

sector,

or -200M to specify a point

200MiB before the last available sector. Pressing the Enter

key

with no input specifies the default value, which is the start of


the largest available block for the start sector and the end
the same block for the end sector.
Number
sgdisk
sgdisk
sgdisk
sgdisk
sgdisk
sgdisk

Start (sector)

End (sector)

Size

--new=1:2048:8388641 /dev/sdb
--typecode=1:fd00 /dev/sdb
--attributes=1:set:2 /dev/sdb
--new=2:8390656:16777249 /dev/sdb
--typecode=2:fd00 /dev/sdb
new=3:16779264:1953525134 /dev/sdb

Code

Name

of

sgdisk --typecode=3:fd00 /dev/sdb

Now Reboot
After the reboot create the raid:
mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb2
mdadm --create /dev/md2 --level=1 --raid-devices=2 missing /dev/sdb3
These's command below will format, mount and copy. Make sure you are in / when
you run these commands.
mkfs.ext3 /dev/md0
mount /dev/md0 /mnt
cp -vxpR / /mnt

This will replace what ever is currently in fstab with /dev/md0:


sed -i 's/LABEL=[a-zA-Z\-]*/\/dev\/md0/' /mnt/etc/fstab
This will Create a new boot image and uncompress it. You should still be in /
until tell you cd to another folder.
mkdir /mnt/root/initrd-raid
mkinitrd -v --fstab=/mnt/etc/fstab /mnt/root/initrd-raid/initrd-`uname -r`-raid.img `uname -r`

cd /mnt/root/initrd-raid
zcat initrd-`uname -r`-raid.img | cpio -i
Edit init and insert raidautorun :
sed -i 's/raidautorun \/dev\/md0/raidautorun \/dev\/md0\nraidautorun \/dev\/md1\nraidautorun
\/dev\/md2/' init

This copy the new ramdisk to the new location.


find . -print | cpio -o -Hnewc | gzip -c > /mnt/boot/initrd-`uname -r`-raid.img

rm /mnt/boot/initrd-2.6-xen.img
cd /mnt/boot
ln -s initrd-`uname -r`-raid.img initrd-2.6-xen.img
Replace in /mnt/boot/extlinux.conf string root=LABEL=root- to
root=/dev/md0 in all menu entries.
sed -i 's/LABEL=[a-zA-Z\-]*/\/dev\/md0/' extlinux.conf
Set up MBR for GPT on /dev/sdb
cat /mnt/usr/share/syslinux/gptmbr.bin > /dev/sdb
cd /mnt
extlinux --raid -i boot/
Reboot (IMPORTANT: Set your server to boot from the SECONDARY HDD before booting!)
When XenServer is up again, include /dev/sda in the array with the following commands:
sgdisk --attributes=1:set:2 /dev/sda
sgdisk --typecode=1:fd00 /dev/sda
sgdisk --typecode=2:fd00 /dev/sda
sgdisk --typecode=3:fd00 /dev/sda
mdadm -a /dev/md0 /dev/sda1
mdadm -a /dev/md1 /dev/sda2
mdadm -a /dev/md2 /dev/sda3

When trying to add /dev/sda3 to /dev/md2 array and you encountered an error:
mdadm: Cannot open /dev/sda3: Device or resource busy
To fix it I had to do these commands:
xe sr-list
Below is the display from this command:
[root@flock ~]# xe sr-list
uuid ( RO)

: 066c92ea-52cd-1b34-de7b-ce16376c3afb
name-label ( RW): DVD drives

name-description ( RW): Physical DVD drives


host ( RO): flock
type ( RO): udev
content-type ( RO): iso

uuid ( RO)

: 1773cdf2-69e3-ab30-6559-832b9fb2885d
name-label ( RW): Local storage

name-description ( RW):
host ( RO): flock
type ( RO): lvm
content-type ( RO): user

uuid ( RO)

: 2260f315-6cf1-6ce4-7a9a-e6a6410be3d2
name-label ( RW): Removable storage

name-description ( RW):
host ( RO): flock
type ( RO): udev
content-type ( RO): disk

uuid ( RO)

: 848b9e96-df82-cd17-bba8-1a23e5adf830

name-label ( RW): XenServer Tools


name-description ( RW): XenServer Tools ISOs
host ( RO): flock
type ( RO): iso
content-type ( RO): iso
Find Your local storage uuid:
The uuid might look like: dce9fc00-3cd9-92c7-be04-be29382dca7f
2) Find uuid of PDB connected to Your local storage (sr-uuid is Your
local storage uuid):
xe pbd-list sr-uuid=1773cdf2-69e3-ab30-6559-832b9fb2885d
Look for PDB uuid, which is in the first line of the answer.
3) Unplug PDB from local storage:
xe pbd-unplug uuid=PDB_UUID
4) Forget the local storage sr:
xe sr-forget uuid=dce9fc00-3cd9-92c7-be04-be29382dca7f
5) Now add the sda3 to md2 array:
mdadm -a /dev/md2 /dev/sda3
The array needs to complete its initial build/synchronisation. That is gonna take a while. Follow its progress
with: watch -n 1 cat /proc/mdstat
When it finish than do the next step
6) Recreate local storage on md2:
[root@flock ~]# pvcreate --metadatasize 10M /dev/md2
WARNING: software RAID md superblock detected on /dev/md2. Wipe it? [y/n] y
Wiping software RAID md superblock on /dev/md2.
Physical volume "/dev/md2" successfully created
[root@flock ~]# xe sr-create name-label="Local Storage" type=lvm deviceconfig:device=/dev/md2 shared=false

When its done on all three arrays, copy the RAID setup to /etc/mdadm.conf
mdadm --detail --scan >> /etc/mdadm.conf