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