Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # https://kamaok.org.ua/?p=182
- # http://blog.ispsystem.info/2016/11/centos-68-raid1-mdadm.html
- #
- ########################################
- #
- EXIT(){
- [[ -n "${2}" ]] && echo "${2}"
- exit "${1}"
- }
- MSG(){
- echo "___________________________________________________"
- echo
- echo " $*"
- echo
- }
- EDITOR="mcedit"
- SRC="/dev/sda"
- TRGT="/dev/sdb"
- B="1" # /boot
- R="2" # / (root FS)
- RDEV=$(grep ^/dev/ /etc/mtab | while read -a i ; do
- [[ "${i[1]}" == "/" ]] && echo "${i[0]}" | sed "s/\//\\\\\//g"
- done)
- [[ -n "${RDEV}" ]] || EXIT 1 "Error: root device not found"
- [[ -b "${TRGT}" ]] || EXIT 1 "Error: ${TRGT} not found"
- [[ -n $(grep "^${SRC}" /etc/mtab) ]] || EXIT 1 "Error: root drive not ${SRC}"
- ########################################
- #
- sfdisk -d "${SRC}" | sfdisk --force "${TRGT}"
- modprobe linear
- modprobe raid0
- modprobe raid1
- ####
- MSG "Linux raid autodetect fd"
- fdisk "${TRGT}"
- MSG "Clear superblocks"
- mdadm --zero-superblock "${TRGT}${B}"
- mdadm --zero-superblock "${TRGT}${R}"
- MSG "Create /dev/md${B} and /dev/md${R}"
- mdadm --create /dev/md"${B}" --metadata=0.90 --level=1 --raid-disks=2 missing "${TRGT}${B}"
- mdadm --create /dev/md"${R}" --metadata=0.90 --level=1 --raid-disks=2 missing "${TRGT}${R}"
- mdadm --detail --scan > /etc/mdadm.conf
- MSG "Mkfs /dev/md${B} and /dev/md${R}"
- mkfs.ext4 /dev/md"${B}"
- mkfs.ext4 /dev/md"${R}"
- #### / (root FS)
- MSG "Mount RootFS"
- mkdir /raid
- mount /dev/md"${R}" /raid/ || EXIT 1 "Mount /dev/md${R} failed"
- MSG "Copy RootFS"
- cd /
- find . -depth -xdev | grep -v '^\./tmp/' | cpio -pmd /raid/
- blkid /dev/md? >> /raid/etc/fstab
- "${EDITOR}" /raid/etc/fstab
- touch /raid/.autorelabel
- #### /boot
- MSG "Mount boot"
- mount /dev/md"${B}" /raid/boot/
- MSG "Copy boot"
- cd /boot/
- find . -depth | cpio -pmd /raid/boot/
- sed -i "s/"${RDEV}"/\/dev\/md"${R}"/g" /raid/boot/grub/grub.conf
- # blkid /dev/md? >> /raid/boot/grub/grub.conf
- # remove rd_NO_DM rd_NO_MD
- # remove VolGroup-lv_root and other
- # add rd_MD_UUID=b9baa472:faeb3a7c:6e31c5b6:310ac827 ?
- "${EDITOR}" /raid/boot/grub/grub.conf
- # (hd0) /dev/sda
- # (hd1) /dev/sdb
- "${EDITOR}" /raid/boot/grub/device.map
- ####
- mount -o bind /dev /raid/dev
- mount -o bind /sys /raid/sys
- mount -o bind /proc /raid/proc
- ####
- MSG "Create initramfs"
- mv /raid/boot/initramfs-$(uname -r).img /raid/boot/initramfs-$(uname -r).img.old
- dracut --nolvmconf --mdadmconf --force /raid/boot/initramfs-$(uname -r).img $(uname -r)
- MSG "Setup grub into chroot and reboot system
- type:
- chroot /raid/"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement