Merge branch 'hheinold/initramfs_features'

This commit is contained in:
Holger Hans Peter Freyther 2014-09-02 20:25:18 +02:00
commit 2a01e305ca
1 changed files with 52 additions and 6 deletions

View File

@ -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
@ -175,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"