diff options
4 files changed, 438 insertions, 0 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh new file mode 100644 index 0000000000..2fea7610f9 --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh | |||
| @@ -0,0 +1,199 @@ | |||
| 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 200 Mb for the boot partition | ||
| 12 | boot_size=200 | ||
| 13 | |||
| 14 | # 50% for the second rootfs | ||
| 15 | testfs_ratio=50 | ||
| 16 | |||
| 17 | found="no" | ||
| 18 | |||
| 19 | echo "Searching for a hard drive..." | ||
| 20 | for device in 'hda' 'hdb' 'sda' 'sdb' 'mmcblk0' 'mmcblk1' | ||
| 21 | do | ||
| 22 | if [ -e /sys/block/${device}/removable ]; then | ||
| 23 | if [ "$(cat /sys/block/${device}/removable)" = "0" ]; then | ||
| 24 | found="yes" | ||
| 25 | |||
| 26 | while true; do | ||
| 27 | # Try sleeping here to avoid getting kernel messages | ||
| 28 | # obscuring/confusing user | ||
| 29 | sleep 5 | ||
| 30 | echo "Found drive at /dev/${device}. Do you want to install this image there ? [y/n]" | ||
| 31 | read answer | ||
| 32 | if [ "$answer" = "y" ] ; then | ||
| 33 | break | ||
| 34 | fi | ||
| 35 | |||
| 36 | if [ "$answer" = "n" ] ; then | ||
| 37 | found=no | ||
| 38 | break | ||
| 39 | fi | ||
| 40 | |||
| 41 | echo "Please answer y or n" | ||
| 42 | done | ||
| 43 | fi | ||
| 44 | fi | ||
| 45 | |||
| 46 | if [ "$found" = "yes" ]; then | ||
| 47 | break; | ||
| 48 | fi | ||
| 49 | |||
| 50 | done | ||
| 51 | |||
| 52 | if [ "$found" = "no" ]; then | ||
| 53 | exit 1 | ||
| 54 | fi | ||
| 55 | |||
| 56 | echo "Installing image on /dev/${device}" | ||
| 57 | |||
| 58 | # | ||
| 59 | # The udev automounter can cause pain here, kill it | ||
| 60 | # | ||
| 61 | rm -f /etc/udev/rules.d/automount.rules | ||
| 62 | rm -f /etc/udev/scripts/mount* | ||
| 63 | |||
| 64 | # | ||
| 65 | # Unmount anything the automounter had mounted | ||
| 66 | # | ||
| 67 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
| 68 | |||
| 69 | mkdir -p /tmp | ||
| 70 | cat /proc/mounts > /etc/mtab | ||
| 71 | |||
| 72 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
| 73 | |||
| 74 | testfs_size=$((disk_size*testfs_ratio/100)) | ||
| 75 | rootfs_size=$((disk_size-boot_size-testfs_size)) | ||
| 76 | |||
| 77 | rootfs_start=$((boot_size)) | ||
| 78 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
| 79 | testfs_start=$((rootfs_end)) | ||
| 80 | |||
| 81 | # MMC devices are special in a couple of ways | ||
| 82 | # 1) they use a partition prefix character 'p' | ||
| 83 | # 2) they are detected asynchronously (need rootwait) | ||
| 84 | rootwait="" | ||
| 85 | part_prefix="" | ||
| 86 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
| 87 | part_prefix="p" | ||
| 88 | rootwait="rootwait" | ||
| 89 | fi | ||
| 90 | bootfs=/dev/${device}${part_prefix}1 | ||
| 91 | rootfs=/dev/${device}${part_prefix}2 | ||
| 92 | testfs=/dev/${device}${part_prefix}3 | ||
| 93 | |||
| 94 | echo "*****************" | ||
| 95 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
| 96 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
| 97 | echo "Testfs partition size: $testfs_size MB ($testfs)" | ||
| 98 | echo "*****************" | ||
| 99 | echo "Deleting partition table on /dev/${device} ..." | ||
| 100 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
| 101 | |||
| 102 | echo "Creating new partition table on /dev/${device} ..." | ||
| 103 | parted /dev/${device} mklabel gpt | ||
| 104 | |||
| 105 | echo "Creating boot partition on $bootfs" | ||
| 106 | parted /dev/${device} mkpart primary 0% $boot_size | ||
| 107 | parted /dev/${device} set 1 boot on | ||
| 108 | |||
| 109 | echo "Creating rootfs partition on $rootfs" | ||
| 110 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
| 111 | |||
| 112 | echo "Creating testfs partition on $testfs" | ||
| 113 | parted /dev/${device} mkpart primary $testfs_start 100% | ||
| 114 | |||
| 115 | parted /dev/${device} print | ||
| 116 | |||
| 117 | echo "Formatting $bootfs to vfat..." | ||
| 118 | mkfs.vfat -n "boot" $bootfs | ||
| 119 | |||
| 120 | echo "Formatting $rootfs to ext3..." | ||
| 121 | mkfs.ext3 -L "platform" $rootfs | ||
| 122 | |||
| 123 | echo "Formatting $testfs to ext3..." | ||
| 124 | mkfs.ext3 -L "testrootfs" $testfs | ||
| 125 | |||
| 126 | mkdir /ssd | ||
| 127 | mkdir /rootmnt | ||
| 128 | mkdir /bootmnt | ||
| 129 | |||
| 130 | mount $rootfs /ssd | ||
| 131 | mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt | ||
| 132 | |||
| 133 | echo "Copying rootfs files..." | ||
| 134 | cp -a /rootmnt/* /ssd | ||
| 135 | |||
| 136 | touch /ssd/etc/masterimage | ||
| 137 | |||
| 138 | if [ -d /ssd/etc/ ] ; then | ||
| 139 | # We dont want udev to mount our root device while we're booting... | ||
| 140 | if [ -d /ssd/etc/udev/ ] ; then | ||
| 141 | echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist | ||
| 142 | fi | ||
| 143 | fi | ||
| 144 | |||
| 145 | umount /ssd | ||
| 146 | umount /rootmnt | ||
| 147 | |||
| 148 | echo "Preparing boot partition..." | ||
| 149 | mount $bootfs /ssd | ||
| 150 | |||
| 151 | EFIDIR="/ssd/EFI/BOOT" | ||
| 152 | mkdir -p $EFIDIR | ||
| 153 | cp /media/$1/vmlinuz /ssd | ||
| 154 | # Copy the efi loader | ||
| 155 | cp /media/$1/EFI/BOOT/*.efi $EFIDIR | ||
| 156 | |||
| 157 | if [ -f /media/$1/EFI/BOOT/grub.cfg ]; then | ||
| 158 | GRUBCFG="$EFIDIR/grub.cfg" | ||
| 159 | cp /media/$1/EFI/BOOT/grub.cfg $GRUBCFG | ||
| 160 | # Update grub config for the installed image | ||
| 161 | # Delete the install entry | ||
| 162 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
| 163 | # Delete the initrd lines | ||
| 164 | sed -i "/initrd /d" $GRUBCFG | ||
| 165 | # Delete any LABEL= strings | ||
| 166 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
| 167 | # Delete any root= strings | ||
| 168 | sed -i "s/ root=[^ ]*/ /" $GRUBCFG | ||
| 169 | # Add the root= and other standard boot options | ||
| 170 | sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG | ||
| 171 | fi | ||
| 172 | |||
| 173 | if [ -d /media/$1/loader ]; then | ||
| 174 | GUMMIBOOT_CFGS="/ssd/loader/entries/*.conf" | ||
| 175 | # copy config files for gummiboot | ||
| 176 | cp -dr /media/$1/loader /ssd | ||
| 177 | # delete the install entry | ||
| 178 | rm -f /ssd/loader/entries/install.conf | ||
| 179 | # delete the initrd lines | ||
| 180 | sed -i "/initrd /d" $GUMMIBOOT_CFGS | ||
| 181 | # delete any LABEL= strings | ||
| 182 | sed -i "s/ LABEL=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
| 183 | # delete any root= strings | ||
| 184 | sed -i "s/ root=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
| 185 | # add the root= and other standard boot options | ||
| 186 | sed -i "s@options *@options root=$rootfs rw $rootwait quiet @" $GUMMIBOOT_CFGS | ||
| 187 | # Add the test label | ||
| 188 | echo -ne "title test\nlinux /test-kernel\noptions root=$testfs rw $rootwait quiet\n" > /ssd/loader/entries/test.conf | ||
| 189 | fi | ||
| 190 | |||
| 191 | umount /ssd | ||
| 192 | sync | ||
| 193 | |||
| 194 | echo "Remove your installation media, and press ENTER" | ||
| 195 | |||
| 196 | read enter | ||
| 197 | |||
| 198 | echo "Rebooting..." | ||
| 199 | reboot -f | ||
diff --git a/meta/recipes-core/initrdscripts/files/init-install-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh new file mode 100644 index 0000000000..d2f2420498 --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | #!/bin/sh -e | ||
| 2 | # | ||
| 3 | # Copyright (C) 2008-2011 Intel | ||
| 4 | # | ||
| 5 | # install.sh [device_name] [rootfs_name] [video_mode] [vga_mode] | ||
| 6 | # | ||
| 7 | |||
| 8 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
| 9 | |||
| 10 | # We need 20 Mb for the boot partition | ||
| 11 | boot_size=200 | ||
| 12 | |||
| 13 | # 50% for the the test partition | ||
| 14 | testfs_ratio=50 | ||
| 15 | |||
| 16 | # Get a list of hard drives | ||
| 17 | hdnamelist="" | ||
| 18 | live_dev_name=${1%%/*} | ||
| 19 | |||
| 20 | echo "Searching for hard drives ..." | ||
| 21 | |||
| 22 | for device in `ls /sys/block/`; do | ||
| 23 | case $device in | ||
| 24 | loop*) | ||
| 25 | # skip loop device | ||
| 26 | ;; | ||
| 27 | ram*) | ||
| 28 | # skip ram device | ||
| 29 | ;; | ||
| 30 | *) | ||
| 31 | # skip the device LiveOS is on | ||
| 32 | # Add valid hard drive name to the list | ||
| 33 | if [ $device != $live_dev_name -a -e /dev/$device ]; then | ||
| 34 | hdnamelist="$hdnamelist $device" | ||
| 35 | fi | ||
| 36 | ;; | ||
| 37 | esac | ||
| 38 | done | ||
| 39 | |||
| 40 | TARGET_DEVICE_NAME="" | ||
| 41 | for hdname in $hdnamelist; do | ||
| 42 | # Display found hard drives and their basic info | ||
| 43 | echo "-------------------------------" | ||
| 44 | echo /dev/$hdname | ||
| 45 | if [ -r /sys/block/$hdname/device/vendor ]; then | ||
| 46 | echo -n "VENDOR=" | ||
| 47 | cat /sys/block/$hdname/device/vendor | ||
| 48 | fi | ||
| 49 | echo -n "MODEL=" | ||
| 50 | cat /sys/block/$hdname/device/model | ||
| 51 | cat /sys/block/$hdname/device/uevent | ||
| 52 | echo | ||
| 53 | # Get user choice | ||
| 54 | while true; do | ||
| 55 | echo -n "Do you want to install this image there? [y/n] " | ||
| 56 | read answer | ||
| 57 | if [ "$answer" = "y" -o "$answer" = "n" ]; then | ||
| 58 | break | ||
| 59 | fi | ||
| 60 | echo "Please answer y or n" | ||
| 61 | done | ||
| 62 | if [ "$answer" = "y" ]; then | ||
| 63 | TARGET_DEVICE_NAME=$hdname | ||
| 64 | break | ||
| 65 | fi | ||
| 66 | done | ||
| 67 | |||
| 68 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
| 69 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
| 70 | else | ||
| 71 | echo "No hard drive selected. Installation aborted." | ||
| 72 | exit 1 | ||
| 73 | fi | ||
| 74 | |||
| 75 | device=$TARGET_DEVICE_NAME | ||
| 76 | |||
| 77 | # | ||
| 78 | # The udev automounter can cause pain here, kill it | ||
| 79 | # | ||
| 80 | rm -f /etc/udev/rules.d/automount.rules | ||
| 81 | rm -f /etc/udev/scripts/mount* | ||
| 82 | |||
| 83 | # | ||
| 84 | # Unmount anything the automounter had mounted | ||
| 85 | # | ||
| 86 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
| 87 | |||
| 88 | if [ ! -b /dev/loop0 ] ; then | ||
| 89 | mknod /dev/loop0 b 7 0 | ||
| 90 | fi | ||
| 91 | |||
| 92 | mkdir -p /tmp | ||
| 93 | cat /proc/mounts > /etc/mtab | ||
| 94 | |||
| 95 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
| 96 | |||
| 97 | testfs_size=$((disk_size*testfs_ratio/100)) | ||
| 98 | rootfs_size=$((disk_size-boot_size-testfs_size)) | ||
| 99 | |||
| 100 | rootfs_start=$((boot_size)) | ||
| 101 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
| 102 | testfs_start=$((rootfs_end)) | ||
| 103 | |||
| 104 | # MMC devices are special in a couple of ways | ||
| 105 | # 1) they use a partition prefix character 'p' | ||
| 106 | # 2) they are detected asynchronously (need rootwait) | ||
| 107 | rootwait="" | ||
| 108 | part_prefix="" | ||
| 109 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
| 110 | part_prefix="p" | ||
| 111 | rootwait="rootwait" | ||
| 112 | fi | ||
| 113 | bootfs=/dev/${device}${part_prefix}1 | ||
| 114 | rootfs=/dev/${device}${part_prefix}2 | ||
| 115 | testfs=/dev/${device}${part_prefix}3 | ||
| 116 | |||
| 117 | echo "*****************" | ||
| 118 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
| 119 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
| 120 | echo "Testfs partition size: $testfs_size MB ($testfs)" | ||
| 121 | echo "*****************" | ||
| 122 | echo "Deleting partition table on /dev/${device} ..." | ||
| 123 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
| 124 | |||
| 125 | echo "Creating new partition table on /dev/${device} ..." | ||
| 126 | parted /dev/${device} mklabel msdos | ||
| 127 | |||
| 128 | echo "Creating boot partition on $bootfs" | ||
| 129 | parted /dev/${device} mkpart primary 0% $boot_size | ||
| 130 | |||
| 131 | echo "Creating rootfs partition on $rootfs" | ||
| 132 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
| 133 | |||
| 134 | echo "Creating testfs partition on $testfs" | ||
| 135 | parted /dev/${device} mkpart primary $testfs_start 100% | ||
| 136 | |||
| 137 | parted /dev/${device} print | ||
| 138 | |||
| 139 | echo "Formatting $bootfs to ext3..." | ||
| 140 | mkfs.ext3 -L "boot" $bootfs | ||
| 141 | |||
| 142 | echo "Formatting $rootfs to ext3..." | ||
| 143 | mkfs.ext3 -L "rootfs" $rootfs | ||
| 144 | |||
| 145 | echo "Formatting $testfs to ext3..." | ||
| 146 | mkfs.ext3 -L "testrootfs" $testfs | ||
| 147 | |||
| 148 | mkdir /tgt_root | ||
| 149 | mkdir /src_root | ||
| 150 | mkdir -p /boot | ||
| 151 | |||
| 152 | # Handling of the target root partition | ||
| 153 | mount $rootfs /tgt_root | ||
| 154 | mount -o rw,loop,noatime,nodiratime /media/$1/$2 /src_root | ||
| 155 | echo "Copying rootfs files..." | ||
| 156 | cp -a /src_root/* /tgt_root | ||
| 157 | if [ -d /tgt_root/etc/ ] ; then | ||
| 158 | echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab | ||
| 159 | # We dont want udev to mount our root device while we're booting... | ||
| 160 | if [ -d /tgt_root/etc/udev/ ] ; then | ||
| 161 | echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist | ||
| 162 | fi | ||
| 163 | fi | ||
| 164 | umount /tgt_root | ||
| 165 | umount /src_root | ||
| 166 | |||
| 167 | # Handling of the target boot partition | ||
| 168 | mount $bootfs /boot | ||
| 169 | echo "Preparing boot partition..." | ||
| 170 | if [ -f /etc/grub.d/40_custom ] ; then | ||
| 171 | echo "Preparing custom grub2 menu..." | ||
| 172 | GRUBCFG="/boot/grub/grub.cfg" | ||
| 173 | mkdir -p $(dirname $GRUBCFG) | ||
| 174 | cp /etc/grub.d/40_custom $GRUBCFG | ||
| 175 | sed -i "s@__ROOTFS__@$rootfs $rootwait@g" $GRUBCFG | ||
| 176 | sed -i "s/__VIDEO_MODE__/$3/g" $GRUBCFG | ||
| 177 | sed -i "s/__VGA_MODE__/$4/g" $GRUBCFG | ||
| 178 | sed -i "s/__CONSOLE__/$5/g" $GRUBCFG | ||
| 179 | sed -i "/#/d" $GRUBCFG | ||
| 180 | sed -i "/exec tail/d" $GRUBCFG | ||
| 181 | |||
| 182 | # Add the test label | ||
| 183 | echo -ne "\nmenuentry 'test' {\nlinux /test-kernel root=$testfs rw $rootwait quiet\n}\n" >> $GRUBCFG | ||
| 184 | |||
| 185 | chmod 0444 $GRUBCFG | ||
| 186 | fi | ||
| 187 | grub-install /dev/${device} | ||
| 188 | echo "(hd0) /dev/${device}" > /boot/grub/device.map | ||
| 189 | |||
| 190 | # If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst | ||
| 191 | if [ ! -f /boot/grub/grub.cfg ] ; then | ||
| 192 | echo "Preparing custom grub menu..." | ||
| 193 | echo "default 0" > /boot/grub/menu.lst | ||
| 194 | echo "timeout 30" >> /boot/grub/menu.lst | ||
| 195 | echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst | ||
| 196 | echo "root (hd0,0)" >> /boot/grub/menu.lst | ||
| 197 | echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst | ||
| 198 | fi | ||
| 199 | |||
| 200 | cp /media/$1/vmlinuz /boot/ | ||
| 201 | |||
| 202 | umount /boot | ||
| 203 | |||
| 204 | sync | ||
| 205 | |||
| 206 | echo "Remove your installation media, and press ENTER" | ||
| 207 | |||
| 208 | read enter | ||
| 209 | |||
| 210 | echo "Rebooting..." | ||
| 211 | reboot -f | ||
diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb new file mode 100644 index 0000000000..a54960c596 --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | SUMMARY = "Live image install script for with a second rootfs/kernel option" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | SRC_URI = "file://init-install-efi-testfs.sh" | ||
| 5 | |||
| 6 | RDEPENDS_${PN} = "parted e2fsprogs-mke2fs dosfstools" | ||
| 7 | |||
| 8 | do_install() { | ||
| 9 | install -m 0755 ${WORKDIR}/init-install-efi-testfs.sh ${D}/install-efi.sh | ||
| 10 | } | ||
| 11 | |||
| 12 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 13 | FILES_${PN} = " /install-efi.sh " | ||
| 14 | COMPATIBLE_HOST = "(i.86|x86_64).*-linux" | ||
diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb new file mode 100644 index 0000000000..db4cf544e8 --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | SUMMARY = "Live image install script with a second rootfs/kernel" | ||
| 2 | LICENSE = "MIT" | ||
| 3 | LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" | ||
| 4 | SRC_URI = "file://init-install-testfs.sh" | ||
| 5 | |||
| 6 | RDEPENDS_${PN} = "grub parted e2fsprogs-mke2fs" | ||
| 7 | |||
| 8 | do_install() { | ||
| 9 | install -m 0755 ${WORKDIR}/init-install-testfs.sh ${D}/install.sh | ||
| 10 | } | ||
| 11 | |||
| 12 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 13 | FILES_${PN} = " /install.sh " | ||
| 14 | COMPATIBLE_HOST = "(i.86|x86_64).*-linux" | ||
