From a3a743ecb2a96ade123b1237716bd489625b7825 Mon Sep 17 00:00:00 2001 From: Henning Heinold Date: Tue, 26 Aug 2014 18:06:36 +0200 Subject: [PATCH 1/2] initramfs: set baudrate for grub from cmdline * take the baudrate for the grub serial console setting from the kernel-cmdline which the system was booted from * better parsing of the options which the install-script gets from init * Video Mode, VGA mode are not used right now and make it empty right now. --- .../initrdscripts/files/init-install.sh | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/recipes-core/initrdscripts/files/init-install.sh b/recipes-core/initrdscripts/files/init-install.sh index 0a02368..2399a24 100644 --- a/recipes-core/initrdscripts/files/init-install.sh +++ b/recipes-core/initrdscripts/files/init-install.sh @@ -9,9 +9,32 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin # We want a 1 Gig partition on the cf partition_size=1000 +# Parse original arguments coming from the kernel cmdline. +# Then shift the first two arguments which contains +# partition information. +dev_name=$1 +shift +image_name=$1 +shift + +kernel_cmdline_console="" +kernel_cmdline_video_mode="" +kernel_cmdline_vga_mode="" + +while [ "$1" != "" ]; do + + echo "$1" | grep -q "console=" + success_console=$? + if [ $success_console -eq 0 ]; then + kernel_cmdline_console=$1 + fi + shift + +done + # Get a list of hard drives hdnamelist="" -live_dev_name=${1%%/*} +live_dev_name=${dev_name%%/*} echo "Searching for hard drives ..." @@ -120,7 +143,7 @@ mkdir /tgt_root mkdir -p /boot echo "Copying rootfs files..." -dd if=/media/$1/$2 of=$rootfs bs=1024 +dd if=/media/$dev_name/$image_name of=$rootfs bs=1024 # Handling of the target root partition mount $rootfs /tgt_root @@ -139,11 +162,13 @@ echo "Preparing boot partition..." GRUBCFG="/boot/grub/grub.cfg" mkdir -p $(dirname $GRUBCFG) +baudrate=`echo $kernel_cmdline_console | cut -f 2 -d ',' | cut -f 1 -d 'n'` + cat > $GRUBCFG << EOF default=0 timeout=1 -serial --unit=0 --speed=38400 +serial --unit=0 --speed=$baudrate terminal --timeout=2 serial terminal_input --append serial @@ -155,9 +180,9 @@ if [ -f /etc/grub.d/40_custom ] ; then cat /etc/grub.d/40_custom >> $GRUBCFG sed -i "s@__ROOTFS__@$rootfs $rootwait@g" $GRUBCFG - sed -i "s/__VIDEO_MODE__/$3/g" $GRUBCFG - sed -i "s/__VGA_MODE__/$4/g" $GRUBCFG - sed -i "s/__CONSOLE__/$5/g" $GRUBCFG + sed -i "s/__VIDEO_MODE__/$kernel_cmdline_video_mode/g" $GRUBCFG + sed -i "s/__VGA_MODE__/$kernel_cmdline_vga_mode/g" $GRUBCFG + sed -i "s/__CONSOLE__/$kernel_cmdline_console/g" $GRUBCFG sed -i "s/quiet/net.ifnames=0 quiet/g" $GRUBCFG sed -i "s/rw/ro/g" $GRUBCFG sed -i "/#/d" $GRUBCFG From 7a09426da5f120ec64fbd31c01707d5f8b2f9b04 Mon Sep 17 00:00:00 2001 From: Henning Heinold Date: Tue, 26 Aug 2014 19:57:53 +0200 Subject: [PATCH 2/2] initramfs: restore configuration if available The error case of the backup not properly restoring has not been tested. Fixes: SYS#525 --- .../initrdscripts/files/init-install.sh | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/recipes-core/initrdscripts/files/init-install.sh b/recipes-core/initrdscripts/files/init-install.sh index 2399a24..4b8919b 100644 --- a/recipes-core/initrdscripts/files/init-install.sh +++ b/recipes-core/initrdscripts/files/init-install.sh @@ -200,7 +200,28 @@ umount /tgt_root echo "Resizing partition" e2fsck -f $rootfs || true resize2fs $rootfs +sync +echo "Re-mounting the root and trying to apply backup." +mount $rootfs /tgt_root + +echo "Finding backupfiles" +backupfile=`find /media/$dev_name/ -name "sysmocom-backup*.tar" | head -n1` +if [ -n "$backupfile" ]; then + if [ ! -r "$backupfile" ]; then + echo "configurations-file $backupfile it is not readable" + else + echo "restoring $backupfile" + backupfile_basename=`basename $backupfile` + cp $backupfile /tgt_root + chroot /tgt_root /usr/sbin/sysmocom-restore $backupfile_basename + rm /tgt_root/$backupfile_basename + fi +else + echo "No configurations-file found" +fi + +umount /tgt_root sync echo "Remove your installation media, and press ENTER"