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.sh230
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
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
17# Get a list of hard drives
18hdnamelist=""
19live_dev_name=${1%%/*}
20live_dev_name=${live_dev_name%%[0-9]*}
21
22echo "Searching for hard drives ..."
23
24for 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
43done
44
45TARGET_DEVICE_NAME=""
46for 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
77done
78
79if [ -n "$TARGET_DEVICE_NAME" ]; then
80 echo "Installing image on /dev/$TARGET_DEVICE_NAME ..."
81else
82 echo "No hard drive selected. Installation aborted."
83 exit 1
84fi
85
86device=$TARGET_DEVICE_NAME
87
88#
89# The udev automounter can cause pain here, kill it
90#
91rm -f /etc/udev/rules.d/automount.rules
92rm -f /etc/udev/scripts/mount*
93
94#
95# Unmount anything the automounter had mounted
96#
97umount /dev/${device}* 2> /dev/null || /bin/true
98
99mkdir -p /tmp
100cat /proc/mounts > /etc/mtab
101
102disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
103
104swap_size=$((disk_size*swap_ratio/100))
105rootfs_size=$((disk_size-boot_size-swap_size))
106
107rootfs_start=$((boot_size))
108rootfs_end=$((rootfs_start+rootfs_size))
109swap_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)
114rootwait=""
115part_prefix=""
116if [ ! "${device#mmcblk}" = "${device}" ]; then
117 part_prefix="p"
118 rootwait="rootwait"
119fi
120bootfs=/dev/${device}${part_prefix}1
121rootfs=/dev/${device}${part_prefix}2
122swap=/dev/${device}${part_prefix}3
123
124echo "*****************"
125echo "Boot partition size: $boot_size MB ($bootfs)"
126echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
127echo "Swap partition size: $swap_size MB ($swap)"
128echo "*****************"
129echo "Deleting partition table on /dev/${device} ..."
130dd if=/dev/zero of=/dev/${device} bs=512 count=2
131
132echo "Creating new partition table on /dev/${device} ..."
133parted /dev/${device} mklabel gpt
134
135echo "Creating boot partition on $bootfs"
136parted /dev/${device} mkpart primary 0% $boot_size
137parted /dev/${device} set 1 boot on
138
139echo "Creating rootfs partition on $rootfs"
140parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
141
142echo "Creating swap partition on $swap"
143parted /dev/${device} mkpart primary $swap_start 100%
144
145parted /dev/${device} print
146
147echo "Formatting $bootfs to vfat..."
148mkfs.vfat $bootfs
149
150echo "Formatting $rootfs to ext3..."
151mkfs.ext3 $rootfs
152
153echo "Formatting swap partition...($swap)"
154mkswap $swap
155
156mkdir /tgt_root
157mkdir /src_root
158mkdir -p /boot
159
160# Handling of the target root partition
161mount $rootfs /tgt_root
162mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
163echo "Copying rootfs files..."
164cp -a /src_root/* /tgt_root
165if [ -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
172fi
173
174umount /src_root
175
176# Handling of the target boot partition
177mount $bootfs /boot
178echo "Preparing boot partition..."
179
180EFIDIR="/boot/EFI/BOOT"
181mkdir -p $EFIDIR
182# Copy the efi loader
183cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
184
185if [ -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
199fi
200
201if [ -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
215fi
216
217umount /tgt_root
218
219cp /run/media/$1/vmlinuz /boot
220
221umount /boot
222
223sync
224
225echo "Remove your installation media, and press ENTER"
226
227read enter
228
229echo "Rebooting..."
230reboot -f