diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /meta/recipes-core/initrdscripts/files/init-install.sh | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/recipes-core/initrdscripts/files/init-install.sh')
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init-install.sh | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init-install.sh b/meta/recipes-core/initrdscripts/files/init-install.sh new file mode 100644 index 0000000000..fb537ee310 --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-install.sh | |||
@@ -0,0 +1,218 @@ | |||
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=20 | ||
12 | |||
13 | # 5% for the swap | ||
14 | swap_ratio=5 | ||
15 | |||
16 | # Get a list of hard drives | ||
17 | hdnamelist="" | ||
18 | live_dev_name=${1%%/*} | ||
19 | live_dev_name=${live_dev_name%%[0-9]*} | ||
20 | |||
21 | echo "Searching for hard drives ..." | ||
22 | |||
23 | for device in `ls /sys/block/`; do | ||
24 | case $device in | ||
25 | loop*) | ||
26 | # skip loop device | ||
27 | ;; | ||
28 | sr*) | ||
29 | # skip CDROM device | ||
30 | ;; | ||
31 | ram*) | ||
32 | # skip ram device | ||
33 | ;; | ||
34 | *) | ||
35 | # skip the device LiveOS is on | ||
36 | # Add valid hard drive name to the list | ||
37 | if [ $device != $live_dev_name -a -e /dev/$device ]; then | ||
38 | hdnamelist="$hdnamelist $device" | ||
39 | fi | ||
40 | ;; | ||
41 | esac | ||
42 | done | ||
43 | |||
44 | TARGET_DEVICE_NAME="" | ||
45 | for hdname in $hdnamelist; do | ||
46 | # Display found hard drives and their basic info | ||
47 | echo "-------------------------------" | ||
48 | echo /dev/$hdname | ||
49 | if [ -r /sys/block/$hdname/device/vendor ]; then | ||
50 | echo -n "VENDOR=" | ||
51 | cat /sys/block/$hdname/device/vendor | ||
52 | fi | ||
53 | if [ -r /sys/block/$hdname/device/model ]; then | ||
54 | echo -n "MODEL=" | ||
55 | cat /sys/block/$hdname/device/model | ||
56 | fi | ||
57 | if [ -r /sys/block/$hdname/device/uevent ]; then | ||
58 | echo -n "UEVENT=" | ||
59 | cat /sys/block/$hdname/device/uevent | ||
60 | fi | ||
61 | echo | ||
62 | # Get user choice | ||
63 | while true; do | ||
64 | echo -n "Do you want to install this image there? [y/n] " | ||
65 | read answer | ||
66 | if [ "$answer" = "y" -o "$answer" = "n" ]; then | ||
67 | break | ||
68 | fi | ||
69 | echo "Please answer y or n" | ||
70 | done | ||
71 | if [ "$answer" = "y" ]; then | ||
72 | TARGET_DEVICE_NAME=$hdname | ||
73 | break | ||
74 | fi | ||
75 | done | ||
76 | |||
77 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
78 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
79 | else | ||
80 | echo "No hard drive selected. Installation aborted." | ||
81 | exit 1 | ||
82 | fi | ||
83 | |||
84 | device=$TARGET_DEVICE_NAME | ||
85 | |||
86 | # | ||
87 | # The udev automounter can cause pain here, kill it | ||
88 | # | ||
89 | rm -f /etc/udev/rules.d/automount.rules | ||
90 | rm -f /etc/udev/scripts/mount* | ||
91 | |||
92 | # | ||
93 | # Unmount anything the automounter had mounted | ||
94 | # | ||
95 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
96 | |||
97 | if [ ! -b /dev/loop0 ] ; then | ||
98 | mknod /dev/loop0 b 7 0 | ||
99 | fi | ||
100 | |||
101 | mkdir -p /tmp | ||
102 | if [ ! -L /etc/mtab ]; then | ||
103 | cat /proc/mounts > /etc/mtab | ||
104 | fi | ||
105 | |||
106 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
107 | |||
108 | swap_size=$((disk_size*swap_ratio/100)) | ||
109 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
110 | |||
111 | rootfs_start=$((boot_size)) | ||
112 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
113 | swap_start=$((rootfs_end)) | ||
114 | |||
115 | # MMC devices are special in a couple of ways | ||
116 | # 1) they use a partition prefix character 'p' | ||
117 | # 2) they are detected asynchronously (need rootwait) | ||
118 | rootwait="" | ||
119 | part_prefix="" | ||
120 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
121 | part_prefix="p" | ||
122 | rootwait="rootwait" | ||
123 | fi | ||
124 | bootfs=/dev/${device}${part_prefix}1 | ||
125 | rootfs=/dev/${device}${part_prefix}2 | ||
126 | swap=/dev/${device}${part_prefix}3 | ||
127 | |||
128 | echo "*****************" | ||
129 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
130 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
131 | echo "Swap partition size: $swap_size MB ($swap)" | ||
132 | echo "*****************" | ||
133 | echo "Deleting partition table on /dev/${device} ..." | ||
134 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
135 | |||
136 | echo "Creating new partition table on /dev/${device} ..." | ||
137 | parted /dev/${device} mklabel msdos | ||
138 | |||
139 | echo "Creating boot partition on $bootfs" | ||
140 | parted /dev/${device} mkpart primary 0% $boot_size | ||
141 | |||
142 | echo "Creating rootfs partition on $rootfs" | ||
143 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
144 | |||
145 | echo "Creating swap partition on $swap" | ||
146 | parted /dev/${device} mkpart primary $swap_start 100% | ||
147 | |||
148 | parted /dev/${device} print | ||
149 | |||
150 | echo "Formatting $bootfs to ext3..." | ||
151 | mkfs.ext3 $bootfs | ||
152 | |||
153 | echo "Formatting $rootfs to ext3..." | ||
154 | mkfs.ext3 $rootfs | ||
155 | |||
156 | echo "Formatting swap partition...($swap)" | ||
157 | mkswap $swap | ||
158 | |||
159 | mkdir /tgt_root | ||
160 | mkdir /src_root | ||
161 | mkdir -p /boot | ||
162 | |||
163 | # Handling of the target root partition | ||
164 | mount $rootfs /tgt_root | ||
165 | mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root | ||
166 | echo "Copying rootfs files..." | ||
167 | cp -a /src_root/* /tgt_root | ||
168 | if [ -d /tgt_root/etc/ ] ; then | ||
169 | echo "$swap swap swap defaults 0 0" >> /tgt_root/etc/fstab | ||
170 | echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab | ||
171 | # We dont want udev to mount our root device while we're booting... | ||
172 | if [ -d /tgt_root/etc/udev/ ] ; then | ||
173 | echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist | ||
174 | fi | ||
175 | fi | ||
176 | umount /tgt_root | ||
177 | umount /src_root | ||
178 | |||
179 | # Handling of the target boot partition | ||
180 | mount $bootfs /boot | ||
181 | echo "Preparing boot partition..." | ||
182 | if [ -f /etc/grub.d/00_header ] ; then | ||
183 | echo "Preparing custom grub2 menu..." | ||
184 | GRUBCFG="/boot/grub/grub.cfg" | ||
185 | mkdir -p $(dirname $GRUBCFG) | ||
186 | cat >$GRUBCFG <<_EOF | ||
187 | menuentry "Linux" { | ||
188 | set root=(hd0,1) | ||
189 | linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet | ||
190 | } | ||
191 | _EOF | ||
192 | chmod 0444 $GRUBCFG | ||
193 | fi | ||
194 | grub-install /dev/${device} | ||
195 | echo "(hd0) /dev/${device}" > /boot/grub/device.map | ||
196 | |||
197 | # If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst | ||
198 | if [ ! -f /boot/grub/grub.cfg ] ; then | ||
199 | echo "Preparing custom grub menu..." | ||
200 | echo "default 0" > /boot/grub/menu.lst | ||
201 | echo "timeout 30" >> /boot/grub/menu.lst | ||
202 | echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst | ||
203 | echo "root (hd0,0)" >> /boot/grub/menu.lst | ||
204 | echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst | ||
205 | fi | ||
206 | |||
207 | cp /run/media/$1/vmlinuz /boot/ | ||
208 | |||
209 | umount /boot | ||
210 | |||
211 | sync | ||
212 | |||
213 | echo "Remove your installation media, and press ENTER" | ||
214 | |||
215 | read enter | ||
216 | |||
217 | echo "Rebooting..." | ||
218 | reboot -f | ||