added uuid_fix to rewrite the fstab and mdadm.conf
Kyle Sheumaker [Fri, 21 Sep 2018 19:03:56 +0000 (14:03 -0500)]
etc/cloner3/installer.sh
etc/cloner3/uuid_fix.sh [new file with mode: 0755]

index 559ad27..9008151 100755 (executable)
@@ -203,6 +203,9 @@ then
 else
        fail_msg
 fi
+
+# fix the filesystem UUID issues
+/etc/cloner3/uuid_fix.sh
        
 
 header "Installing bootloader"
@@ -331,6 +334,28 @@ then
                fail_msg
                clone_fatal_error "Failed to run ${EFIBOOTMGR} ${EFIARGS}"
        fi
+
+       GRUB_MKCONFIG=""
+       GRUB2_CONFIG="/etc/grub2-efi.cfg"
+       if [ -x /cloner/mnt/sbin/grub2-mkconfig ]
+        then
+               GRUB_MKCONFIG="/sbin/grub2-mkconfig "
+        elif  [ -x /cloner/mnt/usr/sbin/grub2-mkconfig ]
+        then
+                GRUB_MKCONFIG="/usr/sbin/grub2-mkconfig "
+       fi
+
+       msg -n "Creating grub2 config file ${GRUB2_CONFIG}"
+       server_log "Creating grub2 config file ${GRUB2_CONFIG}" "${_node}"
+       chroot /cloner/mnt ${GRUB_MKCONFIG} -o ${GRUB2_CONFIG} >> /tmp/stdout.log 2>> /tmp/stderr.log
+       if [ "$?" = "0" ]
+       then
+               ok_msg
+       else
+               fail_msg
+               clone_fatal_error "Failed to create grub2 config file"
+       fi
+
 fi
 
 # if a post install script exists we execute it
diff --git a/etc/cloner3/uuid_fix.sh b/etc/cloner3/uuid_fix.sh
new file mode 100755 (executable)
index 0000000..b484356
--- /dev/null
@@ -0,0 +1,123 @@
+#!/bin/sh
+
+. /etc/library.sh
+. /etc/cloner3/include.sh
+. /etc/cloner3/cloner_server.sh
+. /tmp/cmdline.dat
+
+ORG_UUID_FILE="/cloner/setup/device_uuid"
+NEW_UUID_FILE="/tmp/dest_uuid_map"
+
+blkid > /tmp/dest_uuid_map
+
+new_uuid_by_device() {
+       DEVICE=$1
+
+       RESULT=$(grep "^${DEVICE}:" ${NEW_UUID_FILE})
+       UUID=$(echo ${RESULT} | cut -d" " -f2 | sed 's/\"//g' | sed 's/^UUID=//i' )
+
+       echo ${UUID}
+}
+
+old_uuid_by_device() {
+       DEVICE=$1
+
+       RESULT=$(grep "^${DEVICE}:" ${ORG_UUID_FILE})
+       UUID=$(echo ${RESULT} | cut -d" " -f2 | sed 's/\"//g' | sed 's/^UUID=//i' )
+
+       echo ${UUID}
+}
+
+new_uuid_by_old_uuid() {
+       UUID=$1
+
+       # grep for the UUID and get the last one
+       RESULT=$(grep "UUID=\"${UUID}\"" ${ORG_UUID_FILE} | tail -1)
+       SRC_DEVICE=$(echo ${RESULT} | cut -d":" -f1)
+
+       NEW_UUID=$(new_uuid_by_device ${SRC_DEVICE})
+
+       echo ${NEW_UUID}
+}
+
+
+convert_fstab() {
+
+       SRC=$1
+       DEST=$2
+       
+       while read line
+       do
+               DEVICE=$(echo ${line} | awk '{print $1}')
+               REST=$(echo ${line} | awk '{$1 = ""; print $0}')
+               IS_UUID=$(echo ${DEVICE} | grep "^UUID=")
+
+               if [ "${IS_UUID}" != "" ]
+               then
+                       OLD_UUID=$(echo ${DEVICE} | sed 's/UUID=//' | sed 's/\"//g')
+
+                       msg -n "Looking for replacement for ${ANSI_BLUE}${OLD_UUID}${ANSI_DONE}"
+                       NEW_UUID=$(new_uuid_by_old_uuid ${OLD_UUID})
+                       if [ "${NEW_UUID}" = "" ]
+                       then
+                               clone_fatal_error "Can't find new UUID for ${DEVICE}"
+                               return 1
+                       fi
+                       msg -n " found ${ANSI_BLUE}${NEW_UUID}${ANSI_DONE}"
+                       ok_msg
+
+                       echo "UUID=${NEW_UUID} ${REST}" >> ${DEST}
+               else 
+                       echo ${line} >> ${DEST}
+               fi
+
+       done < ${SRC}
+}
+
+header "Updating mdadm.conf with new UUIDs"
+if [ -e "/cloner/mnt/etc/mdadm.conf" ]
+then
+       
+       msg -n "Updating configuration file ${ANSI_BLUE}/etc/mdadm.conf${ANSI_DONE}"
+       server_log "Updating /etc/mdadm.conf configuration" "${_node}"
+       grep -v "^ARRAY" /cloner/mnt/etc/mdadm.conf" > /tmp/new-mdadm.conf
+       echo "### AUTOGENERATED BY CLONER ON `date`" >> /tmp/new-mdadm.conf
+       mdadm --detail --scan >> /tmp/new-mdadm.conf
+       mv /tmp/new-mdadm.conf /cloner/mnt/etc/mdadm.conf
+       ok_msg
+
+       if [ -e /cloner/mnt/usr/sbin/dracut ]
+       then
+               for kver in `ls -1 /cloner/mnt/lib/modules`
+               do
+                       msg -n "Updating dracut for kernel ${ANSI_BLUE}${kver}${ANSI_DONE}
+                       chroot /cloner/mnt /usr/sbin/dracut -f --kver=${kver} \
+                               >> /tmp/stdout.log 2> /tmp/stderr.log
+
+                       if [ "$?" = "0" ]
+                       then
+                               ok_msg
+                       else
+                               clone_fatal_error "Can't update initrd for ${kver} with dracut"
+                       fi
+               done
+       fi
+
+fi
+
+if [ ! -e ${ORIG_UUID_FILE} ]
+then
+       exit 0
+fi
+
+header_msg "Updating UUIDs in /etc/fstab"
+convert_fstab /cloner/mnt/etc/fstab /tmp/fstab.converted
+if [ "$?" != "0" ]
+then
+       clone_fatal_error "Can't convert UUIDs from old fstab to new."
+fi
+if [ -e /tmp/fstab.converted ]
+       mv /tmp/fstab.converted /cloner/mnt/etc/fstab
+fi
+
+return 0