summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initrdscripts/files/init-install-efi.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/initrdscripts/files/init-install-efi.sh')
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install-efi.sh178
1 files changed, 178 insertions, 0 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi.sh b/meta/recipes-core/initrdscripts/files/init-install-efi.sh
new file mode 100644
index 0000000000..9846637316
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-install-efi.sh
@@ -0,0 +1,178 @@
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
17found="no"
18
19echo "Searching for a hard drive..."
20for device in 'hda' 'hdb' 'sda' 'sdb' 'mmcblk0' 'mmcblk1'
21do
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
50done
51
52if [ "$found" = "no" ]; then
53 exit 1
54fi
55
56echo "Installing image on /dev/${device}"
57
58#
59# The udev automounter can cause pain here, kill it
60#
61rm -f /etc/udev/rules.d/automount.rules
62rm -f /etc/udev/scripts/mount*
63
64#
65# Unmount anything the automounter had mounted
66#
67umount /dev/${device}* 2> /dev/null || /bin/true
68
69mkdir -p /tmp
70cat /proc/mounts > /etc/mtab
71
72disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
73
74swap_size=$((disk_size*swap_ratio/100))
75rootfs_size=$((disk_size-boot_size-swap_size))
76
77rootfs_start=$((boot_size))
78rootfs_end=$((rootfs_start+rootfs_size))
79swap_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)
84rootwait=""
85part_prefix=""
86if [ ! "${device#mmcblk}" = "${device}" ]; then
87 part_prefix="p"
88 rootwait="rootwait"
89fi
90bootfs=/dev/${device}${part_prefix}1
91rootfs=/dev/${device}${part_prefix}2
92swap=/dev/${device}${part_prefix}3
93
94echo "*****************"
95echo "Boot partition size: $boot_size MB ($bootfs)"
96echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
97echo "Swap partition size: $swap_size MB ($swap)"
98echo "*****************"
99echo "Deleting partition table on /dev/${device} ..."
100dd if=/dev/zero of=/dev/${device} bs=512 count=2
101
102echo "Creating new partition table on /dev/${device} ..."
103parted /dev/${device} mklabel gpt
104
105echo "Creating boot partition on $bootfs"
106parted /dev/${device} mkpart primary 0% $boot_size
107
108echo "Creating rootfs partition on $rootfs"
109parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
110
111echo "Creating swap partition on $swap"
112parted /dev/${device} mkpart primary $swap_start 100%
113
114parted /dev/${device} print
115
116echo "Formatting $bootfs to vfat..."
117mkfs.vfat $bootfs
118
119echo "Formatting $rootfs to ext3..."
120mkfs.ext3 $rootfs
121
122echo "Formatting swap partition...($swap)"
123mkswap $swap
124
125mkdir /ssd
126mkdir /rootmnt
127mkdir /bootmnt
128
129mount $rootfs /ssd
130mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt
131
132echo "Copying rootfs files..."
133cp -a /rootmnt/* /ssd
134
135if [ -d /ssd/etc/ ] ; then
136 echo "$swap swap swap defaults 0 0" >> /ssd/etc/fstab
137
138 # We dont want udev to mount our root device while we're booting...
139 if [ -d /ssd/etc/udev/ ] ; then
140 echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist
141 fi
142fi
143
144umount /ssd
145umount /rootmnt
146
147echo "Preparing boot partition..."
148mount $bootfs /ssd
149
150EFIDIR="/ssd/EFI/BOOT"
151mkdir -p $EFIDIR
152GRUBCFG="$EFIDIR/grub.cfg"
153
154cp /media/$1/vmlinuz /ssd
155# Copy the efi loader and config (booti*.efi and grub.cfg)
156cp /media/$1/EFI/BOOT/* $EFIDIR
157
158# Update grub config for the installed image
159# Delete the install entry
160sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG
161# Delete the initrd lines
162sed -i "/initrd /d" $GRUBCFG
163# Delete any LABEL= strings
164sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG
165# Delete any root= strings
166sed -i "s/ root=[^ ]*/ /" $GRUBCFG
167# Add the root= and other standard boot options
168sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG
169
170umount /ssd
171sync
172
173echo "Remove your installation media, and press ENTER"
174
175read enter
176
177echo "Rebooting..."
178reboot -f