Some more nand-sata-install fixes

This commit is contained in:
ThomasKaiser 2017-09-05 11:00:58 -07:00
parent 66b088ff7e
commit 313f10240c

View file

@ -57,8 +57,13 @@ create_armbian()
# create mount points, mount and clean
TempDir=$(mktemp -d /mnt/${0##*/}.XXXXXX || exit 1)
sync && mkdir -p ${TempDir}/bootfs ${TempDir}/rootfs
[[ -n $1 ]] && mount ${1::-1}"1" ${TempDir}/bootfs
[[ -n $2 ]] && ( mount -o compress-force=zlib $2 ${TempDir}/rootfs || mount $2 ${TempDir}/rootfs )
if [[ $eMMCFilesystemChoosen == "btrfs" ]]; then
[[ -n $1 ]] && mount ${1::-1}"1" ${TempDir}/bootfs
[[ -n $2 ]] && ( mount -o compress-force=zlib $2 ${TempDir}/rootfs || mount $2 ${TempDir}/rootfs )
else
[[ -n $2 ]] && mount $2 ${TempDir}/rootfs
[[ -n $1 ]] && mount $1 ${TempDir}/bootfs
fi
rm -rf ${TempDir}/bootfs/* ${TempDir}/rootfs/*
# sata root part
@ -69,6 +74,14 @@ create_armbian()
# UUID=xxx...
sduuid=$(blkid -o export /dev/mmcblk*p1 | grep -w UUID | grep -v "$root_partition_device")
# write information to log
echo -e "\nOld UUID: ${root_uuid}" >> $logfile
echo "SD UUID: $sduuid" >> $logfile
echo "SATA UUID: $satauuid" >> $logfile
echo "eMMC UUID: $emmcuuid $eMMCFilesystemChoosen" >> $logfile
echo "Boot: \$1 $1 $eMMCFilesystemChoosen" >> $logfile
echo "Root: \$2 $2 $FilesystemChoosen" >> $logfile
# calculate usage and see if it fits on destination
USAGE=$(df -BM | grep ^/dev | head -1 | awk '{print $3}' | tr -cd '[0-9]. \n')
DEST=$(df -BM | grep ^/dev | grep ${TempDir}/rootfs | awk '{print $4}' | tr -cd '[0-9]. \n')
@ -84,13 +97,7 @@ create_armbian()
rsync -aqc $BOOTLOADER/* ${TempDir}/bootfs
fi
# write stuff to log
echo -e "\nOld UUID: ${root_uuid}" >> $logfile
echo "SD UUID: $sduuid" >> $logfile
echo "SATA UUID: $satauuid" >> $logfile
echo "eMMC UUID: $emmcuuid $eMMCFilesystemChoosen" >> $logfile
echo "Boot: \$1 $1 $eMMCFilesystemChoosen" >> $logfile
echo "Root: \$2 $2 $FilesystemChoosen" >> $logfile
# write information to log
echo "Usage: $USAGE" >> $logfile
echo -e "Dest: $DEST\n\n/etc/fstab:" >> $logfile
cat /etc/fstab >> $logfile
@ -104,20 +111,21 @@ create_armbian()
StopRunningServices "nfs-|smbd|nmbd|winbind|ftpd|netatalk|monit|cron|webmin|rrdcached" >> $logfile
StopRunningServices "log2ram|folder2ram|postgres|mariadb|mysql|postfix|mail|nginx|apache|snmpd" >> $logfile
pkill dhclient 2>/dev/null
LANG=C echo -e "\n\nAgain checking for open files:" >> $logfile
LANG=C echo -e "\n\nChecking again for open files:" >> $logfile
lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
# count files is needed for progress bar
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 40
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Counting files ... few seconds." 5 60
TODO=$(rsync -ahvrltDn --delete --stats --exclude-from=$EX_LIST / ${TempDir}/rootfs | grep "Number of files:"|awk '{print $4}' | tr -d '.,')
echo -e "\nCopying ${TODO} files to $2. \c" >> $logfile
# creating rootfs
rsync -avrltD --delete --exclude-from=$EX_LIST / ${TempDir}/rootfs | nl | awk '{ printf "%.0f\n", 100*$1/"'"$TODO"'" }' \
| dialog --backtitle "$backtitle" --title "$title" --gauge "\n\n Creating rootfs on $2 ($USAGE MB). \n\n \
This will take around $((USAGE/60)) minutes to finish. Please wait!\n\n" 11 80
| dialog --backtitle "$backtitle" --title "$title" --gauge "\n\n Transferring rootfs to $2 ($USAGE MB). \n\n \
This will take approximately $(( $((USAGE/300)) * 5 )) minutes to finish. Please wait!\n\n" 11 80
# run rsync again to silently catch outstanding changes between / and ${TempDir}/rootfs/
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... few seconds." 5 40
dialog --title "$title" --backtitle "$backtitle" --infobox "\n Cleaning up ... Almost done." 5 40
rsync -avrltD --delete --exclude-from=$EX_LIST / ${TempDir}/rootfs >/dev/null 2>&1
# creating fstab from scratch
@ -132,7 +140,7 @@ create_armbian()
# creating fstab, kernel and boot script for NAND partition
#
if [[ $1 == *nand* ]]; then
echo -e "\nInstall to NAND" >> $logfile
echo "Finishing installation to NAND." >> $logfile
REMOVESDTXT="and remove SD to boot from NAND"
echo "$1 /boot vfat defaults 0 0" >> ${TempDir}/rootfs/etc/fstab
echo "$2 / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1" >> ${TempDir}/rootfs/etc/fstab
@ -171,14 +179,14 @@ create_armbian()
if [[ $2 == ${SDA_ROOT_PART} ]]; then
local targetuuid=$satauuid
local choosen_fs=$FilesystemChoosen
echo -e "\nBoot on eMMC, root on USB/SATA" >> $logfile
echo "Finalizing: boot from eMMC, rootfs on USB/SATA." >> $logfile
if [[ $eMMCFilesystemChoosen == "btrfs" ]]; then
echo "$emmcuuid /media/mmcroot $eMMCFilesystemChoosen ${mountopts[$eMMCFilesystemChoosen]}" >> ${TempDir}/rootfs/etc/fstab
fi
else
local targetuuid=$emmcuuid
local choosen_fs=$eMMCFilesystemChoosen
echo -e "\nFull install to eMMC" >> $logfile
echo "Finishing full install to eMMC." >> $logfile
fi
# fix that we can have one exlude file
@ -223,7 +231,7 @@ create_armbian()
# Boot from SD card, root = SATA / USB
#
if [[ $2 == ${SDA_ROOT_PART} && -z $1 ]]; then
echo -e "\nInstall to USB/SATA, boot from SD" >> $logfile
echo -e "Finishing transfer to USB/SATA, boot from SD/eMMC" >> $logfile
[[ -f /boot/boot.cmd ]] && sed -e 's,root='"$root_uuid"',root='"$satauuid"',g' -i /boot/boot.cmd
[[ -f /boot/boot.ini ]] && sed -e 's,^setenv rootdev.*$,setenv rootdev "'"$satauuid"'",' -i /boot/boot.ini
# new boot scripts
@ -248,7 +256,9 @@ create_armbian()
mkswap ${TempDir}/rootfs/var/swap
fi
LANG=C echo -e "\n$(date): Finished" >> $logfile
echo -e "\nChecking again for open files:" >> $logfile
lsof / | awk 'NR==1 || $4~/[0-9][uw]/' | grep -v "^COMMAND" >> $logfile
LANG=C echo -e "\n$(date): Finished\n\n" >> $logfile
cat $logfile >${TempDir}/rootfs${logfile}
sync
@ -474,7 +484,7 @@ main()
umount ${TempDir}/bootfs
;;
2)
title="$ichip boot / SATA root install"
title="$ichip boot | USB/SATA root install"
command="Power off"
checksatatarget
ShowWarning "This script will erase your $ichip and $SDA_ROOT_PART. Continue?"
@ -492,7 +502,7 @@ main()
umount ${TempDir}/bootfs
;;
3)
title="SD boot / SATA root install"
title="MMC (SD/eMMC) boot | USB/SATA root install"
command="Reboot"
checksatatarget
ShowWarning "This script will erase your device $SDA_ROOT_PART. Continue?"
@ -519,7 +529,7 @@ main()
esac
done
dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label "Exit" --yesno "\nAll done. $command $REMOVESDTXT" 7 60
dialog --title "$title" --backtitle "$backtitle" --yes-label "$command" --no-label "Exit" --yesno "\nAll done. $command $REMOVESDTXT" 7 70
[[ $? -eq 0 ]] && "$(echo ${command,,} | sed 's/ //')"
} # main