diff options
Diffstat (limited to 'meta/recipes-core/initrdscripts/files/init-install-efi.sh')
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init-install-efi.sh | 178 |
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 | |||
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 | 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 | swap_size=$((disk_size*swap_ratio/100)) | ||
75 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
76 | |||
77 | rootfs_start=$((boot_size)) | ||
78 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
79 | swap_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 | swap=/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 "Swap partition size: $swap_size MB ($swap)" | ||
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 | |||
108 | echo "Creating rootfs partition on $rootfs" | ||
109 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
110 | |||
111 | echo "Creating swap partition on $swap" | ||
112 | parted /dev/${device} mkpart primary $swap_start 100% | ||
113 | |||
114 | parted /dev/${device} print | ||
115 | |||
116 | echo "Formatting $bootfs to vfat..." | ||
117 | mkfs.vfat $bootfs | ||
118 | |||
119 | echo "Formatting $rootfs to ext3..." | ||
120 | mkfs.ext3 $rootfs | ||
121 | |||
122 | echo "Formatting swap partition...($swap)" | ||
123 | mkswap $swap | ||
124 | |||
125 | mkdir /ssd | ||
126 | mkdir /rootmnt | ||
127 | mkdir /bootmnt | ||
128 | |||
129 | mount $rootfs /ssd | ||
130 | mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt | ||
131 | |||
132 | echo "Copying rootfs files..." | ||
133 | cp -a /rootmnt/* /ssd | ||
134 | |||
135 | if [ -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 | ||
142 | fi | ||
143 | |||
144 | umount /ssd | ||
145 | umount /rootmnt | ||
146 | |||
147 | echo "Preparing boot partition..." | ||
148 | mount $bootfs /ssd | ||
149 | |||
150 | EFIDIR="/ssd/EFI/BOOT" | ||
151 | mkdir -p $EFIDIR | ||
152 | GRUBCFG="$EFIDIR/grub.cfg" | ||
153 | |||
154 | cp /media/$1/vmlinuz /ssd | ||
155 | # Copy the efi loader and config (booti*.efi and grub.cfg) | ||
156 | cp /media/$1/EFI/BOOT/* $EFIDIR | ||
157 | |||
158 | # Update grub config for the installed image | ||
159 | # Delete the install entry | ||
160 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
161 | # Delete the initrd lines | ||
162 | sed -i "/initrd /d" $GRUBCFG | ||
163 | # Delete any LABEL= strings | ||
164 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
165 | # Delete any root= strings | ||
166 | sed -i "s/ root=[^ ]*/ /" $GRUBCFG | ||
167 | # Add the root= and other standard boot options | ||
168 | sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG | ||
169 | |||
170 | umount /ssd | ||
171 | sync | ||
172 | |||
173 | echo "Remove your installation media, and press ENTER" | ||
174 | |||
175 | read enter | ||
176 | |||
177 | echo "Rebooting..." | ||
178 | reboot -f | ||