summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorNg, Wei Tee <wei.tee.ng@intel.com>2017-07-23 16:51:56 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-07-27 22:36:53 +0100
commit8b960914ac6193c2146eb1bb39fc9ec5c0008404 (patch)
treea69dccd8278e5d3b780042ac5bf2fedd77629c4c /meta
parent716d5d9e65ad05712e127e575bd5e9c68178d33e (diff)
downloadpoky-8b960914ac6193c2146eb1bb39fc9ec5c0008404.tar.gz
initramfs-framework: include install-efi module in recipe for installation
Utilized the existing init-install-efi.sh script and renamed it to install-efi.sh to manage the installation process of images in initramfs-framework model. This script will be executed when "install" option is being chosen in the grub menu and install the image on the target platform. A new install-efi module is being added in the recipe to handle the installation process using initramfs-framework. [YOCTO #10989] (From OE-Core rev: 41b34441c22143cbabace3d794ead05801afb7a0) Signed-off-by: Ng, Wei Tee <wei.tee.ng@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh276
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb19
2 files changed, 292 insertions, 3 deletions
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh b/meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh
new file mode 100644
index 0000000000..5ad3a60c05
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh
@@ -0,0 +1,276 @@
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
9PATH=/sbin:/bin:/usr/sbin:/usr/bin
10
11# We need 20 Mb for the boot partition
12boot_size=20
13
14# 5% for swap
15swap_ratio=5
16
17# Get a list of hard drives
18hdnamelist=""
19live_dev_name=`cat /proc/mounts | grep ${1%/} | awk '{print $1}'`
20live_dev_name=${live_dev_name#\/dev/}
21# Only strip the digit identifier if the device is not an mmc
22case $live_dev_name in
23 mmcblk*)
24 ;;
25 nvme*)
26 ;;
27 *)
28 live_dev_name=${live_dev_name%%[0-9]*}
29 ;;
30esac
31
32echo "Searching for hard drives ..."
33
34# Some eMMC devices have special sub devices such as mmcblk0boot0 etc
35# we're currently only interested in the root device so pick them wisely
36devices=`ls /sys/block/ | grep -v mmcblk` || true
37mmc_devices=`ls /sys/block/ | grep "mmcblk[0-9]\{1,\}$"` || true
38devices="$devices $mmc_devices"
39
40for device in $devices; do
41 case $device in
42 loop*)
43 # skip loop device
44 ;;
45 sr*)
46 # skip CDROM device
47 ;;
48 ram*)
49 # skip ram device
50 ;;
51 *)
52 # skip the device LiveOS is on
53 # Add valid hard drive name to the list
54 case $device in
55 $live_dev_name*)
56 # skip the device we are running from
57 ;;
58 *)
59 hdnamelist="$hdnamelist $device"
60 ;;
61 esac
62 ;;
63 esac
64done
65
66if [ -z "${hdnamelist}" ]; then
67 echo "You need another device (besides the live device /dev/${live_dev_name}) to install the image. Installation aborted."
68 exit 1
69fi
70
71TARGET_DEVICE_NAME=""
72for hdname in $hdnamelist; do
73 # Display found hard drives and their basic info
74 echo "-------------------------------"
75 echo /dev/$hdname
76 if [ -r /sys/block/$hdname/device/vendor ]; then
77 echo -n "VENDOR="
78 cat /sys/block/$hdname/device/vendor
79 fi
80 if [ -r /sys/block/$hdname/device/model ]; then
81 echo -n "MODEL="
82 cat /sys/block/$hdname/device/model
83 fi
84 if [ -r /sys/block/$hdname/device/uevent ]; then
85 echo -n "UEVENT="
86 cat /sys/block/$hdname/device/uevent
87 fi
88 echo
89done
90
91# Get user choice
92while true; do
93 echo "Please select an install target or press n to exit ($hdnamelist ): "
94 read answer
95 if [ "$answer" = "n" ]; then
96 echo "Installation manually aborted."
97 exit 1
98 fi
99 for hdname in $hdnamelist; do
100 if [ "$answer" = "$hdname" ]; then
101 TARGET_DEVICE_NAME=$answer
102 break
103 fi
104 done
105 if [ -n "$TARGET_DEVICE_NAME" ]; then
106 break
107 fi
108done
109
110if [ -n "$TARGET_DEVICE_NAME" ]; then
111 echo "Installing image on /dev/$TARGET_DEVICE_NAME ..."
112else
113 echo "No hard drive selected. Installation aborted."
114 exit 1
115fi
116
117device=/dev/$TARGET_DEVICE_NAME
118
119#
120# The udev automounter can cause pain here, kill it
121#
122rm -f /etc/udev/rules.d/automount.rules
123rm -f /etc/udev/scripts/mount*
124
125#
126# Unmount anything the automounter had mounted
127#
128umount ${device}* 2> /dev/null || /bin/true
129
130mkdir -p /tmp
131
132# Create /etc/mtab if not present
133if [ ! -e /etc/mtab ] && [ -e /proc/mounts ]; then
134 ln -sf /proc/mounts /etc/mtab
135fi
136
137disk_size=$(parted ${device} unit mb print | grep '^Disk .*: .*MB' | cut -d" " -f 3 | sed -e "s/MB//")
138
139swap_size=$((disk_size*swap_ratio/100))
140rootfs_size=$((disk_size-boot_size-swap_size))
141
142rootfs_start=$((boot_size))
143rootfs_end=$((rootfs_start+rootfs_size))
144swap_start=$((rootfs_end))
145
146# MMC devices are special in a couple of ways
147# 1) they use a partition prefix character 'p'
148# 2) they are detected asynchronously (need rootwait)
149rootwait=""
150part_prefix=""
151if [ ! "${device#/dev/mmcblk}" = "${device}" ] || \
152 [ ! "${device#/dev/nvme}" = "${device}" ]; then
153 part_prefix="p"
154 rootwait="rootwait"
155fi
156
157# USB devices also require rootwait
158if [ -n `readlink /dev/disk/by-id/usb* | grep $TARGET_DEVICE_NAME` ]; then
159 rootwait="rootwait"
160fi
161
162bootfs=${device}${part_prefix}1
163rootfs=${device}${part_prefix}2
164swap=${device}${part_prefix}3
165
166echo "*****************"
167echo "Boot partition size: $boot_size MB ($bootfs)"
168echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
169echo "Swap partition size: $swap_size MB ($swap)"
170echo "*****************"
171echo "Deleting partition table on ${device} ..."
172dd if=/dev/zero of=${device} bs=512 count=35
173
174echo "Creating new partition table on ${device} ..."
175parted ${device} mklabel gpt
176
177echo "Creating boot partition on $bootfs"
178parted ${device} mkpart boot fat32 0% $boot_size
179parted ${device} set 1 boot on
180
181echo "Creating rootfs partition on $rootfs"
182parted ${device} mkpart root ext3 $rootfs_start $rootfs_end
183
184echo "Creating swap partition on $swap"
185parted ${device} mkpart swap linux-swap $swap_start 100%
186
187parted ${device} print
188
189echo "Formatting $bootfs to vfat..."
190mkfs.vfat $bootfs
191
192echo "Formatting $rootfs to ext3..."
193mkfs.ext3 $rootfs
194
195echo "Formatting swap partition...($swap)"
196mkswap $swap
197
198mkdir /tgt_root
199mkdir /src_root
200mkdir -p /boot
201
202# Handling of the target root partition
203mount $rootfs /tgt_root
204mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
205echo "Copying rootfs files..."
206cp -a /src_root/* /tgt_root
207if [ -d /tgt_root/etc/ ] ; then
208 boot_uuid=$(blkid -o value -s UUID ${bootfs})
209 swap_part_uuid=$(blkid -o value -s PARTUUID ${swap})
210 echo "/dev/disk/by-partuuid/$swap_part_uuid swap swap defaults 0 0" >> /tgt_root/etc/fstab
211 echo "UUID=$boot_uuid /boot vfat defaults 1 2" >> /tgt_root/etc/fstab
212 # We dont want udev to mount our root device while we're booting...
213 if [ -d /tgt_root/etc/udev/ ] ; then
214 echo "${device}" >> /tgt_root/etc/udev/mount.blacklist
215 fi
216fi
217
218umount /src_root
219
220# Handling of the target boot partition
221mount $bootfs /boot
222echo "Preparing boot partition..."
223
224EFIDIR="/boot/EFI/BOOT"
225mkdir -p $EFIDIR
226# Copy the efi loader
227cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
228
229if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
230 root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs})
231 GRUBCFG="$EFIDIR/grub.cfg"
232 cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
233 # Update grub config for the installed image
234 # Delete the install entry
235 sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG
236 # Delete the initrd lines
237 sed -i "/initrd /d" $GRUBCFG
238 # Delete any LABEL= strings
239 sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG
240 # Delete any root= strings
241 sed -i "s/ root=[^ ]*/ /g" $GRUBCFG
242 # Add the root= and other standard boot options
243 sed -i "s@linux /vmlinuz *@linux /vmlinuz root=PARTUUID=$root_part_uuid rw $rootwait quiet @" $GRUBCFG
244fi
245
246if [ -d /run/media/$1/loader ]; then
247 rootuuid=$(blkid -o value -s PARTUUID ${rootfs})
248 SYSTEMDBOOT_CFGS="/boot/loader/entries/*.conf"
249 # copy config files for systemd-boot
250 cp -dr /run/media/$1/loader /boot
251 # delete the install entry
252 rm -f /boot/loader/entries/install.conf
253 # delete the initrd lines
254 sed -i "/initrd /d" $SYSTEMDBOOT_CFGS
255 # delete any LABEL= strings
256 sed -i "s/ LABEL=[^ ]*/ /" $SYSTEMDBOOT_CFGS
257 # delete any root= strings
258 sed -i "s/ root=[^ ]*/ /" $SYSTEMDBOOT_CFGS
259 # add the root= and other standard boot options
260 sed -i "s@options *@options root=PARTUUID=$rootuuid rw $rootwait quiet @" $SYSTEMDBOOT_CFGS
261fi
262
263umount /tgt_root
264
265cp /run/media/$1/vmlinuz /boot
266
267umount /boot
268
269sync
270
271echo "Remove your installation media, and press ENTER"
272
273read enter
274
275echo "Rebooting..."
276reboot -f
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
index 211e89d5d3..9d69a696f1 100644
--- a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
+++ b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb
@@ -5,7 +5,11 @@ RDEPENDS_${PN} += "${VIRTUAL-RUNTIME_base-utils}"
5 5
6PR = "r2" 6PR = "r2"
7 7
8inherit allarch 8# While the packages maybe an allarch due to it being a
9# simple script, reality is that it is Host specific based
10# on the COMPATIBLE_HOST below, which needs to take precedence
11#inherit allarch
12INHIBIT_DEFAULT_DEPS = "1"
9 13
10SRC_URI = "file://init \ 14SRC_URI = "file://init \
11 file://rootfs \ 15 file://rootfs \
@@ -14,7 +18,8 @@ SRC_URI = "file://init \
14 file://udev \ 18 file://udev \
15 file://e2fs \ 19 file://e2fs \
16 file://debug \ 20 file://debug \
17 file://setup-live" 21 file://setup-live \
22 file://install-efi.sh"
18 23
19S = "${WORKDIR}" 24S = "${WORKDIR}"
20 25
@@ -41,6 +46,9 @@ do_install() {
41 # debug 46 # debug
42 install -m 0755 ${WORKDIR}/debug ${D}/init.d/00-debug 47 install -m 0755 ${WORKDIR}/debug ${D}/init.d/00-debug
43 48
49 # install-efi
50 install -m 0755 ${WORKDIR}/install-efi.sh ${D}/init.d/install-efi.sh
51
44 # Create device nodes expected by some kernels in initramfs 52 # Create device nodes expected by some kernels in initramfs
45 # before even executing /init. 53 # before even executing /init.
46 install -d ${D}/dev 54 install -d ${D}/dev
@@ -53,7 +61,8 @@ PACKAGES = "${PN}-base \
53 initramfs-module-e2fs \ 61 initramfs-module-e2fs \
54 initramfs-module-rootfs \ 62 initramfs-module-rootfs \
55 initramfs-module-debug \ 63 initramfs-module-debug \
56 initramfs-module-setup-live" 64 initramfs-module-setup-live \
65 initramfs-module-install-efi"
57 66
58FILES_${PN}-base = "/init /init.d/99-finish /dev" 67FILES_${PN}-base = "/init /init.d/99-finish /dev"
59 68
@@ -88,3 +97,7 @@ FILES_initramfs-module-rootfs = "/init.d/90-rootfs"
88SUMMARY_initramfs-module-debug = "initramfs dynamic debug support" 97SUMMARY_initramfs-module-debug = "initramfs dynamic debug support"
89RDEPENDS_initramfs-module-debug = "${PN}-base" 98RDEPENDS_initramfs-module-debug = "${PN}-base"
90FILES_initramfs-module-debug = "/init.d/00-debug" 99FILES_initramfs-module-debug = "/init.d/00-debug"
100
101SUMMARY_initramfs-module-install-efi = "initramfs support for installation option"
102RDEPENDS_initramfs-module-install-efi = "${PN}-base parted e2fsprogs-mke2fs dosfstools util-linux-blkid"
103FILES_initramfs-module-install-efi = "/init.d/install-efi.sh"