diff options
Diffstat (limited to 'recipes-core/initrdscripts')
-rw-r--r-- | recipes-core/initrdscripts/files/intel-x86-common/init-install-efi.sh | 342 | ||||
-rw-r--r-- | recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend | 2 |
2 files changed, 344 insertions, 0 deletions
diff --git a/recipes-core/initrdscripts/files/intel-x86-common/init-install-efi.sh b/recipes-core/initrdscripts/files/intel-x86-common/init-install-efi.sh new file mode 100644 index 00000000..a7a2ad4c --- /dev/null +++ b/recipes-core/initrdscripts/files/intel-x86-common/init-install-efi.sh | |||
@@ -0,0 +1,342 @@ | |||
1 | #!/bin/sh -e | ||
2 | # | ||
3 | # Copyright (c) 2016, Intel Corporation. | ||
4 | # All rights reserved. | ||
5 | # | ||
6 | # install.sh [device_name] [rootfs_name] | ||
7 | # | ||
8 | # This file is a copy of file with same name in OE: | ||
9 | # meta/recipes-core/initrdscripts/files/. We modify | ||
10 | # it for RMC feature to deploy file blobs from RMC | ||
11 | # database file to target. | ||
12 | |||
13 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
14 | |||
15 | # We need 20 Mb for the boot partition | ||
16 | boot_size=20 | ||
17 | |||
18 | # 5% for swap | ||
19 | swap_ratio=5 | ||
20 | |||
21 | # Get a list of hard drives | ||
22 | hdnamelist="" | ||
23 | live_dev_name=`cat /proc/mounts | grep ${1%/} | awk '{print $1}'` | ||
24 | live_dev_name=${live_dev_name#\/dev/} | ||
25 | # Only strip the digit identifier if the device is not an mmc | ||
26 | case $live_dev_name in | ||
27 | mmcblk*) | ||
28 | ;; | ||
29 | nvme*) | ||
30 | ;; | ||
31 | *) | ||
32 | live_dev_name=${live_dev_name%%[0-9]*} | ||
33 | ;; | ||
34 | esac | ||
35 | |||
36 | echo "Searching for hard drives ..." | ||
37 | |||
38 | for device in `ls /sys/block/`; do | ||
39 | case $device in | ||
40 | loop*) | ||
41 | # skip loop device | ||
42 | ;; | ||
43 | sr*) | ||
44 | # skip CDROM device | ||
45 | ;; | ||
46 | ram*) | ||
47 | # skip ram device | ||
48 | ;; | ||
49 | *) | ||
50 | # skip the device LiveOS is on | ||
51 | # Add valid hard drive name to the list | ||
52 | case $device in | ||
53 | $live_dev_name*) | ||
54 | # skip the device we are running from | ||
55 | ;; | ||
56 | *) | ||
57 | hdnamelist="$hdnamelist $device" | ||
58 | ;; | ||
59 | esac | ||
60 | ;; | ||
61 | esac | ||
62 | done | ||
63 | |||
64 | if [ -z "${hdnamelist}" ]; then | ||
65 | echo "You need another device (besides the live device /dev/${live_dev_name}) to install the image. Installation aborted." | ||
66 | exit 1 | ||
67 | fi | ||
68 | |||
69 | TARGET_DEVICE_NAME="" | ||
70 | for hdname in $hdnamelist; do | ||
71 | # Display found hard drives and their basic info | ||
72 | echo "-------------------------------" | ||
73 | echo /dev/$hdname | ||
74 | if [ -r /sys/block/$hdname/device/vendor ]; then | ||
75 | echo -n "VENDOR=" | ||
76 | cat /sys/block/$hdname/device/vendor | ||
77 | fi | ||
78 | if [ -r /sys/block/$hdname/device/model ]; then | ||
79 | echo -n "MODEL=" | ||
80 | cat /sys/block/$hdname/device/model | ||
81 | fi | ||
82 | if [ -r /sys/block/$hdname/device/uevent ]; then | ||
83 | echo -n "UEVENT=" | ||
84 | cat /sys/block/$hdname/device/uevent | ||
85 | fi | ||
86 | echo | ||
87 | done | ||
88 | |||
89 | # Get user choice | ||
90 | while true; do | ||
91 | echo "Please select an install target or press n to exit ($hdnamelist ): " | ||
92 | read answer | ||
93 | if [ "$answer" = "n" ]; then | ||
94 | echo "Installation manually aborted." | ||
95 | exit 1 | ||
96 | fi | ||
97 | for hdname in $hdnamelist; do | ||
98 | if [ "$answer" = "$hdname" ]; then | ||
99 | TARGET_DEVICE_NAME=$answer | ||
100 | break | ||
101 | fi | ||
102 | done | ||
103 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
104 | break | ||
105 | fi | ||
106 | done | ||
107 | |||
108 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
109 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
110 | else | ||
111 | echo "No hard drive selected. Installation aborted." | ||
112 | exit 1 | ||
113 | fi | ||
114 | |||
115 | device=/dev/$TARGET_DEVICE_NAME | ||
116 | |||
117 | # | ||
118 | # The udev automounter can cause pain here, kill it | ||
119 | # | ||
120 | rm -f /etc/udev/rules.d/automount.rules | ||
121 | rm -f /etc/udev/scripts/mount* | ||
122 | |||
123 | # | ||
124 | # Unmount anything the automounter had mounted | ||
125 | # | ||
126 | umount ${device}* 2> /dev/null || /bin/true | ||
127 | |||
128 | mkdir -p /tmp | ||
129 | |||
130 | # Create /etc/mtab if not present | ||
131 | if [ ! -e /etc/mtab ]; then | ||
132 | cat /proc/mounts > /etc/mtab | ||
133 | fi | ||
134 | |||
135 | disk_size=$(parted ${device} unit mb print | grep '^Disk .*: .*MB' | cut -d" " -f 3 | sed -e "s/MB//") | ||
136 | |||
137 | swap_size=$((disk_size*swap_ratio/100)) | ||
138 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
139 | |||
140 | rootfs_start=$((boot_size)) | ||
141 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
142 | swap_start=$((rootfs_end)) | ||
143 | |||
144 | # MMC devices are special in a couple of ways | ||
145 | # 1) they use a partition prefix character 'p' | ||
146 | # 2) they are detected asynchronously (need rootwait) | ||
147 | rootwait="" | ||
148 | part_prefix="" | ||
149 | if [ ! "${device#/dev/mmcblk}" = "${device}" ] || \ | ||
150 | [ ! "${device#/dev/nvme}" = "${device}" ]; then | ||
151 | part_prefix="p" | ||
152 | rootwait="rootwait" | ||
153 | fi | ||
154 | bootfs=${device}${part_prefix}1 | ||
155 | rootfs=${device}${part_prefix}2 | ||
156 | swap=${device}${part_prefix}3 | ||
157 | |||
158 | echo "*****************" | ||
159 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
160 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
161 | echo "Swap partition size: $swap_size MB ($swap)" | ||
162 | echo "*****************" | ||
163 | echo "Deleting partition table on ${device} ..." | ||
164 | dd if=/dev/zero of=${device} bs=512 count=35 | ||
165 | |||
166 | echo "Creating new partition table on ${device} ..." | ||
167 | parted ${device} mklabel gpt | ||
168 | |||
169 | echo "Creating boot partition on $bootfs" | ||
170 | parted ${device} mkpart boot fat32 0% $boot_size | ||
171 | parted ${device} set 1 boot on | ||
172 | |||
173 | echo "Creating rootfs partition on $rootfs" | ||
174 | parted ${device} mkpart root ext3 $rootfs_start $rootfs_end | ||
175 | |||
176 | echo "Creating swap partition on $swap" | ||
177 | parted ${device} mkpart swap linux-swap $swap_start 100% | ||
178 | |||
179 | parted ${device} print | ||
180 | |||
181 | echo "Formatting $bootfs to vfat..." | ||
182 | mkfs.vfat $bootfs | ||
183 | |||
184 | echo "Formatting $rootfs to ext3..." | ||
185 | mkfs.ext3 $rootfs | ||
186 | |||
187 | echo "Formatting swap partition...($swap)" | ||
188 | mkswap $swap | ||
189 | |||
190 | mkdir /tgt_root | ||
191 | mkdir /src_root | ||
192 | mkdir -p /boot | ||
193 | |||
194 | # Handling of the target root partition | ||
195 | mount $rootfs /tgt_root | ||
196 | mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root | ||
197 | echo "Copying rootfs files..." | ||
198 | cp -a /src_root/* /tgt_root | ||
199 | if [ -d /tgt_root/etc/ ] ; then | ||
200 | boot_uuid=$(blkid -o value -s UUID ${bootfs}) | ||
201 | swap_part_uuid=$(blkid -o value -s PARTUUID ${swap}) | ||
202 | echo "/dev/disk/by-partuuid/$swap_part_uuid swap swap defaults 0 0" >> /tgt_root/etc/fstab | ||
203 | echo "UUID=$boot_uuid /boot vfat defaults 1 2" >> /tgt_root/etc/fstab | ||
204 | # We dont want udev to mount our root device while we're booting... | ||
205 | if [ -d /tgt_root/etc/udev/ ] ; then | ||
206 | echo "${device}" >> /tgt_root/etc/udev/mount.blacklist | ||
207 | fi | ||
208 | fi | ||
209 | |||
210 | # Handling of the target boot partition | ||
211 | mount $bootfs /boot | ||
212 | echo "Preparing boot partition..." | ||
213 | |||
214 | EFIDIR="/boot/EFI/BOOT" | ||
215 | mkdir -p $EFIDIR | ||
216 | # Copy the efi loader | ||
217 | cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR | ||
218 | |||
219 | # RMC deployment | ||
220 | RMC_CMD=/src_root/usr/bin/rmc | ||
221 | RMC_DB=/run/media/$1/rmc.db | ||
222 | |||
223 | # We don't want to quit when a step failed. For example, | ||
224 | # a file system could not support some operations. | ||
225 | set +e | ||
226 | |||
227 | if [ -f "${RMC_DB}" ] && [ -f "${RMC_CMD}" ]; then | ||
228 | echo "Found RMC database and tool, start RMC deployment" | ||
229 | # query INSTALLER.CONFIG from RMC DB | ||
230 | if ${RMC_CMD} -B INSTALLER.CONFIG -d "${RMC_DB}" -o /tmp/installer.config; then | ||
231 | while IFS=':' read -r NAME TGT_UID TGT_GID TGT_MODE TGT_PATH; do | ||
232 | # skip comment | ||
233 | # The regexp in grep works with busybox grep which doesn't | ||
234 | # seem to have a -P to recognize '\t'. But this expression could not | ||
235 | # work with gnu grep... | ||
236 | if echo "$NAME"|grep -q $'^[ \t]*#'; then | ||
237 | continue | ||
238 | fi | ||
239 | # check if we should create a directory (last char in target path is '/') | ||
240 | # or deploy a file | ||
241 | LAST_CHAR=$(echo "${TGT_PATH:$((${#TGT_PATH}-1)):1}") | ||
242 | |||
243 | # Do not bail out for failures but user should get stderr message | ||
244 | if [ ${LAST_CHAR} = "/" ]; then | ||
245 | # name field is skipped for directory | ||
246 | echo "DIR: ${TGT_UID}:${TGT_GID}:${TGT_MODE} => ${TGT_PATH}" | ||
247 | mkdir -p "$TGT_PATH" | ||
248 | chown "${TGT_UID}:${TGT_GID}" "$TGT_PATH" | ||
249 | chmod "${TGT_MODE}" "$TGT_PATH" | ||
250 | else | ||
251 | ${RMC_CMD} -B "${NAME}" -d "${RMC_DB}" -o "${TGT_PATH}" | ||
252 | echo "FILE: ${NAME}:${TGT_UID}:${TGT_GID}:${TGT_MODE} => ${TGT_PATH}" | ||
253 | chown "${TGT_UID}:${TGT_GID}" "$TGT_PATH" | ||
254 | chmod "${TGT_MODE}" "$TGT_PATH" | ||
255 | fi | ||
256 | done < /tmp/installer.config | ||
257 | rm -rf /tmp/installer.config | ||
258 | |||
259 | # remove rmc from target since we don't think it is a valid | ||
260 | # case to run rmc after installation. | ||
261 | rm -rf /tgt_root/usr/bin/rmc | ||
262 | echo "RMC deployment finished" | ||
263 | else | ||
264 | echo "INSTALLER.CONFIG is not found, skip RMC deployment" | ||
265 | fi | ||
266 | |||
267 | # Final retouching by calling post-install hook | ||
268 | if ${RMC_CMD} -B POSTINSTALL.sh -d "${RMC_DB}" -o /tmp/POSTINSTALL.sh; then | ||
269 | echo "Found POSTINSTALL.sh execute it..." | ||
270 | chmod 500 /tmp/POSTINSTALL.sh | ||
271 | /tmp/POSTINSTALL.sh | ||
272 | rm -rf /tmp/POSTINSTALL.sh | ||
273 | fi | ||
274 | fi | ||
275 | set -e | ||
276 | |||
277 | if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then | ||
278 | root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs}) | ||
279 | GRUBCFG="$EFIDIR/grub.cfg" | ||
280 | cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG | ||
281 | # Update grub config for the installed image | ||
282 | # Delete the install entry | ||
283 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
284 | # Delete the initrd lines | ||
285 | sed -i "/initrd /d" $GRUBCFG | ||
286 | # Delete any LABEL= strings | ||
287 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
288 | # Delete any root= strings | ||
289 | sed -i "s/ root=[^ ]*/ /g" $GRUBCFG | ||
290 | # Add the root= and other standard boot options | ||
291 | sed -i "s@linux /vmlinuz *@linux /vmlinuz root=PARTUUID=$root_part_uuid rw $rootwait quiet @" $GRUBCFG | ||
292 | fi | ||
293 | |||
294 | if [ -d /run/media/$1/loader ]; then | ||
295 | rootuuid=$(blkid -o value -s PARTUUID ${rootfs}) | ||
296 | GUMMIBOOT_CFGS="/boot/loader/entries/*.conf" | ||
297 | if [ -d /boot/loader ]; then | ||
298 | # Don't override loader.conf RMC already deployed | ||
299 | if [ ! -f /boot/loader/loader.conf ]; then | ||
300 | cp /run/media/$1/loader/loader.conf /boot/loader/ | ||
301 | fi | ||
302 | # only copy built OE entries when RMC entries don't exist. | ||
303 | if [ ! -d /boot/loader/entries ] || [ ! ls /boot/loader/entries/*.conf &>/dev/null ]; then | ||
304 | cp -dr /run/media/$1/loader/entries /boot/loader | ||
305 | fi | ||
306 | else | ||
307 | # copy config files for gummiboot | ||
308 | cp -dr /run/media/$1/loader /boot | ||
309 | # delete the install entry | ||
310 | rm -f /boot/loader/entries/install.conf | ||
311 | fi | ||
312 | # delete the initrd lines | ||
313 | sed -i "/initrd /d" $GUMMIBOOT_CFGS | ||
314 | # delete any LABEL= strings | ||
315 | sed -i "s/ LABEL=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
316 | # delete any root= strings | ||
317 | sed -i "s/ root=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
318 | # add the root= and other standard boot options | ||
319 | sed -i "s@options *@options root=PARTUUID=$rootuuid rw $rootwait quiet @" $GUMMIBOOT_CFGS | ||
320 | # if RMC feature presents, append global kernel command line fragment when it exists. | ||
321 | if [ -f "${RMC_DB}" ] && [ -f "${RMC_CMD}" ]; then | ||
322 | if ${RMC_CMD} -B KBOOTPARAM -d "${RMC_DB}" -o /tmp/kbootparam; then | ||
323 | sed -i "/^[ \t]*options/ s/$/ $(cat /tmp/kbootparam)/" $GUMMIBOOT_CFGS | ||
324 | rm /tmp/kbootparam | ||
325 | fi | ||
326 | fi | ||
327 | fi | ||
328 | |||
329 | cp /run/media/$1/vmlinuz /boot | ||
330 | |||
331 | umount /src_root | ||
332 | umount /tgt_root | ||
333 | umount /boot | ||
334 | |||
335 | sync | ||
336 | |||
337 | echo "Remove your installation media, and press ENTER" | ||
338 | |||
339 | read enter | ||
340 | |||
341 | echo "Rebooting..." | ||
342 | reboot -f | ||
diff --git a/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend b/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend new file mode 100644 index 00000000..0b3a1d3d --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend | |||
@@ -0,0 +1,2 @@ | |||
1 | FILESEXTRAPATHS_prepend_intel-x86-common := "${THISDIR}/files:" | ||
2 | PACKAGE_ARCH_intel-x86-common = "${INTEL_COMMON_PACKAGE_ARCH}" | ||