Advertisement
Guest User

Untitled

a guest
Oct 7th, 2019
471
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Clone drive partition table
  4. sfdisk -d /dev/sda | sfdisk /dev/sdb
  5.  
  6. # Create degraded RAIDs, format, and mount
  7. mdadm --create /dev/md0 -l raid1 -f -n 1 /dev/sdb3
  8. mdadm --create /dev/md1 -l raid1 -f -n 1 /dev/sdb4
  9. mdadm --detail --scan > /etc/mdadm.conf
  10. mkfs.ext4 /dev/md0
  11. mkswap /dev/md1
  12. if [ ! -d "/mnt/md0" ]; then
  13.     mkdir /dev/md0
  14. fi
  15. mount /dev/md0 /mnt/md0
  16.  
  17. # Get Blkid of EXT4
  18. NEWROOTUUID=`blkid -o udev /dev/md0 | grep ID_FS_UUID= | sed 's/ID_FS_UUID=//'`
  19. OLDROOTUUID=`blkid -o udev /dev/sda3 | grep ID_FS_UUID= | sed 's/ID_FS_UUID=//'`
  20. NEWSWAPUUID=`blkid -o udev /dev/md1 | grep ID_FS_UUID= | sed 's/ID_FS_UUID=//'`
  21. OLDSWAPUUID=`blkid -o udev /dev/sda4 | grep ID_FS_UUID= | sed 's/ID_FS_UUID=//'`
  22. echo "Root UUID: Old $OLDROOTUUID  -  New $NEWROOTUUID"
  23. echo "Swap UUID: Old $OLDSWAPUUID  -  New $NEWSWAPUUID"
  24.  
  25. # Make appropriate config file changes
  26. cp /etc/fstab /etc/fstab.bak
  27. sed -i "s/$OLDROOTUUID/$NEWROOTUUID/g" /etc/fstab
  28. sed -i "s/LABEL=SWAP/UUID=$NEWSWAPUUID/" /etc/fstab
  29. cp /etc/sysconfig/bootloader /etc/sysconfig/bootloader.bak
  30. sed -i "s/$OLDROOTUUID/$NEWROOTUUID/g" /etc/sysconfig/bootloader
  31. cp /etc/default/grub /etc/default/grub.bak
  32. sed -i "s/$OLDROOTUUID/$NEWROOTUUID/g" /etc/default/grub
  33. grub2-mkconfig -o /boot/grub2/grub.cfg
  34.  
  35.  
  36. # Finally copy the file system and update/install grub2
  37. rsync -avP --numeric-ids --exclude='/dev' --exclude='/proc' --exclude='/sys' --exclude='/mnt' / /mnt/md0
  38. grub2-install /dev/sda
  39. grub2-install /dev/sdb
  40.  
  41. # On reboot, Select OpenSuSE v.15.1 on /dev/md0
  42. # The missing bit of magic
Advertisement
RAW Paste Data Copied
Advertisement