summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initrdscripts/files/init-install.sh
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/initrdscripts/files/init-install.sh')
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install.sh218
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
8PATH=/sbin:/bin:/usr/sbin:/usr/bin
9
10# We need 20 Mb for the boot partition
11boot_size=20
12
13# 5% for the swap
14swap_ratio=5
15
16# Get a list of hard drives
17hdnamelist=""
18live_dev_name=${1%%/*}
19live_dev_name=${live_dev_name%%[0-9]*}
20
21echo "Searching for hard drives ..."
22
23for 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
42done
43
44TARGET_DEVICE_NAME=""
45for 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
75done
76
77if [ -n "$TARGET_DEVICE_NAME" ]; then
78 echo "Installing image on /dev/$TARGET_DEVICE_NAME ..."
79else
80 echo "No hard drive selected. Installation aborted."
81 exit 1
82fi
83
84device=$TARGET_DEVICE_NAME
85
86#
87# The udev automounter can cause pain here, kill it
88#
89rm -f /etc/udev/rules.d/automount.rules
90rm -f /etc/udev/scripts/mount*
91
92#
93# Unmount anything the automounter had mounted
94#
95umount /dev/${device}* 2> /dev/null || /bin/true
96
97if [ ! -b /dev/loop0 ] ; then
98 mknod /dev/loop0 b 7 0
99fi
100
101mkdir -p /tmp
102if [ ! -L /etc/mtab ]; then
103 cat /proc/mounts > /etc/mtab
104fi
105
106disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
107
108swap_size=$((disk_size*swap_ratio/100))
109rootfs_size=$((disk_size-boot_size-swap_size))
110
111rootfs_start=$((boot_size))
112rootfs_end=$((rootfs_start+rootfs_size))
113swap_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)
118rootwait=""
119part_prefix=""
120if [ ! "${device#mmcblk}" = "${device}" ]; then
121 part_prefix="p"
122 rootwait="rootwait"
123fi
124bootfs=/dev/${device}${part_prefix}1
125rootfs=/dev/${device}${part_prefix}2
126swap=/dev/${device}${part_prefix}3
127
128echo "*****************"
129echo "Boot partition size: $boot_size MB ($bootfs)"
130echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
131echo "Swap partition size: $swap_size MB ($swap)"
132echo "*****************"
133echo "Deleting partition table on /dev/${device} ..."
134dd if=/dev/zero of=/dev/${device} bs=512 count=2
135
136echo "Creating new partition table on /dev/${device} ..."
137parted /dev/${device} mklabel msdos
138
139echo "Creating boot partition on $bootfs"
140parted /dev/${device} mkpart primary 0% $boot_size
141
142echo "Creating rootfs partition on $rootfs"
143parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
144
145echo "Creating swap partition on $swap"
146parted /dev/${device} mkpart primary $swap_start 100%
147
148parted /dev/${device} print
149
150echo "Formatting $bootfs to ext3..."
151mkfs.ext3 $bootfs
152
153echo "Formatting $rootfs to ext3..."
154mkfs.ext3 $rootfs
155
156echo "Formatting swap partition...($swap)"
157mkswap $swap
158
159mkdir /tgt_root
160mkdir /src_root
161mkdir -p /boot
162
163# Handling of the target root partition
164mount $rootfs /tgt_root
165mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
166echo "Copying rootfs files..."
167cp -a /src_root/* /tgt_root
168if [ -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
175fi
176umount /tgt_root
177umount /src_root
178
179# Handling of the target boot partition
180mount $bootfs /boot
181echo "Preparing boot partition..."
182if [ -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
187menuentry "Linux" {
188 set root=(hd0,1)
189 linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
190}
191_EOF
192 chmod 0444 $GRUBCFG
193fi
194grub-install /dev/${device}
195echo "(hd0) /dev/${device}" > /boot/grub/device.map
196
197# If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst
198if [ ! -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
205fi
206
207cp /run/media/$1/vmlinuz /boot/
208
209umount /boot
210
211sync
212
213echo "Remove your installation media, and press ENTER"
214
215read enter
216
217echo "Rebooting..."
218reboot -f