diff options
| -rw-r--r-- | meta/recipes-core/initrdscripts/initramfs-framework/install-efi.sh | 276 | ||||
| -rw-r--r-- | meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb | 19 |
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 | |||
| 9 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
| 10 | |||
| 11 | # We need 20 Mb for the boot partition | ||
| 12 | boot_size=20 | ||
| 13 | |||
| 14 | # 5% for swap | ||
| 15 | swap_ratio=5 | ||
| 16 | |||
| 17 | # Get a list of hard drives | ||
| 18 | hdnamelist="" | ||
| 19 | live_dev_name=`cat /proc/mounts | grep ${1%/} | awk '{print $1}'` | ||
| 20 | live_dev_name=${live_dev_name#\/dev/} | ||
| 21 | # Only strip the digit identifier if the device is not an mmc | ||
| 22 | case $live_dev_name in | ||
| 23 | mmcblk*) | ||
| 24 | ;; | ||
| 25 | nvme*) | ||
| 26 | ;; | ||
| 27 | *) | ||
| 28 | live_dev_name=${live_dev_name%%[0-9]*} | ||
| 29 | ;; | ||
| 30 | esac | ||
| 31 | |||
| 32 | echo "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 | ||
| 36 | devices=`ls /sys/block/ | grep -v mmcblk` || true | ||
| 37 | mmc_devices=`ls /sys/block/ | grep "mmcblk[0-9]\{1,\}$"` || true | ||
| 38 | devices="$devices $mmc_devices" | ||
| 39 | |||
| 40 | for 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 | ||
| 64 | done | ||
| 65 | |||
| 66 | if [ -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 | ||
| 69 | fi | ||
| 70 | |||
| 71 | TARGET_DEVICE_NAME="" | ||
| 72 | for 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 | ||
| 89 | done | ||
| 90 | |||
| 91 | # Get user choice | ||
| 92 | while 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 | ||
| 108 | done | ||
| 109 | |||
| 110 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
| 111 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
| 112 | else | ||
| 113 | echo "No hard drive selected. Installation aborted." | ||
| 114 | exit 1 | ||
| 115 | fi | ||
| 116 | |||
| 117 | device=/dev/$TARGET_DEVICE_NAME | ||
| 118 | |||
| 119 | # | ||
| 120 | # The udev automounter can cause pain here, kill it | ||
| 121 | # | ||
| 122 | rm -f /etc/udev/rules.d/automount.rules | ||
| 123 | rm -f /etc/udev/scripts/mount* | ||
| 124 | |||
| 125 | # | ||
| 126 | # Unmount anything the automounter had mounted | ||
| 127 | # | ||
| 128 | umount ${device}* 2> /dev/null || /bin/true | ||
| 129 | |||
| 130 | mkdir -p /tmp | ||
| 131 | |||
| 132 | # Create /etc/mtab if not present | ||
| 133 | if [ ! -e /etc/mtab ] && [ -e /proc/mounts ]; then | ||
| 134 | ln -sf /proc/mounts /etc/mtab | ||
| 135 | fi | ||
| 136 | |||
| 137 | disk_size=$(parted ${device} unit mb print | grep '^Disk .*: .*MB' | cut -d" " -f 3 | sed -e "s/MB//") | ||
| 138 | |||
| 139 | swap_size=$((disk_size*swap_ratio/100)) | ||
| 140 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
| 141 | |||
| 142 | rootfs_start=$((boot_size)) | ||
| 143 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
| 144 | swap_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) | ||
| 149 | rootwait="" | ||
| 150 | part_prefix="" | ||
| 151 | if [ ! "${device#/dev/mmcblk}" = "${device}" ] || \ | ||
| 152 | [ ! "${device#/dev/nvme}" = "${device}" ]; then | ||
| 153 | part_prefix="p" | ||
| 154 | rootwait="rootwait" | ||
| 155 | fi | ||
| 156 | |||
| 157 | # USB devices also require rootwait | ||
| 158 | if [ -n `readlink /dev/disk/by-id/usb* | grep $TARGET_DEVICE_NAME` ]; then | ||
| 159 | rootwait="rootwait" | ||
| 160 | fi | ||
| 161 | |||
| 162 | bootfs=${device}${part_prefix}1 | ||
| 163 | rootfs=${device}${part_prefix}2 | ||
| 164 | swap=${device}${part_prefix}3 | ||
| 165 | |||
| 166 | echo "*****************" | ||
| 167 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
| 168 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
| 169 | echo "Swap partition size: $swap_size MB ($swap)" | ||
| 170 | echo "*****************" | ||
| 171 | echo "Deleting partition table on ${device} ..." | ||
| 172 | dd if=/dev/zero of=${device} bs=512 count=35 | ||
| 173 | |||
| 174 | echo "Creating new partition table on ${device} ..." | ||
| 175 | parted ${device} mklabel gpt | ||
| 176 | |||
| 177 | echo "Creating boot partition on $bootfs" | ||
| 178 | parted ${device} mkpart boot fat32 0% $boot_size | ||
| 179 | parted ${device} set 1 boot on | ||
| 180 | |||
| 181 | echo "Creating rootfs partition on $rootfs" | ||
| 182 | parted ${device} mkpart root ext3 $rootfs_start $rootfs_end | ||
| 183 | |||
| 184 | echo "Creating swap partition on $swap" | ||
| 185 | parted ${device} mkpart swap linux-swap $swap_start 100% | ||
| 186 | |||
| 187 | parted ${device} print | ||
| 188 | |||
| 189 | echo "Formatting $bootfs to vfat..." | ||
| 190 | mkfs.vfat $bootfs | ||
| 191 | |||
| 192 | echo "Formatting $rootfs to ext3..." | ||
| 193 | mkfs.ext3 $rootfs | ||
| 194 | |||
| 195 | echo "Formatting swap partition...($swap)" | ||
| 196 | mkswap $swap | ||
| 197 | |||
| 198 | mkdir /tgt_root | ||
| 199 | mkdir /src_root | ||
| 200 | mkdir -p /boot | ||
| 201 | |||
| 202 | # Handling of the target root partition | ||
| 203 | mount $rootfs /tgt_root | ||
| 204 | mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root | ||
| 205 | echo "Copying rootfs files..." | ||
| 206 | cp -a /src_root/* /tgt_root | ||
| 207 | if [ -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 | ||
| 216 | fi | ||
| 217 | |||
| 218 | umount /src_root | ||
| 219 | |||
| 220 | # Handling of the target boot partition | ||
| 221 | mount $bootfs /boot | ||
| 222 | echo "Preparing boot partition..." | ||
| 223 | |||
| 224 | EFIDIR="/boot/EFI/BOOT" | ||
| 225 | mkdir -p $EFIDIR | ||
| 226 | # Copy the efi loader | ||
| 227 | cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR | ||
| 228 | |||
| 229 | if [ -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 | ||
| 244 | fi | ||
| 245 | |||
| 246 | if [ -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 | ||
| 261 | fi | ||
| 262 | |||
| 263 | umount /tgt_root | ||
| 264 | |||
| 265 | cp /run/media/$1/vmlinuz /boot | ||
| 266 | |||
| 267 | umount /boot | ||
| 268 | |||
| 269 | sync | ||
| 270 | |||
| 271 | echo "Remove your installation media, and press ENTER" | ||
| 272 | |||
| 273 | read enter | ||
| 274 | |||
| 275 | echo "Rebooting..." | ||
| 276 | reboot -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 | ||
| 6 | PR = "r2" | 6 | PR = "r2" |
| 7 | 7 | ||
| 8 | inherit 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 | ||
| 12 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 9 | 13 | ||
| 10 | SRC_URI = "file://init \ | 14 | SRC_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 | ||
| 19 | S = "${WORKDIR}" | 24 | S = "${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 | ||
| 58 | FILES_${PN}-base = "/init /init.d/99-finish /dev" | 67 | FILES_${PN}-base = "/init /init.d/99-finish /dev" |
| 59 | 68 | ||
| @@ -88,3 +97,7 @@ FILES_initramfs-module-rootfs = "/init.d/90-rootfs" | |||
| 88 | SUMMARY_initramfs-module-debug = "initramfs dynamic debug support" | 97 | SUMMARY_initramfs-module-debug = "initramfs dynamic debug support" |
| 89 | RDEPENDS_initramfs-module-debug = "${PN}-base" | 98 | RDEPENDS_initramfs-module-debug = "${PN}-base" |
| 90 | FILES_initramfs-module-debug = "/init.d/00-debug" | 99 | FILES_initramfs-module-debug = "/init.d/00-debug" |
| 100 | |||
| 101 | SUMMARY_initramfs-module-install-efi = "initramfs support for installation option" | ||
| 102 | RDEPENDS_initramfs-module-install-efi = "${PN}-base parted e2fsprogs-mke2fs dosfstools util-linux-blkid" | ||
| 103 | FILES_initramfs-module-install-efi = "/init.d/install-efi.sh" | ||
