* [PATCH 1/2] init-install.sh: improve hard drive searching process
2013-08-16 9:38 [PATCH 0/2] minimal-installer: improvements and bug fixes Qi.Chen
@ 2013-08-16 9:38 ` Qi.Chen
2013-08-16 9:38 ` [PATCH 2/2] init-install.sh: fix to handle the boot partition correctly Qi.Chen
1 sibling, 0 replies; 3+ messages in thread
From: Qi.Chen @ 2013-08-16 9:38 UTC (permalink / raw)
To: openembedded-core; +Cc: Zhangle.Yang
From: Chen Qi <Qi.Chen@windriver.com>
Previously, only unremovable hard drives are searched and are treated
as candidates of target disks to intall into.
However, it's possible that we're going to install the live image into
a removable media such as an USB. This patch enables this possibility.
In addition, this patch presents more information about the hard drives
so that user may have more knowledge about which hard drive they are
going to install their image into.
[YOCTO #5018]
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
.../initrdscripts/files/init-install.sh | 98 +++++++++++---------
1 file changed, 55 insertions(+), 43 deletions(-)
diff --git a/meta/recipes-core/initrdscripts/files/init-install.sh b/meta/recipes-core/initrdscripts/files/init-install.sh
index d2a0db3..c892075 100644
--- a/meta/recipes-core/initrdscripts/files/init-install.sh
+++ b/meta/recipes-core/initrdscripts/files/init-install.sh
@@ -13,46 +13,66 @@ boot_size=20
# 5% for the swap
swap_ratio=5
-found="no"
-
-echo "Searching for a hard drive..."
-for device in 'hda' 'hdb' 'sda' 'sdb' 'mmcblk0' 'mmcblk1'
- do
- if [ -e /sys/block/${device}/removable ]; then
- if [ "$(cat /sys/block/${device}/removable)" = "0" ]; then
- found="yes"
-
- while true; do
- # Try sleeping here to avoid getting kernel messages
- # obscuring/confusing user
- sleep 5
- echo "Found drive at /dev/${device}. Do you want to install this image there ? [y/n]"
- read answer
- if [ "$answer" = "y" ] ; then
- break
- fi
-
- if [ "$answer" = "n" ] ; then
- found=no
- break
- fi
-
- echo "Please answer by y or n"
- done
- fi
- fi
-
- if [ "$found" = "yes" ]; then
- break;
- fi
+# Get a list of hard drives
+hdnamelist=""
+live_dev_name=${1%%/*}
+
+echo "Searching for hard drives ..."
+
+for device in `ls /sys/block/`; do
+ case $device in
+ loop*)
+ # skip loop device
+ ;;
+ ram*)
+ # skip ram device
+ ;;
+ *)
+ # skip the device LiveOS is on
+ # Add valid hard drive name to the list
+ if [ $device != $live_dev_name -a -e /dev/$device ]; then
+ hdnamelist="$hdnamelist $device"
+ fi
+ ;;
+ esac
+done
+TARGET_DEVICE_NAME=""
+for hdname in $hdnamelist; do
+ # Display found hard drives and their basic info
+ echo "-------------------------------"
+ echo /dev/$hdname
+ if [ -r /sys/block/$hdname/device/vendor ]; then
+ echo -n "VENDOR="
+ cat /sys/block/$hdname/device/vendor
+ fi
+ echo -n "MODEL="
+ cat /sys/block/$hdname/device/model
+ cat /sys/block/$hdname/device/uevent
+ echo
+ # Get user choice
+ while true; do
+ echo -n "Do you want to install this image there? [y/n] "
+ read answer
+ if [ "$answer" = "y" -o "$answer" = "n" ]; then
+ break
+ fi
+ echo "Please answer y or n"
+ done
+ if [ "$answer" = "y" ]; then
+ TARGET_DEVICE_NAME=$hdname
+ break
+ fi
done
-if [ "$found" = "no" ]; then
- exit 1
+if [ -n "$TARGET_DEVICE_NAME" ]; then
+ echo "Installing image on /dev/$TARGET_DEVICE_NAME ..."
+else
+ echo "No hard drive selected. Installation aborted."
+ exit 1
fi
-echo "Installing image on /dev/${device}"
+device=$TARGET_DEVICE_NAME
#
# The udev automounter can cause pain here, kill it
@@ -65,14 +85,6 @@ rm -f /etc/udev/scripts/mount*
#
umount /dev/${device}* 2> /dev/null || /bin/true
-if [ ! -b /dev/sda ] ; then
- mknod /dev/sda b 8 0
-fi
-
-if [ ! -b /dev/sdb ] ; then
- mknod /dev/sdb b 8 16
-fi
-
if [ ! -b /dev/loop0 ] ; then
mknod /dev/loop0 b 7 0
fi
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] init-install.sh: fix to handle the boot partition correctly
2013-08-16 9:38 [PATCH 0/2] minimal-installer: improvements and bug fixes Qi.Chen
2013-08-16 9:38 ` [PATCH 1/2] init-install.sh: improve hard drive searching process Qi.Chen
@ 2013-08-16 9:38 ` Qi.Chen
1 sibling, 0 replies; 3+ messages in thread
From: Qi.Chen @ 2013-08-16 9:38 UTC (permalink / raw)
To: openembedded-core; +Cc: Zhangle.Yang
From: Chen Qi <Qi.Chen@windriver.com>
Previously, the boot partition was created for the target hard drive
but there was no corresponding entry for it in /etc/fstab. Besides,
even if the boot partition was mounted, it would just result in odd
directory hierarchy like /boot/boot/grub. However, what we really need
is /boot/grub. This patch fixes this problem.
Besides, for future maintance work, this patch also renames some of the
intermediate directories. It uses more descriptive names like /tgt_root
and /src_root. The name of /ssd is dropped.
[YOCTO #5018]
Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
---
meta/recipes-bsp/grub/grub-2.00/40_custom | 2 +-
.../initrdscripts/files/init-install.sh | 62 +++++++++-----------
2 files changed, 30 insertions(+), 34 deletions(-)
diff --git a/meta/recipes-bsp/grub/grub-2.00/40_custom b/meta/recipes-bsp/grub/grub-2.00/40_custom
index ba48830..f891b02 100755
--- a/meta/recipes-bsp/grub/grub-2.00/40_custom
+++ b/meta/recipes-bsp/grub/grub-2.00/40_custom
@@ -5,5 +5,5 @@ exec tail -n +3 $0
# the 'exec tail' line above.
menuentry "Linux" {
set root=(hd0,1)
- linux /boot/vmlinuz root=__ROOTFS__ rw __CONSOLE__ __VIDEO_MODE__ __VGA_MODE__ quiet
+ linux /vmlinuz root=__ROOTFS__ rw __CONSOLE__ __VIDEO_MODE__ __VGA_MODE__ quiet
}
diff --git a/meta/recipes-core/initrdscripts/files/init-install.sh b/meta/recipes-core/initrdscripts/files/init-install.sh
index c892075..8e433d5 100644
--- a/meta/recipes-core/initrdscripts/files/init-install.sh
+++ b/meta/recipes-core/initrdscripts/files/init-install.sh
@@ -145,29 +145,32 @@ mkfs.ext3 $rootfs
echo "Formatting swap partition...($swap)"
mkswap $swap
-mkdir /ssd
-mkdir /rootmnt
-mkdir /bootmnt
-
-mount $rootfs /ssd
-mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt
+mkdir /tgt_root
+mkdir /src_root
+mkdir -p /boot
+# Handling of the target root partition
+mount $rootfs /tgt_root
+mount -o rw,loop,noatime,nodiratime /media/$1/$2 /src_root
echo "Copying rootfs files..."
-cp -a /rootmnt/* /ssd
-
-if [ -d /ssd/etc/ ] ; then
- echo "$swap swap swap defaults 0 0" >> /ssd/etc/fstab
-
+cp -a /src_root/* /tgt_root
+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 /ssd/etc/udev/ ] ; then
- echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist
+ 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 [ -f /etc/grub.d/40_custom ] ; then
echo "Preparing custom grub2 menu..."
- GRUBCFG="/bootmnt/boot/grub/grub.cfg"
- mount $bootfs /bootmnt
+ GRUBCFG="/boot/grub/grub.cfg"
mkdir -p $(dirname $GRUBCFG)
cp /etc/grub.d/40_custom $GRUBCFG
sed -i "s@__ROOTFS__@$rootfs $rootwait@g" $GRUBCFG
@@ -177,31 +180,24 @@ if [ -f /etc/grub.d/40_custom ] ; then
sed -i "/#/d" $GRUBCFG
sed -i "/exec tail/d" $GRUBCFG
chmod 0444 $GRUBCFG
- umount /bootmnt
fi
-
-umount /ssd
-umount /rootmnt
-
-echo "Preparing boot partition..."
-mount $bootfs /ssd
-grub-install --root-directory=/ssd /dev/${device}
-
-echo "(hd0) /dev/${device}" > /ssd/boot/grub/device.map
+grub-install /dev/${device}
+echo "(hd0) /dev/${device}" > /boot/grub/device.map
# If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst
-if [ ! -f /ssd/boot/grub/grub.cfg ] ; then
+if [ ! -f /boot/grub/grub.cfg ] ; then
echo "Preparing custom grub menu..."
- echo "default 0" > /ssd/boot/grub/menu.lst
- echo "timeout 30" >> /ssd/boot/grub/menu.lst
- echo "title Live Boot/Install-Image" >> /ssd/boot/grub/menu.lst
- echo "root (hd0,0)" >> /ssd/boot/grub/menu.lst
- echo "kernel /boot/vmlinuz root=$rootfs rw $3 $4 quiet" >> /ssd/boot/grub/menu.lst
+ echo "default 0" > /boot/grub/menu.lst
+ echo "timeout 30" >> /boot/grub/menu.lst
+ echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst
+ echo "root (hd0,0)" >> /boot/grub/menu.lst
+ echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst
fi
-cp /media/$1/vmlinuz /ssd/boot/
+cp /media/$1/vmlinuz /boot/
+
+umount /boot
-umount /ssd
sync
echo "Remove your installation media, and press ENTER"
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread