среда, 13 декабря 2017 г.

How to move virtuozzo 7 on packet.net to software raid1

After installation Type 1 node on packet.net we have same scheme block device:
lsblk 
NAME              MAJ:MIN    RM   SIZE RO TYPE  MOUNTPOINT
sda                 8:0       0 223.6G  0 disk  
├─sda1              8:1       0     2M  0 part  
├─sda2              8:2       0   256M  0 part  /boot
├─sda3              8:3       0     8G  0 part  [SWAP]
└─sda4              8:4       0 215.3G  0 part  /
sdb                 8:16      0 223.6G  0 disk  
└─mpathb          253:0       0 223.6G  0 mpath 
ploop17991        182:287856  0    10G  0 disk  
└─ploop17991p1    182:287857  0    10G  0 part  /vz/pfcache

Check disk labels:

fdisk -l /dev/sda
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: C63AA19D-6E91-4A1E-976D-899D800EC489


#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot parti BIOS
 2         6144       530431    256M  Linux filesyste BOOT
 3       530432     17307647      8G  Linux filesyste SWAP
 4     17307648    468862094  215.3G  Linux filesyste ROOT
fdisk -l /dev/sdb

Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

and create gpt label on /dev/sdb:

parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) q                                                                
Information: You may need to update /etc/fstab.

fdisk -l /dev/sdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: 2F21C828-C60E-4DBD-AC6B-DDA2B119B92D
#         Start          End    Size  Type            Name


Now create partitions on /dev/sdb like /dev/sda but need set Type RAID for all partitions except BIOS boot  partiotions:

fdisk -l /dev/sda
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sda: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: C63AA19D-6E91-4A1E-976D-899D800EC489


#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot parti BIOS
 2         6144       530431    256M  Linux filesyste BOOT
 3       530432     17307647      8G  Linux filesyste SWAP
 4     17307648    468862094  215.3G  Linux filesyste ROOT
fdisk /dev/sdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: 2F21C828-C60E-4DBD-AC6B-DDA2B119B92D


#         Start          End    Size  Type            Name

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-468862094, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-468862094, default 468862094): 6143
Created partition 1


Command (m for help): n
Partition number (2-128, default 2): 2
First sector (34-468862094, default 6144): 
Last sector, +sectors or +size{K,M,G,T,P} (6144-468862094, default 468862094): 530431
Created partition 2


Command (m for help): n
Partition number (3-128, default 3): 3
First sector (34-468862094, default 530432): 
Last sector, +sectors or +size{K,M,G,T,P} (530432-468862094, default 468862094): 17307647
Created partition 3


Command (m for help): n
Partition number (4-128, default 4): 4
First sector (34-468862094, default 17307648): 
Last sector, +sectors or +size{K,M,G,T,P} (17307648-468862094, default 468862094): 468862094
Created partition 4


Command (m for help): t
Partition number (1-4, default 4): 1
Partition type (type L to list all types): 3
Changed type of partition 'Linux filesystem' to 'BIOS boot partition'

Command (m for help): t
Partition number (1-4, default 4): 2
Partition type (type L to list all types): 13
Changed type of partition 'Linux filesystem' to 'Linux RAID'

Command (m for help): t
Partition number (1-4, default 4): 3
Partition type (type L to list all types): 13
Changed type of partition 'Linux filesystem' to 'Linux RAID'

Command (m for help): t
Partition number (1-4, default 4): 4
Partition type (type L to list all types): 13
Changed type of partition 'Linux filesystem' to 'Linux RAID'

Command (m for help): p

Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: 2F21C828-C60E-4DBD-AC6B-DDA2B119B92D


#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot parti 
 2         6144       530431    256M  Linux RAID      
 3       530432     17307647      8G  Linux RAID      
 4     17307648    468862094  215.3G  Linux RAID      

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

Calling ioctl() to re-read partition table.
Syncing disks.


reboot hard node and list block devices:

lsblk 
NAME              MAJ:MIN    RM   SIZE RO TYPE  MOUNTPOINT
sda                 8:0       0 223.6G  0 disk  
├─sda1              8:1       0     2M  0 part  
├─sda2              8:2       0   256M  0 part  /boot
├─sda3              8:3       0     8G  0 part  [SWAP]
└─sda4              8:4       0 215.3G  0 part  /
sdb              8:16      0 223.6G  0 disk  
├─sdb1           8:17      0     2M  0 part  
├─sdb2           8:18      0   256M  0 part  
│ └─md0          9:0       0 255.7M  0 raid1 /boot
├─sdb3           8:19      0     8G  0 part  
│ └─md1          9:1       0     8G  0 raid1 [SWAP]
└─sdb4           8:20      0 215.3G  0 part  
  └─md2          9:2       0 215.2G  0 raid1 /
  

Now create raid :


mdadm --create /dev/md0 --level=1 --raid-devices=2 missing /dev/sdb2 
mdadm --create /dev/md1 --level=1 --raid-devices=2 missing /dev/sdb3 
mdadm --create /dev/md2 --level=1 --raid-devices=2 missing /dev/sdb4 


and make ext4 file system and swap:


mkfs.ext4 /dev/md0
mkfs.ext4 /dev/md2     
mkswap  /dev/md1

mount raid partitions and copy source and target :

mount /dev/md1 /mnt/
rsync -axu / /mnt/
mount /dev/md0 /mnt/boot/
rsync -axu /boot/ /mnt/boot/

Now mount and chroot :

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


Get blkid for md devices 

blkid | grep md
/dev/md1: UUID="68f122be-c9e3-4b55-ae59-140ba641ba57" TYPE="swap" 
/dev/md0: UUID="029cce04-6af9-49ac-b904-9c524e89af69" TYPE="ext4" 
/dev/md2: UUID="3f5bb96b-4803-49f8-aefc-f04f92586471" TYPE="ext4" 

and put it into /etc/fstab instead old's for / , /boot , swap


Create mdadm.conf :

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


save current initrd and run dracut :

 mv /boot/initramfs-3.10.0-693.1.1.vz7.37.30.img /boot/initramfs-3.10.0-693.1.1.vz7.37.30.img.bak
 dracut /boot/initramfs-$(uname -r).img $(uname -r)

Add value  rd.auto=1 in /etc/default/grub to parameter GRUB_CMDLINE_LINUX:

GRUB_CMDLINE_LINUX="console=ttyS1,115200n8 crashkernel=auto console=ttyS1,115200n8,rd.auto=1"



Generate new grub.cfg 


grub2-mkconfig -o /boot/grub2/grub.cfg

and write new grub on both disks:

grub2-install /dev/sdb
grub2-install /dev/sda

exit from chroot and umount resources :

umount /mnt/run
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev
umount /mnt/boot
umount /mnt 

Reboot hard node and change type partitions for /dev/sda like /dev/sdb :

fdisk -l /dev/sda
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt

#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot parti BIOS
 2         6144       530431    256M  Linux RAID      BOOT
 3       530432     17307647      8G  Linux RAID      SWAP
 4     17307648    468862094  215.3G  Linux RAID      ROOT

fdisk -l /dev/sdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt

#         Start          End    Size  Type            Name
 1         2048         6143      2M  BIOS boot parti 
 2         6144       530431    256M  Linux RAID      
 3       530432     17307647      8G  Linux RAID      
 4     17307648    468862094  215.3G  Linux RAID  

Then add sdaX partition to raid :
mdadm --manage /dev/md0 --add /dev/sda2
mdadm --manage /dev/md1 --add /dev/sda3
mdadm --manage /dev/md2 --add /dev/sda4


Комментариев нет:

Отправить комментарий