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 | 230 |
1 files changed, 230 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..329586d74d --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-install-efi.sh | |||
@@ -0,0 +1,230 @@ | |||
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=${1%%/*} | ||
20 | live_dev_name=${live_dev_name%%[0-9]*} | ||
21 | |||
22 | echo "Searching for hard drives ..." | ||
23 | |||
24 | for device in `ls /sys/block/`; do | ||
25 | case $device in | ||
26 | loop*) | ||
27 | # skip loop device | ||
28 | ;; | ||
29 | sr*) | ||
30 | # skip CDROM device | ||
31 | ;; | ||
32 | ram*) | ||
33 | # skip ram device | ||
34 | ;; | ||
35 | *) | ||
36 | # skip the device LiveOS is on | ||
37 | # Add valid hard drive name to the list | ||
38 | if [ $device != $live_dev_name -a -e /dev/$device ]; then | ||
39 | hdnamelist="$hdnamelist $device" | ||
40 | fi | ||
41 | ;; | ||
42 | esac | ||
43 | done | ||
44 | |||
45 | TARGET_DEVICE_NAME="" | ||
46 | for hdname in $hdnamelist; do | ||
47 | # Display found hard drives and their basic info | ||
48 | echo "-------------------------------" | ||
49 | echo /dev/$hdname | ||
50 | if [ -r /sys/block/$hdname/device/vendor ]; then | ||
51 | echo -n "VENDOR=" | ||
52 | cat /sys/block/$hdname/device/vendor | ||
53 | fi | ||
54 | if [ -r /sys/block/$hdname/device/model ]; then | ||
55 | echo -n "MODEL=" | ||
56 | cat /sys/block/$hdname/device/model | ||
57 | fi | ||
58 | if [ -r /sys/block/$hdname/device/uevent ]; then | ||
59 | echo -n "UEVENT=" | ||
60 | cat /sys/block/$hdname/device/uevent | ||
61 | fi | ||
62 | echo | ||
63 | # Get user choice | ||
64 | while true; do | ||
65 | echo -n "Do you want to install this image there? [y/n] " | ||
66 | read answer | ||
67 | if [ "$answer" = "y" -o "$answer" = "n" ]; then | ||
68 | break | ||
69 | fi | ||
70 | echo "Please answer y or n" | ||
71 | done | ||
72 | if [ "$answer" = "y" ]; then | ||
73 | TARGET_DEVICE_NAME=$hdname | ||
74 | break | ||
75 | fi | ||
76 | |||
77 | done | ||
78 | |||
79 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
80 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
81 | else | ||
82 | echo "No hard drive selected. Installation aborted." | ||
83 | exit 1 | ||
84 | fi | ||
85 | |||
86 | device=$TARGET_DEVICE_NAME | ||
87 | |||
88 | # | ||
89 | # The udev automounter can cause pain here, kill it | ||
90 | # | ||
91 | rm -f /etc/udev/rules.d/automount.rules | ||
92 | rm -f /etc/udev/scripts/mount* | ||
93 | |||
94 | # | ||
95 | # Unmount anything the automounter had mounted | ||
96 | # | ||
97 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
98 | |||
99 | mkdir -p /tmp | ||
100 | cat /proc/mounts > /etc/mtab | ||
101 | |||
102 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
103 | |||
104 | swap_size=$((disk_size*swap_ratio/100)) | ||
105 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
106 | |||
107 | rootfs_start=$((boot_size)) | ||
108 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
109 | swap_start=$((rootfs_end)) | ||
110 | |||
111 | # MMC devices are special in a couple of ways | ||
112 | # 1) they use a partition prefix character 'p' | ||
113 | # 2) they are detected asynchronously (need rootwait) | ||
114 | rootwait="" | ||
115 | part_prefix="" | ||
116 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
117 | part_prefix="p" | ||
118 | rootwait="rootwait" | ||
119 | fi | ||
120 | bootfs=/dev/${device}${part_prefix}1 | ||
121 | rootfs=/dev/${device}${part_prefix}2 | ||
122 | swap=/dev/${device}${part_prefix}3 | ||
123 | |||
124 | echo "*****************" | ||
125 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
126 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
127 | echo "Swap partition size: $swap_size MB ($swap)" | ||
128 | echo "*****************" | ||
129 | echo "Deleting partition table on /dev/${device} ..." | ||
130 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
131 | |||
132 | echo "Creating new partition table on /dev/${device} ..." | ||
133 | parted /dev/${device} mklabel gpt | ||
134 | |||
135 | echo "Creating boot partition on $bootfs" | ||
136 | parted /dev/${device} mkpart primary 0% $boot_size | ||
137 | parted /dev/${device} set 1 boot on | ||
138 | |||
139 | echo "Creating rootfs partition on $rootfs" | ||
140 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
141 | |||
142 | echo "Creating swap partition on $swap" | ||
143 | parted /dev/${device} mkpart primary $swap_start 100% | ||
144 | |||
145 | parted /dev/${device} print | ||
146 | |||
147 | echo "Formatting $bootfs to vfat..." | ||
148 | mkfs.vfat $bootfs | ||
149 | |||
150 | echo "Formatting $rootfs to ext3..." | ||
151 | mkfs.ext3 $rootfs | ||
152 | |||
153 | echo "Formatting swap partition...($swap)" | ||
154 | mkswap $swap | ||
155 | |||
156 | mkdir /tgt_root | ||
157 | mkdir /src_root | ||
158 | mkdir -p /boot | ||
159 | |||
160 | # Handling of the target root partition | ||
161 | mount $rootfs /tgt_root | ||
162 | mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root | ||
163 | echo "Copying rootfs files..." | ||
164 | cp -a /src_root/* /tgt_root | ||
165 | if [ -d /tgt_root/etc/ ] ; then | ||
166 | echo "$swap swap swap defaults 0 0" >> /tgt_root/etc/fstab | ||
167 | echo "$bootfs /boot vfat defaults 1 2" >> /tgt_root/etc/fstab | ||
168 | # We dont want udev to mount our root device while we're booting... | ||
169 | if [ -d /tgt_root/etc/udev/ ] ; then | ||
170 | echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist | ||
171 | fi | ||
172 | fi | ||
173 | |||
174 | umount /src_root | ||
175 | |||
176 | # Handling of the target boot partition | ||
177 | mount $bootfs /boot | ||
178 | echo "Preparing boot partition..." | ||
179 | |||
180 | EFIDIR="/boot/EFI/BOOT" | ||
181 | mkdir -p $EFIDIR | ||
182 | # Copy the efi loader | ||
183 | cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR | ||
184 | |||
185 | if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then | ||
186 | GRUBCFG="$EFIDIR/grub.cfg" | ||
187 | cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG | ||
188 | # Update grub config for the installed image | ||
189 | # Delete the install entry | ||
190 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
191 | # Delete the initrd lines | ||
192 | sed -i "/initrd /d" $GRUBCFG | ||
193 | # Delete any LABEL= strings | ||
194 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
195 | # Delete any root= strings | ||
196 | sed -i "s/ root=[^ ]*/ /" $GRUBCFG | ||
197 | # Add the root= and other standard boot options | ||
198 | sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG | ||
199 | fi | ||
200 | |||
201 | if [ -d /run/media/$1/loader ]; then | ||
202 | GUMMIBOOT_CFGS="/boot/loader/entries/*.conf" | ||
203 | # copy config files for gummiboot | ||
204 | cp -dr /run/media/$1/loader /boot | ||
205 | # delete the install entry | ||
206 | rm -f /boot/loader/entries/install.conf | ||
207 | # delete the initrd lines | ||
208 | sed -i "/initrd /d" $GUMMIBOOT_CFGS | ||
209 | # delete any LABEL= strings | ||
210 | sed -i "s/ LABEL=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
211 | # delete any root= strings | ||
212 | sed -i "s/ root=[^ ]*/ /" $GUMMIBOOT_CFGS | ||
213 | # add the root= and other standard boot options | ||
214 | sed -i "s@options *@options root=$rootfs rw $rootwait quiet @" $GUMMIBOOT_CFGS | ||
215 | fi | ||
216 | |||
217 | umount /tgt_root | ||
218 | |||
219 | cp /run/media/$1/vmlinuz /boot | ||
220 | |||
221 | umount /boot | ||
222 | |||
223 | sync | ||
224 | |||
225 | echo "Remove your installation media, and press ENTER" | ||
226 | |||
227 | read enter | ||
228 | |||
229 | echo "Rebooting..." | ||
230 | reboot -f | ||