diff options
Diffstat (limited to 'common/recipes-core/initrdscripts')
| -rw-r--r-- | common/recipes-core/initrdscripts/files/init-install-efi.sh | 326 | ||||
| -rw-r--r-- | common/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend | 1 |
2 files changed, 327 insertions, 0 deletions
diff --git a/common/recipes-core/initrdscripts/files/init-install-efi.sh b/common/recipes-core/initrdscripts/files/init-install-efi.sh new file mode 100644 index 00000000..e12a9d21 --- /dev/null +++ b/common/recipes-core/initrdscripts/files/init-install-efi.sh | |||
| @@ -0,0 +1,326 @@ | |||
| 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 | *) | ||
| 30 | live_dev_name=${live_dev_name%%[0-9]*} | ||
| 31 | ;; | ||
| 32 | esac | ||
| 33 | |||
| 34 | echo "Searching for hard drives ..." | ||
| 35 | |||
| 36 | for 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 | ||
| 60 | done | ||
| 61 | |||
| 62 | if [ -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 | ||
| 65 | fi | ||
| 66 | |||
| 67 | TARGET_DEVICE_NAME="" | ||
| 68 | for 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 | ||
| 85 | done | ||
| 86 | |||
| 87 | # Get user choice | ||
| 88 | while 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 | ||
| 104 | done | ||
| 105 | |||
| 106 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
| 107 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
| 108 | else | ||
| 109 | echo "No hard drive selected. Installation aborted." | ||
| 110 | exit 1 | ||
| 111 | fi | ||
| 112 | |||
| 113 | device=/dev/$TARGET_DEVICE_NAME | ||
| 114 | |||
| 115 | # | ||
| 116 | # The udev automounter can cause pain here, kill it | ||
| 117 | # | ||
| 118 | rm -f /etc/udev/rules.d/automount.rules | ||
| 119 | rm -f /etc/udev/scripts/mount* | ||
| 120 | |||
| 121 | # | ||
| 122 | # Unmount anything the automounter had mounted | ||
| 123 | # | ||
| 124 | umount ${device}* 2> /dev/null || /bin/true | ||
| 125 | |||
| 126 | mkdir -p /tmp | ||
| 127 | |||
| 128 | # Create /etc/mtab if not present | ||
| 129 | if [ ! -e /etc/mtab ]; then | ||
| 130 | cat /proc/mounts > /etc/mtab | ||
| 131 | fi | ||
| 132 | |||
| 133 | disk_size=$(parted ${device} unit mb print | grep '^Disk .*: .*MB' | cut -d" " -f 3 | sed -e "s/MB//") | ||
| 134 | |||
| 135 | swap_size=$((disk_size*swap_ratio/100)) | ||
| 136 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
| 137 | |||
| 138 | rootfs_start=$((boot_size)) | ||
| 139 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
| 140 | swap_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) | ||
| 145 | rootwait="" | ||
| 146 | part_prefix="" | ||
| 147 | if [ ! "${device#/dev/mmcblk}" = "${device}" ]; then | ||
| 148 | part_prefix="p" | ||
| 149 | rootwait="rootwait" | ||
| 150 | fi | ||
| 151 | bootfs=${device}${part_prefix}1 | ||
| 152 | rootfs=${device}${part_prefix}2 | ||
| 153 | swap=${device}${part_prefix}3 | ||
| 154 | |||
| 155 | echo "*****************" | ||
| 156 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
| 157 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
| 158 | echo "Swap partition size: $swap_size MB ($swap)" | ||
| 159 | echo "*****************" | ||
| 160 | echo "Deleting partition table on ${device} ..." | ||
| 161 | dd if=/dev/zero of=${device} bs=512 count=35 | ||
| 162 | |||
| 163 | echo "Creating new partition table on ${device} ..." | ||
| 164 | parted ${device} mklabel gpt | ||
| 165 | |||
| 166 | echo "Creating boot partition on $bootfs" | ||
| 167 | parted ${device} mkpart boot fat32 0% $boot_size | ||
| 168 | parted ${device} set 1 boot on | ||
| 169 | |||
| 170 | echo "Creating rootfs partition on $rootfs" | ||
| 171 | parted ${device} mkpart root ext3 $rootfs_start $rootfs_end | ||
| 172 | |||
| 173 | echo "Creating swap partition on $swap" | ||
| 174 | parted ${device} mkpart swap linux-swap $swap_start 100% | ||
| 175 | |||
| 176 | parted ${device} print | ||
| 177 | |||
| 178 | echo "Formatting $bootfs to vfat..." | ||
| 179 | mkfs.vfat $bootfs | ||
| 180 | |||
| 181 | echo "Formatting $rootfs to ext3..." | ||
| 182 | mkfs.ext3 $rootfs | ||
| 183 | |||
| 184 | echo "Formatting swap partition...($swap)" | ||
| 185 | mkswap $swap | ||
| 186 | |||
| 187 | mkdir /tgt_root | ||
| 188 | mkdir /src_root | ||
| 189 | mkdir -p /boot | ||
| 190 | |||
| 191 | # Handling of the target root partition | ||
| 192 | mount $rootfs /tgt_root | ||
| 193 | mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root | ||
| 194 | echo "Copying rootfs files..." | ||
| 195 | cp -a /src_root/* /tgt_root | ||
| 196 | if [ -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 | ||
| 205 | fi | ||
| 206 | |||
| 207 | # Handling of the target boot partition | ||
| 208 | mount $bootfs /boot | ||
| 209 | echo "Preparing boot partition..." | ||
| 210 | |||
| 211 | # RMC deployment | ||
| 212 | RMC_CMD=/src_root/usr/bin/rmc | ||
| 213 | RMC_DB=/run/media/$1/rmc.db | ||
| 214 | |||
| 215 | EFIDIR="/boot/EFI/BOOT" | ||
| 216 | mkdir -p $EFIDIR | ||
| 217 | |||
| 218 | # Copy the efi loader | ||
| 219 | cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR | ||
| 220 | |||
| 221 | # We only support gummiboot/systemd-boot. Leave grub-efi not changed. | ||
| 222 | if [ -d /run/media/$1/loader ]; then | ||
| 223 | # copy config files for gummiboot | ||
| 224 | cp -dr /run/media/$1/loader /boot | ||
| 225 | fi | ||
| 226 | |||
| 227 | # We don't want to quit when a step failed. For example, | ||
| 228 | # a file system could not support some operations. | ||
| 229 | set +e | ||
| 230 | |||
| 231 | if [ -f "${RMC_DB}" ] && [ -f "${RMC_CMD}" ]; then | ||
| 232 | echo "Found RMC database and tool, start RMC deployment" | ||
| 233 | # query INSTALLER.CONFIG from RMC DB | ||
| 234 | if ${RMC_CMD} -B INSTALLER.CONFIG -d "${RMC_DB}" -o /tmp/installer.config; then | ||
| 235 | while IFS=':' read -r NAME TGT_UID TGT_GID TGT_MODE TGT_PATH; do | ||
| 236 | # skip comment | ||
| 237 | # The regexp in grep works with busybox grep which doesn't | ||
| 238 | # seem to have a -P to recognize '\t'. But this expression could not | ||
| 239 | # work with gnu grep... | ||
| 240 | if echo "$NAME"|grep -q $'^[ \t]*#'; then | ||
| 241 | continue | ||
| 242 | fi | ||
| 243 | # check if we should create a directory (last char in target path is '/') | ||
| 244 | # or deploy a file | ||
| 245 | LAST_CHAR=$(echo "${TGT_PATH:$((${#TGT_PATH}-1)):1}") | ||
| 246 | |||
| 247 | # Do not bail out for failures but user should get stderr message | ||
| 248 | if [ ${LAST_CHAR} = "/" ]; then | ||
| 249 | # name field is skipped for directory | ||
| 250 | echo "DIR: ${TGT_UID}:${TGT_GID}:${TGT_MODE} => ${TGT_PATH}" | ||
| 251 | mkdir -p "$TGT_PATH" | ||
| 252 | chown "${TGT_UID}:${TGT_GID}" "$TGT_PATH" | ||
| 253 | chmod "${TGT_MODE}" "$TGT_PATH" | ||
| 254 | else | ||
| 255 | ${RMC_CMD} -B "${NAME}" -d "${RMC_DB}" -o "${TGT_PATH}" | ||
| 256 | echo "FILE: ${NAME}:${TGT_UID}:${TGT_GID}:${TGT_MODE} => ${TGT_PATH}" | ||
| 257 | chown "${TGT_UID}:${TGT_GID}" "$TGT_PATH" | ||
| 258 | chmod "${TGT_MODE}" "$TGT_PATH" | ||
| 259 | fi | ||
| 260 | done < /tmp/installer.config | ||
| 261 | rm -rf /tmp/installer.config | ||
| 262 | |||
| 263 | # remove rmc from target since we don't think it is a valid | ||
| 264 | # case to run rmc after installation. | ||
| 265 | rm -rf /tgt_root/usr/bin/rmc | ||
| 266 | echo "RMC deployment finished" | ||
| 267 | else | ||
| 268 | echo "INSTALLER.CONFIG is not found, skip RMC deployment" | ||
| 269 | fi | ||
| 270 | fi | ||
| 271 | set -e | ||
| 272 | |||
| 273 | if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then | ||
| 274 | root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs}) | ||
| 275 | GRUBCFG="$EFIDIR/grub.cfg" | ||
| 276 | cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG | ||
| 277 | # Update grub config for the installed image | ||
| 278 | # Delete the install entry | ||
| 279 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
| 280 | # Delete the initrd lines | ||
| 281 | sed -i "/initrd /d" $GRUBCFG | ||
| 282 | # Delete any LABEL= strings | ||
| 283 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
| 284 | # Delete any root= strings | ||
| 285 | sed -i "s/ root=[^ ]*/ /g" $GRUBCFG | ||
| 286 | # Add the root= and other standard boot options | ||
| 287 | sed -i "s@linux /vmlinuz *@linux /vmlinuz root=PARTUUID=$root_part_uuid rw $rootwait quiet @" $GRUBCFG | ||
| 288 | fi | ||
| 289 | |||
| 290 | if [ -d /run/media/$1/loader ]; then | ||
| 291 | rootuuid=$(blkid -o value -s PARTUUID ${rootfs}) | ||
| 292 | GUMMIBOOT_CFGS="/boot/loader/entries/*.conf" | ||
| 293 | # delete the install entry | ||
| 294 | # fixme: If RMC did deploy install.conf at previous steps, it is purged here... | ||
| 295 | rm -f /boot/loader/entries/install.conf | ||
| 296 | # delete the initrd lines | ||
| 297 | sed -i "/initrd /d" $GUMMIBOOT_CFGS | ||
| 298 | # delete any LABEL= strings | ||
| 299 | sed -i "s/ LABEL=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
| 300 | # delete any root= strings | ||
| 301 | sed -i "s/ root=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
| 302 | # add the root= and other standard boot options | ||
| 303 | sed -i "s@options *@options root=PARTUUID=$rootuuid rw $rootwait quiet @" $GUMMIBOOT_CFGS | ||
| 304 | # if RMC feature presents, append global kernel command line fragment when it exists. | ||
| 305 | if [ -f "${RMC_DB}" ] && [ -f "${RMC_CMD}" ]; then | ||
| 306 | if ${RMC_CMD} -B KBOOTPARAM -d "${RMC_DB}" -o /tmp/kbootparam; then | ||
| 307 | sed -i "/^[ \t]*options/ s/$/ $(cat /tmp/kbootparam)/" $GUMMIBOOT_CFGS | ||
| 308 | rm /tmp/kbootparam | ||
| 309 | fi | ||
| 310 | fi | ||
| 311 | fi | ||
| 312 | |||
| 313 | cp /run/media/$1/vmlinuz /boot | ||
| 314 | |||
| 315 | umount /src_root | ||
| 316 | umount /tgt_root | ||
| 317 | umount /boot | ||
| 318 | |||
| 319 | sync | ||
| 320 | |||
| 321 | echo "Remove your installation media, and press ENTER" | ||
| 322 | |||
| 323 | read enter | ||
| 324 | |||
| 325 | echo "Rebooting..." | ||
| 326 | reboot -f | ||
diff --git a/common/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend b/common/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend new file mode 100644 index 00000000..81fe7b79 --- /dev/null +++ b/common/recipes-core/initrdscripts/initramfs-live-install-efi_%.bbappend | |||
| @@ -0,0 +1 @@ | |||
| FILESEXTRAPATHS_prepend := "${THISDIR}/files:" | |||
