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