summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Qi <Qi.Chen@windriver.com>2014-06-12 11:27:02 +0800
committerChen Qi <Qi.Chen@windriver.com>2014-06-16 18:36:09 +0800
commit23a3411d065b16b054a0339d4aab9839d87cd6f3 (patch)
tree971a5d8f1e8b15da19c9fbd1cf9abf01bd63bf7a
parent93ba2af3e4e47c86e9dfac2790f81a3718fecef6 (diff)
downloadopenembedded-core-contrib-ChenQi/initramfs-uuid.tar.gz
openembedded-core-contrib-ChenQi/initramfs-uuid.tar.bz2
openembedded-core-contrib-ChenQi/initramfs-uuid.zip
init-install.sh: add support for installing initramfs onto the targetChenQi/initramfs-uuid
Add support to install initramfs image or the kernel bundled with it onto the target. And if there's an initramfs image available, we try to use the 'root=UUID=xxx' in the grub entry so that the target can always boot up even if the device names are changed, say, from /dev/hdb to /dev/hda. Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install.sh49
1 files changed, 40 insertions, 9 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init-install.sh b/meta/recipes-core/initrdscripts/files/init-install.sh
index 0a1141a6f5..748a9d87b9 100644
--- a/meta/recipes-core/initrdscripts/files/init-install.sh
+++ b/meta/recipes-core/initrdscripts/files/init-install.sh
@@ -151,25 +151,55 @@ mkdir /tgt_root
mkdir /src_root
mkdir -p /boot
-# Handling of the target root partition
+# mount target filesystems
+mount $bootfs /boot
mount $rootfs /tgt_root
+
+# Check whether an initramfs is available and get uuid of filesystems
+has_initramfs=""
+uuid_rootfs=""
+uuid_bootfs=""
+uuid_swap=""
+if [ -e /run/media/$1/vmlinuz-initramfs -o -e /run/media/$1/initrd.img ]; then
+ has_initramfs="yes"
+ uuid_rootfs="`blkid $rootfs | cut -d' ' -f2 | sed -e 's/\"//g'`"
+ uuid_bootfs="`blkid $bootfs | cut -d' ' -f2 | sed -e 's/\"//g'`"
+ uuid_swap="`blkid $swap | cut -d' ' -f2 | sed -e 's/\"//g'`"
+fi
+
+# Handling of the target root partition
mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
echo "Copying rootfs files..."
cp -a /src_root/* /tgt_root
+# Try to use uuid entries in /etc/fstab
+if [ "$has_initramfs" = "yes" ]; then
+ swap="$uuid_swap"
+ bootfs="$uuid_bootfs"
+fi
if [ -d /tgt_root/etc/ ] ; then
echo "$swap swap swap defaults 0 0" >> /tgt_root/etc/fstab
echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab
- # We dont want udev to mount our root device while we're booting...
- if [ -d /tgt_root/etc/udev/ ] ; then
- echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
- fi
fi
-umount /tgt_root
umount /src_root
# Handling of the target boot partition
-mount $bootfs /boot
echo "Preparing boot partition..."
+
+# If there's an initramfs available, try to use UUID in grub.cfg.
+# We assume the initramfs has the ability to deal with the UUID parameter.
+if [ -e /run/media/$1/vmlinuz-initramfs ]; then
+ cp /run/media/$1/vmlinuz-initramfs /boot/vmlinuz
+ rootfs="$uuid_rootfs"
+else
+ cp /run/media/$1/vmlinuz /boot/
+fi
+
+if [ -e /run/media/$1/initrd.img ]; then
+ cp /run/media/$1/initrd.img /boot/initrd.img
+ rootfs="$uuid_rootfs"
+ initrd_line="initrd /initrd.img"
+fi
+
if [ -f /etc/grub.d/00_header ] ; then
echo "Preparing custom grub2 menu..."
GRUBCFG="/boot/grub/grub.cfg"
@@ -178,6 +208,7 @@ if [ -f /etc/grub.d/00_header ] ; then
menuentry "Linux" {
set root=(hd0,1)
linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
+ $initrd_line
}
_EOF
chmod 0444 $GRUBCFG
@@ -195,8 +226,8 @@ if [ ! -f /boot/grub/grub.cfg ] ; then
echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst
fi
-cp /run/media/$1/vmlinuz /boot/
-
+# umount target filesystems
+umount /tgt_root
umount /boot
sync