summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh276
-rw-r--r--meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb6
2 files changed, 3 insertions, 279 deletions
diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh b/meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh
deleted file mode 100644
index 5ad3a60c05..0000000000
--- a/meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh
+++ /dev/null
@@ -1,276 +0,0 @@
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-module-install-efi_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb
index 2270441d06..3d8c9e7ebb 100644
--- a/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb
+++ b/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb
@@ -7,14 +7,14 @@ PR = "r4"
7 7
8inherit allarch 8inherit allarch
9 9
10FILESEXTRAPATHS_prepend := "${THISDIR}/initramfs-framework:" 10FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
11SRC_URI = "file://install-efi.sh" 11SRC_URI = "file://init-install-efi.sh"
12 12
13S = "${WORKDIR}" 13S = "${WORKDIR}"
14 14
15do_install() { 15do_install() {
16 install -d ${D}/init.d 16 install -d ${D}/init.d
17 install -m 0755 ${WORKDIR}/install-efi.sh ${D}/init.d/install-efi.sh 17 install -m 0755 ${WORKDIR}/init-install-efi.sh ${D}/init.d/install-efi.sh
18} 18}
19 19
20FILES_${PN} = "/init.d/install-efi.sh" 20FILES_${PN} = "/init.d/install-efi.sh"