⬆️ ⬇️

Migrating Xenserver 7 to linux raid

Xenserver was recently updated to the seventh version and I, of course, could not pass by.



Among the eye-catching buns (besides migrating to CentOS 7) is another partitioning of the disk with / var / log separately mounted (finally) and a root increased to 20 gigs (hallelujah!).

But he doesn't know how to do when booting a RAID of any level. So, you need to migrate the already installed system again.



image

')

Fortunately, if XenServer is just installed, it is not so bad.





So, I will not give installation manuals - nothing has really changed there. If you install from scratch - during the installation, you do not need to create storages for VMs, we will do them later.



After installation we will have a breakdown like this:



/ (root) 18GB (update) 18GB /boot/efi 512M /var/log 4GB swap 1GB 


0. Remove old



First of all, turn off the existing storage (if there are any):



 xe sr-list xe pbd-list sr-uuid=<local storage-uuid> xe pbd-unplug uuid=<uuid> xe sr-forget uuid=<local storage-uuid> 


Naturally, pv and vg indicate our own, and not just copy-paste;)



Now stop and delete the RAID, if they are in the system:

 mdadm --stop /dev/md0 mdadm --stop /dev/md1 mdadm --stop /dev/md2 mdadm --stop /dev/md3 mdadm --stop /dev/md4 mdadm --stop /dev/md5 mdadm --zero-superblock /dev/sdb1 mdadm --zero-superblock /dev/sdb2 mdadm --zero-superblock /dev/sdb3 mdadm --zero-superblock /dev/sdb4 mdadm --zero-superblock /dev/sdb5 mdadm --zero-superblock /dev/sdb6 


At the same time, you may not have any partitions - for example, I did not have sda4 (apparently because I did not create a repository during installation).



Below, I believe that you have no / dev / sda4 partition.



1. Build new



Remove the partition table on / dev / sdb and copy it from / dev / sda:



 sgdisk --zap-all /dev/sdb sgdisk -R /dev/sdb /dev/sda 


Set the RAID type for partitions:



 sgdisk --typecode=1:fd00 /dev/sdb sgdisk --typecode=2:fd00 /dev/sdb sgdisk --typecode=3:fd00 /dev/sdb sgdisk --typecode=5:fd00 /dev/sdb sgdisk --typecode=6:fd00 /dev/sdb 


Create, in fact, RAID:



 yes|mdadm --create /dev/md0 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb1 missing yes|mdadm --create /dev/md1 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb2 missing yes|mdadm --create /dev/md2 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb3 missing yes|mdadm --create /dev/md3 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb5 missing yes|mdadm --create /dev/md4 --level=1 --raid-devices=2 --metadata=0.90 /dev/sdb6 missing 




Create a new swap partition. It will not live on a RAID, so we will have two.

 mkswap /dev/md4 




Create partitions (root and / var / logs) and mount:

 mkfs.ext3 /dev/md0 mkfs.ext3 /dev/md3 mount /dev/md0 /mnt mkdir -p /mnt/var/log mount /dev/md3 /mnt/var/log 


Copy files to a new section:



 cp -xR --preserve=all / /mnt 


Create the mdadm.conf file:



 echo "MAILADDR root" > /mnt/etc/mdadm.conf echo "auto +imsm +1.x -all" >> /mnt/etc/mdadm.conf echo "DEVICE /dev/sd*[az][1-9]" >> /mnt/etc/mdadm.conf 


 mdadm --detail --scan >> /mnt/etc/mdadm.conf cp /mnt/etc/mdadm.conf /etc 




2. We rule fstab and grub





Change the mount point to RAID:

 sed -i 's/LABEL=root-[a-zA-Z\-]*/\/dev\/md0/' /mnt/etc/fstab sed -i 's/LABEL=swap-[a-zA-Z\-]*/\/dev\/sda6/' /mnt/etc/fstab sed -i 's/LABEL=logs-[a-zA-Z\-]*/\/dev\/md3/' /mnt/etc/fstab sed -i '/sda6/ a\/dev/sdb6 swap swap defaults 0 0 ' /mnt/etc/fstab 




Copy the partition label to / dev / sdb:

 e2label /dev/sda1 |xargs -t e2label /dev/sdb1 




We chroot into our future system:

 mount --bind /dev /mnt/dev mount --bind /sys /mnt/sys mount --bind /proc /mnt/proc mount --bind /run /mnt/run chroot /mnt /bin/bash 




Install the bootloader:

 grub-install /dev/sdb</code>   initrd: <source lang="bash"> dracut --mdadmconf --fstab --add="mdraid" --filesystems "ext3 tmpfs devpts sysfs proc" --add-drivers="raid1 raid456 mdraid1x mdraid09" --force /boot/initrd-$(uname -r).img $(uname -r) -M 




Changing the GRUB configuration to boot from RAID:

 sed -i 's/quiet/rd.auto rd.auto=1 rhgb quiet/' /boot/grub/grub.cfg sed -i 's/LABEL=root-[a-zA-Z\-]*/\/dev\/md0/' /boot/grub/grub.cfg sed -i '/search/ i\ insmod gzio' /boot/grub/grub.cfg sed -i '/search/ i\ insmod part_msdos' /boot/grub/grub.cfg sed -i '/search/ i\ insmod diskfilter mdraid09' /boot/grub/grub.cfg sed -i '/search/ c\ set root=(hd0,gpt1)' /boot/grub/grub.cfg 




Exit the chroot:

 exit 


Reboot. As the boot disk we put the second one, on which we created a RAID. If something goes wrong, there will be a chance to boot from the “old” system and try again.



If everything went well, then rewrite the table from / dev / sdb to / dev / sda:

 sgdisk -R /dev/sda /dev/sdb 




And we add partitions to RAID:

 mdadm -a /dev/md0 /dev/sda1 mdadm -a /dev/md1 /dev/sda2 mdadm -a /dev/md2 /dev/sda3 mdadm -a /dev/md3 /dev/sda5 mdadm -a /dev/md4 /dev/sda6 




Just in case, re-create SWAP and reinstall the bootloader to / dev / sda:

 grub-install /dev/sda 


Reboot again in order to verify that everything was installed correctly.

Well, that's all. Now it remains to connect (or create) data partitions, add (if necessary) them to RAID and create / connect storages:



 xe sr-create content-type=user device-config:device=/dev/md5 host-uuid=<host-uuid> name-label=”SRRaid1-Local” shared=false type=lvm 


This material is a compilation of several howto, found in the vast web. Comments and additions are welcome.

Source: https://habr.com/ru/post/307234/



All Articles