diff options
| author | Darren Hart <dvhart@linux.intel.com> | 2012-07-03 21:05:46 -0700 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-07-19 17:49:48 +0100 |
| commit | 64f7feb5c37d06e1985c59106cf2f7cd286fd0b8 (patch) | |
| tree | a016868a9546b81060b0d3b5ff9e33fcea46bad6 | |
| parent | d36fa9a8835cd5aa6e14800d862b1a9da4dae30a (diff) | |
| download | poky-64f7feb5c37d06e1985c59106cf2f7cd286fd0b8.tar.gz | |
EFI: Make installer EFI aware
[YOCTO #1919]
Create a basic EFI installer script modeled after the existing installer
and add it to a new initramfs-live-install-efi recipe. Update the
init-live.sh script to distinguish between LABEL=install and
LABEL=install-efi and select the appropriate script. Add the efi
installer to core-image-minimal-initramfs.
Update grub-efi.bbclass to use "LABEL=install-efi" when it detects a
label of "install". This is clearly not ideal, but a proper fix would
involve decoupling the LABELS assignment from the image-live.bbclass
usage of SYSLINUX_LABELS. We should be able to address that in a
follow-on clean-up series.
V2: Include missing initramfs-live-install-efi_1.0.bb
V3: Rebase after Radu's console_params fix
(From OE-Core rev: 4bce3417917a3e88ba6529db394525fba82e0699)
Signed-off-by: Darren Hart <dvhart@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
5 files changed, 203 insertions, 4 deletions
diff --git a/meta/classes/grub-efi.bbclass b/meta/classes/grub-efi.bbclass index 1efb43b805..147accc895 100644 --- a/meta/classes/grub-efi.bbclass +++ b/meta/classes/grub-efi.bbclass | |||
| @@ -99,6 +99,8 @@ python build_grub_cfg() { | |||
| 99 | bb.data.update_data(localdata) | 99 | bb.data.update_data(localdata) |
| 100 | 100 | ||
| 101 | cfgfile.write('\nmenuentry \'%s\'{\n' % (label)) | 101 | cfgfile.write('\nmenuentry \'%s\'{\n' % (label)) |
| 102 | if label == "install": | ||
| 103 | label = "install-efi" | ||
| 102 | cfgfile.write('linux /vmlinuz LABEL=%s' % (label)) | 104 | cfgfile.write('linux /vmlinuz LABEL=%s' % (label)) |
| 103 | 105 | ||
| 104 | append = localdata.getVar('APPEND', True) | 106 | append = localdata.getVar('APPEND', True) |
diff --git a/meta/recipes-core/images/core-image-minimal-initramfs.bb b/meta/recipes-core/images/core-image-minimal-initramfs.bb index 4aeb6188f7..7f6826ceb1 100644 --- a/meta/recipes-core/images/core-image-minimal-initramfs.bb +++ b/meta/recipes-core/images/core-image-minimal-initramfs.bb | |||
| @@ -3,7 +3,7 @@ DESCRIPTION = "Small image capable of booting a device. The kernel includes \ | |||
| 3 | the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \ | 3 | the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \ |
| 4 | first “init” program more efficiently." | 4 | first “init” program more efficiently." |
| 5 | 5 | ||
| 6 | IMAGE_INSTALL = "initramfs-live-boot initramfs-live-install busybox udev base-passwd" | 6 | IMAGE_INSTALL = "initramfs-live-boot initramfs-live-install initramfs-live-install-efi busybox udev base-passwd" |
| 7 | 7 | ||
| 8 | # Do not pollute the initrd image with rootfs features | 8 | # Do not pollute the initrd image with rootfs features |
| 9 | IMAGE_FEATURES = "" | 9 | IMAGE_FEATURES = "" |
diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi.sh b/meta/recipes-core/initrdscripts/files/init-install-efi.sh new file mode 100644 index 0000000000..23228c92c4 --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-install-efi.sh | |||
| @@ -0,0 +1,175 @@ | |||
| 1 | #!/bin/sh -e | ||
| 2 | # | ||
| 3 | # Copyright (c) 2012, Intel Corporation. | ||
| 4 | # All rights reserved. | ||
| 5 | # | ||
| 6 | # install.sh [device_name] [rootfs_name] | ||
| 7 | # | ||
| 8 | |||
| 9 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
| 10 | |||
| 11 | # We need 20 Mb for the boot partition | ||
| 12 | boot_size=20 | ||
| 13 | |||
| 14 | # 5% for swap | ||
| 15 | swap_ratio=5 | ||
| 16 | |||
| 17 | found="no" | ||
| 18 | |||
| 19 | echo "Searching for a hard drive..." | ||
| 20 | for device in 'hda' 'hdb' 'sda' 'sdb' 'mmcblk0' 'mmcblk1' | ||
| 21 | do | ||
| 22 | if [ -e /sys/block/${device}/removable ]; then | ||
| 23 | if [ "$(cat /sys/block/${device}/removable)" = "0" ]; then | ||
| 24 | found="yes" | ||
| 25 | |||
| 26 | while true; do | ||
| 27 | # Try sleeping here to avoid getting kernel messages | ||
| 28 | # obscuring/confusing user | ||
| 29 | sleep 5 | ||
| 30 | echo "Found drive at /dev/${device}. Do you want to install this image there ? [y/n]" | ||
| 31 | read answer | ||
| 32 | if [ "$answer" = "y" ] ; then | ||
| 33 | break | ||
| 34 | fi | ||
| 35 | |||
| 36 | if [ "$answer" = "n" ] ; then | ||
| 37 | found=no | ||
| 38 | break | ||
| 39 | fi | ||
| 40 | |||
| 41 | echo "Please answer y or n" | ||
| 42 | done | ||
| 43 | fi | ||
| 44 | fi | ||
| 45 | |||
| 46 | if [ "$found" = "yes" ]; then | ||
| 47 | break; | ||
| 48 | fi | ||
| 49 | |||
| 50 | done | ||
| 51 | |||
| 52 | if [ "$found" = "no" ]; then | ||
| 53 | exit 1 | ||
| 54 | fi | ||
| 55 | |||
| 56 | echo "Installing image on /dev/${device}" | ||
| 57 | |||
| 58 | # | ||
| 59 | # The udev automounter can cause pain here, kill it | ||
| 60 | # | ||
| 61 | rm -f /etc/udev/scripts/mount* | ||
| 62 | |||
| 63 | # | ||
| 64 | # Unmount anything the automounter had mounted | ||
| 65 | # | ||
| 66 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
| 67 | |||
| 68 | mkdir -p /tmp | ||
| 69 | cat /proc/mounts > /etc/mtab | ||
| 70 | |||
| 71 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
| 72 | |||
| 73 | swap_size=$((disk_size*swap_ratio/100)) | ||
| 74 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
| 75 | |||
| 76 | rootfs_start=$((boot_size)) | ||
| 77 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
| 78 | swap_start=$((rootfs_end)) | ||
| 79 | |||
| 80 | # MMC devices are special in a couple of ways | ||
| 81 | # 1) they use a partition prefix character 'p' | ||
| 82 | # 2) they are detected asynchronously (need rootwait) | ||
| 83 | rootwait="" | ||
| 84 | part_prefix="" | ||
| 85 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
| 86 | part_prefix="p" | ||
| 87 | rootwait="rootwait" | ||
| 88 | fi | ||
| 89 | bootfs=/dev/${device}${part_prefix}1 | ||
| 90 | rootfs=/dev/${device}${part_prefix}2 | ||
| 91 | swap=/dev/${device}${part_prefix}3 | ||
| 92 | |||
| 93 | echo "*****************" | ||
| 94 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
| 95 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
| 96 | echo "Swap partition size: $swap_size MB ($swap)" | ||
| 97 | echo "*****************" | ||
| 98 | echo "Deleting partition table on /dev/${device} ..." | ||
| 99 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
| 100 | |||
| 101 | echo "Creating new partition table on /dev/${device} ..." | ||
| 102 | parted /dev/${device} mklabel gpt | ||
| 103 | |||
| 104 | echo "Creating boot partition on $bootfs" | ||
| 105 | parted /dev/${device} mkpart primary 0% $boot_size | ||
| 106 | |||
| 107 | echo "Creating rootfs partition on $rootfs" | ||
| 108 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
| 109 | |||
| 110 | echo "Creating swap partition on $swap" | ||
| 111 | parted /dev/${device} mkpart primary $swap_start 100% | ||
| 112 | |||
| 113 | parted /dev/${device} print | ||
| 114 | |||
| 115 | echo "Formatting $bootfs to vfat..." | ||
| 116 | mkfs.vfat $bootfs | ||
| 117 | |||
| 118 | echo "Formatting $rootfs to ext3..." | ||
| 119 | mkfs.ext3 $rootfs | ||
| 120 | |||
| 121 | echo "Formatting swap partition...($swap)" | ||
| 122 | mkswap $swap | ||
| 123 | |||
| 124 | mkdir /ssd | ||
| 125 | mkdir /rootmnt | ||
| 126 | mkdir /bootmnt | ||
| 127 | |||
| 128 | mount $rootfs /ssd | ||
| 129 | mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt | ||
| 130 | |||
| 131 | echo "Copying rootfs files..." | ||
| 132 | cp -a /rootmnt/* /ssd | ||
| 133 | |||
| 134 | if [ -d /ssd/etc/ ] ; then | ||
| 135 | echo "$swap swap swap defaults 0 0" >> /ssd/etc/fstab | ||
| 136 | |||
| 137 | # We dont want udev to mount our root device while we're booting... | ||
| 138 | if [ -d /ssd/etc/udev/ ] ; then | ||
| 139 | echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist | ||
| 140 | fi | ||
| 141 | fi | ||
| 142 | |||
| 143 | umount /ssd | ||
| 144 | umount /rootmnt | ||
| 145 | |||
| 146 | echo "Preparing boot partition..." | ||
| 147 | mount $bootfs /ssd | ||
| 148 | |||
| 149 | EFIDIR="/ssd/EFI/BOOT" | ||
| 150 | mkdir -p $EFIDIR | ||
| 151 | GRUBCFG="$EFIDIR/grub.cfg" | ||
| 152 | |||
| 153 | cp /media/$1/vmlinuz /ssd | ||
| 154 | # Copy the efi loader and config (booti*.efi and grub.cfg) | ||
| 155 | cp /media/$1/EFI/BOOT/* $EFIDIR | ||
| 156 | |||
| 157 | # Update grub config for the installed image | ||
| 158 | # Delete the install entry | ||
| 159 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
| 160 | # Delete the initrd lines | ||
| 161 | sed -i "/initrd /d" $GRUBCFG | ||
| 162 | # Delete any LABEL= strings | ||
| 163 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
| 164 | # Replace the ramdisk root with the install device and include other options | ||
| 165 | sed -i "s@ root=[^ ]*@ root=$rootfs rw $rootwait quiet@" $GRUBCFG | ||
| 166 | |||
| 167 | umount /ssd | ||
| 168 | sync | ||
| 169 | |||
| 170 | echo "Remove your installation media, and press ENTER" | ||
| 171 | |||
| 172 | read enter | ||
| 173 | |||
| 174 | echo "Rebooting..." | ||
| 175 | reboot -f | ||
diff --git a/meta/recipes-core/initrdscripts/files/init-live.sh b/meta/recipes-core/initrdscripts/files/init-live.sh index d5e241a620..3fba7dc3a1 100644 --- a/meta/recipes-core/initrdscripts/files/init-live.sh +++ b/meta/recipes-core/initrdscripts/files/init-live.sh | |||
| @@ -116,11 +116,11 @@ case $label in | |||
| 116 | fi | 116 | fi |
| 117 | fi | 117 | fi |
| 118 | ;; | 118 | ;; |
| 119 | install) | 119 | install|install-efi) |
| 120 | if [ -f /media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then | 120 | if [ -f /media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then |
| 121 | ./install.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params | 121 | ./$label.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params |
| 122 | else | 122 | else |
| 123 | fatal "Could not find install script" | 123 | fatal "Could not find $label script" |
| 124 | fi | 124 | fi |
| 125 | 125 | ||
| 126 | # If we're getting here, we failed... | 126 | # If we're getting here, we failed... |
diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb new file mode 100644 index 0000000000..8ad47d476b --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | DESCRIPTION = "A live image init script for grub-efi" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | SRC_URI = "file://init-install-efi.sh" | ||
| 5 | |||
| 6 | PR = "r0" | ||
| 7 | |||
| 8 | RDEPENDS_${PN} = "parted e2fsprogs-mke2fs dosfstools" | ||
| 9 | |||
| 10 | do_install() { | ||
| 11 | install -m 0755 ${WORKDIR}/init-install-efi.sh ${D}/install-efi.sh | ||
| 12 | } | ||
| 13 | |||
| 14 | # While this package maybe an allarch due to it being a | ||
| 15 | # simple script, reality is that it is Host specific based | ||
| 16 | # on the COMPATIBLE_HOST below, which needs to take precedence | ||
| 17 | #inherit allarch | ||
| 18 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 19 | |||
| 20 | FILES_${PN} = " /install-efi.sh " | ||
| 21 | |||
| 22 | COMPATIBLE_HOST = "(i.86|x86_64).*-linux" | ||
