]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
init-install.sh: add support for installing initramfs onto the target ChenQi/initramfs-uuid
authorChen Qi <Qi.Chen@windriver.com>
Thu, 12 Jun 2014 03:27:02 +0000 (11:27 +0800)
committerChen Qi <Qi.Chen@windriver.com>
Mon, 16 Jun 2014 10:36:09 +0000 (18:36 +0800)
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>
meta/recipes-core/initrdscripts/files/init-install.sh

index 0a1141a6f5d35110b1d5618221171372817d4d6f..748a9d87b990af08d6705593c94362eac1b0eaa7 100644 (file)
@@ -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