From: Ed Bartosh <ed.bartosh@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH v2 05/11] init-install: Use GPT table with GRUB 2
Date: Tue, 16 Jun 2015 09:13:48 +0300 [thread overview]
Message-ID: <1434435234-4892-6-git-send-email-ed.bartosh@linux.intel.com> (raw)
In-Reply-To: <1434435234-4892-1-git-send-email-ed.bartosh@linux.intel.com>
Changed partition type from 'msdos' to 'gpt'.
Added special partition for grub stage2 bootloader.
NOTE: This is done only for GRUB 2 as legacy GRUB is
rarely used and doesn't support GPT partitions.
Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
diff --git a/meta/recipes-core/initrdscripts/files/init-install.sh b/meta/recipes-core/initrdscripts/files/init-install.sh
index cb26163..298ea8d 100644
--- a/meta/recipes-core/initrdscripts/files/init-install.sh
+++ b/meta/recipes-core/initrdscripts/files/init-install.sh
@@ -106,10 +106,21 @@ fi
disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
+grub_version=$(grub-install -v|sed 's/.* \([0-9]\).*/\1/')
+
+if [ $grub_version -eq 0 ] ; then
+ bios_boot_size=0
+else
+ # For GRUB 2 we need separate parition to store stage2 grub image
+ # 2Mb value is chosen to align partition for best performance.
+ bios_boot_size=2
+fi
+
swap_size=$((disk_size*swap_ratio/100))
-rootfs_size=$((disk_size-boot_size-swap_size))
+rootfs_size=$((disk_size-bios_boot_size-boot_size-swap_size))
-rootfs_start=$((boot_size))
+boot_start=$((bios_boot_size))
+rootfs_start=$((bios_boot_size+boot_size))
rootfs_end=$((rootfs_start+rootfs_size))
swap_start=$((rootfs_end))
@@ -122,11 +133,21 @@ if [ ! "${device#mmcblk}" = "${device}" ]; then
part_prefix="p"
rootwait="rootwait"
fi
-bootfs=/dev/${device}${part_prefix}1
-rootfs=/dev/${device}${part_prefix}2
-swap=/dev/${device}${part_prefix}3
+
+if [ $grub_version -eq 0 ] ; then
+ bios_boot=''
+ bootfs=/dev/${device}${part_prefix}1
+ rootfs=/dev/${device}${part_prefix}2
+ swap=/dev/${device}${part_prefix}3
+else
+ bios_boot=/dev/${device}${part_prefix}1
+ bootfs=/dev/${device}${part_prefix}2
+ rootfs=/dev/${device}${part_prefix}3
+ swap=/dev/${device}${part_prefix}4
+fi
echo "*****************"
+[ $grub_version -ne 0 ] && echo "BIOS boot partition size: $bios_boot_size MB ($bios_boot)"
echo "Boot partition size: $boot_size MB ($bootfs)"
echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
echo "Swap partition size: $swap_size MB ($swap)"
@@ -135,10 +156,18 @@ echo "Deleting partition table on /dev/${device} ..."
dd if=/dev/zero of=/dev/${device} bs=512 count=2
echo "Creating new partition table on /dev/${device} ..."
-parted /dev/${device} mklabel msdos
-
-echo "Creating boot partition on $bootfs"
-parted /dev/${device} mkpart primary 0% $boot_size
+if [ $grub_version -eq 0 ] ; then
+ parted /dev/${device} mktable msdos
+ echo "Creating boot partition on $bootfs"
+ parted /dev/${device} mkpart primary 0% $boot_size
+else
+ parted /dev/${device} mktable gpt
+ echo "Creating BIOS boot partition on $bios_boot"
+ parted /dev/${device} mkpart primary 0% $bios_boot_size
+ parted /dev/${device} set 1 bios_grub on
+ echo "Creating boot partition on $bootfs"
+ parted /dev/${device} mkpart primary $boot_start $boot_size
+fi
echo "Creating rootfs partition on $rootfs"
parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
@@ -186,7 +215,7 @@ if [ -f /etc/grub.d/00_header ] ; then
mkdir -p $(dirname $GRUBCFG)
cat >$GRUBCFG <<_EOF
menuentry "Linux" {
- set root=(hd0,1)
+ set root=(hd0,2)
linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
}
_EOF
@@ -195,8 +224,7 @@ fi
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 /boot/grub/grub.cfg ] ; then
+if [ $grub_version -eq 0 ] ; then
echo "Preparing custom grub menu..."
echo "default 0" > /boot/grub/menu.lst
echo "timeout 30" >> /boot/grub/menu.lst
--
2.1.4
next prev parent reply other threads:[~2015-06-16 8:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-16 6:13 [PATCH v2 00/11] UUID support in installer (poky-contrib: ed/oe-core/uuid-init-install) Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 01/11] image-live: Set syslinux timeout to 5s Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 02/11] initramfs-live-install: Add blkid to initramfs Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 03/11] busybox: Enable UUID-related options Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 04/11] init-install-efi: Implement UUID support Ed Bartosh
2015-06-16 6:13 ` Ed Bartosh [this message]
2015-06-16 6:13 ` [PATCH v2 06/11] init-install: " Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 07/11] init-install: Specify filesystem type in parted command line Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 08/11] init-install: Specify partition name " Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 09/11] init-install: code cleanup: Replace tabs with spaces Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 10/11] init-install: code cleanup: replace /dev/$device -> $device Ed Bartosh
2015-06-16 6:13 ` [PATCH v2 11/11] init-install: Properly delete partition table Ed Bartosh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434435234-4892-6-git-send-email-ed.bartosh@linux.intel.com \
--to=ed.bartosh@linux.intel.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.