summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/initrdscripts/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/initrdscripts/files')
-rw-r--r--meta/recipes-core/initrdscripts/files/init-boot.sh10
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh199
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install-efi.sh230
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install-testfs.sh220
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install.sh218
-rw-r--r--meta/recipes-core/initrdscripts/files/init-live.sh235
6 files changed, 1112 insertions, 0 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init-boot.sh b/meta/recipes-core/initrdscripts/files/init-boot.sh
new file mode 100644
index 0000000000..e82eba025d
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-boot.sh
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3PATH=/sbin:/bin:/usr/sbin:/usr/bin
4
5mkdir /proc
6mkdir /sys
7mount -t proc proc /proc
8mount -t sysfs sysfs /sys
9
10exec sh
diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh
new file mode 100644
index 0000000000..7a0b4d4406
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh
@@ -0,0 +1,199 @@
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 200 Mb for the boot partition
12boot_size=200
13
14# 50% for the second rootfs
15testfs_ratio=50
16
17found="no"
18
19echo "Searching for a hard drive..."
20for device in 'hda' 'hdb' 'sda' 'sdb' 'mmcblk0' 'mmcblk1'
21do
22 if [ -e /sys/block/${device}/removable ]; then
23 if [ "$(cat /sys/block/${device}/removable)" = "0" ]; then
24 found="yes"
25
26 while true; do
27 # Try sleeping here to avoid getting kernel messages
28 # obscuring/confusing user
29 sleep 5
30 echo "Found drive at /dev/${device}. Do you want to install this image there ? [y/n]"
31 read answer
32 if [ "$answer" = "y" ] ; then
33 break
34 fi
35
36 if [ "$answer" = "n" ] ; then
37 found=no
38 break
39 fi
40
41 echo "Please answer y or n"
42 done
43 fi
44 fi
45
46 if [ "$found" = "yes" ]; then
47 break;
48 fi
49
50done
51
52if [ "$found" = "no" ]; then
53 exit 1
54fi
55
56echo "Installing image on /dev/${device}"
57
58#
59# The udev automounter can cause pain here, kill it
60#
61rm -f /etc/udev/rules.d/automount.rules
62rm -f /etc/udev/scripts/mount*
63
64#
65# Unmount anything the automounter had mounted
66#
67umount /dev/${device}* 2> /dev/null || /bin/true
68
69mkdir -p /tmp
70cat /proc/mounts > /etc/mtab
71
72disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
73
74testfs_size=$((disk_size*testfs_ratio/100))
75rootfs_size=$((disk_size-boot_size-testfs_size))
76
77rootfs_start=$((boot_size))
78rootfs_end=$((rootfs_start+rootfs_size))
79testfs_start=$((rootfs_end))
80
81# MMC devices are special in a couple of ways
82# 1) they use a partition prefix character 'p'
83# 2) they are detected asynchronously (need rootwait)
84rootwait=""
85part_prefix=""
86if [ ! "${device#mmcblk}" = "${device}" ]; then
87 part_prefix="p"
88 rootwait="rootwait"
89fi
90bootfs=/dev/${device}${part_prefix}1
91rootfs=/dev/${device}${part_prefix}2
92testfs=/dev/${device}${part_prefix}3
93
94echo "*****************"
95echo "Boot partition size: $boot_size MB ($bootfs)"
96echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
97echo "Testfs partition size: $testfs_size MB ($testfs)"
98echo "*****************"
99echo "Deleting partition table on /dev/${device} ..."
100dd if=/dev/zero of=/dev/${device} bs=512 count=2
101
102echo "Creating new partition table on /dev/${device} ..."
103parted /dev/${device} mklabel gpt
104
105echo "Creating boot partition on $bootfs"
106parted /dev/${device} mkpart primary 0% $boot_size
107parted /dev/${device} set 1 boot on
108
109echo "Creating rootfs partition on $rootfs"
110parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
111
112echo "Creating testfs partition on $testfs"
113parted /dev/${device} mkpart primary $testfs_start 100%
114
115parted /dev/${device} print
116
117echo "Formatting $bootfs to vfat..."
118mkfs.vfat -n "boot" $bootfs
119
120echo "Formatting $rootfs to ext3..."
121mkfs.ext3 -L "platform" $rootfs
122
123echo "Formatting $testfs to ext3..."
124mkfs.ext3 -L "testrootfs" $testfs
125
126mkdir /ssd
127mkdir /rootmnt
128mkdir /bootmnt
129
130mount $rootfs /ssd
131mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /rootmnt
132
133echo "Copying rootfs files..."
134cp -a /rootmnt/* /ssd
135
136touch /ssd/etc/masterimage
137
138if [ -d /ssd/etc/ ] ; then
139 # We dont want udev to mount our root device while we're booting...
140 if [ -d /ssd/etc/udev/ ] ; then
141 echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist
142 fi
143fi
144
145umount /ssd
146umount /rootmnt
147
148echo "Preparing boot partition..."
149mount $bootfs /ssd
150
151EFIDIR="/ssd/EFI/BOOT"
152mkdir -p $EFIDIR
153cp /run/media/$1/vmlinuz /ssd
154# Copy the efi loader
155cp /run/media/$1/EFI/BOOT/*.efi $EFIDIR
156
157if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then
158 GRUBCFG="$EFIDIR/grub.cfg"
159 cp /run/media/$1/EFI/BOOT/grub.cfg $GRUBCFG
160 # Update grub config for the installed image
161 # Delete the install entry
162 sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG
163 # Delete the initrd lines
164 sed -i "/initrd /d" $GRUBCFG
165 # Delete any LABEL= strings
166 sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG
167 # Delete any root= strings
168 sed -i "s/ root=[^ ]*/ /" $GRUBCFG
169 # Add the root= and other standard boot options
170 sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG
171fi
172
173if [ -d /run/media/$1/loader ]; then
174 GUMMIBOOT_CFGS="/ssd/loader/entries/*.conf"
175 # copy config files for gummiboot
176 cp -dr /run/media/$1/loader /ssd
177 # delete the install entry
178 rm -f /ssd/loader/entries/install.conf
179 # delete the initrd lines
180 sed -i "/initrd /d" $GUMMIBOOT_CFGS
181 # delete any LABEL= strings
182 sed -i "s/ LABEL=[^ ]*/ /" $GUMMIBOOT_CFGS
183 # delete any root= strings
184 sed -i "s/ root=[^ ]*/ /" $GUMMIBOOT_CFGS
185 # add the root= and other standard boot options
186 sed -i "s@options *@options root=$rootfs rw $rootwait quiet @" $GUMMIBOOT_CFGS
187 # Add the test label
188 echo -ne "title test\nlinux /test-kernel\noptions root=$testfs rw $rootwait quiet\n" > /ssd/loader/entries/test.conf
189fi
190
191umount /ssd
192sync
193
194echo "Remove your installation media, and press ENTER"
195
196read enter
197
198echo "Rebooting..."
199reboot -f
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
diff --git a/meta/recipes-core/initrdscripts/files/init-install-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh
new file mode 100644
index 0000000000..ac62160528
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh
@@ -0,0 +1,220 @@
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=200
12
13# 50% for the the test partition
14testfs_ratio=50
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
93if [ ! -L /etc/mtab ]; then
94 cat /proc/mounts > /etc/mtab
95fi
96
97disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//")
98
99testfs_size=$((disk_size*testfs_ratio/100))
100rootfs_size=$((disk_size-boot_size-testfs_size))
101
102rootfs_start=$((boot_size))
103rootfs_end=$((rootfs_start+rootfs_size))
104testfs_start=$((rootfs_end))
105
106# MMC devices are special in a couple of ways
107# 1) they use a partition prefix character 'p'
108# 2) they are detected asynchronously (need rootwait)
109rootwait=""
110part_prefix=""
111if [ ! "${device#mmcblk}" = "${device}" ]; then
112 part_prefix="p"
113 rootwait="rootwait"
114fi
115bootfs=/dev/${device}${part_prefix}1
116rootfs=/dev/${device}${part_prefix}2
117testfs=/dev/${device}${part_prefix}3
118
119echo "*****************"
120echo "Boot partition size: $boot_size MB ($bootfs)"
121echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
122echo "Testfs partition size: $testfs_size MB ($testfs)"
123echo "*****************"
124echo "Deleting partition table on /dev/${device} ..."
125dd if=/dev/zero of=/dev/${device} bs=512 count=2
126
127echo "Creating new partition table on /dev/${device} ..."
128parted /dev/${device} mklabel msdos
129
130echo "Creating boot partition on $bootfs"
131parted /dev/${device} mkpart primary 0% $boot_size
132
133echo "Creating rootfs partition on $rootfs"
134parted /dev/${device} mkpart primary $rootfs_start $rootfs_end
135
136echo "Creating testfs partition on $testfs"
137parted /dev/${device} mkpart primary $testfs_start 100%
138
139parted /dev/${device} print
140
141echo "Formatting $bootfs to ext3..."
142mkfs.ext3 -L "boot" $bootfs
143
144echo "Formatting $rootfs to ext3..."
145mkfs.ext3 -L "rootfs" $rootfs
146
147echo "Formatting $testfs to ext3..."
148mkfs.ext3 -L "testrootfs" $testfs
149
150mkdir /tgt_root
151mkdir /src_root
152mkdir -p /boot
153
154# Handling of the target root partition
155mount $rootfs /tgt_root
156mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root
157
158echo "Copying rootfs files..."
159cp -a /src_root/* /tgt_root
160
161touch /tgt_root/etc/masterimage
162
163if [ -d /tgt_root/etc/ ] ; then
164 echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab
165 # We dont want udev to mount our root device while we're booting...
166 if [ -d /tgt_root/etc/udev/ ] ; then
167 echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
168 fi
169fi
170umount /tgt_root
171umount /src_root
172
173# Handling of the target boot partition
174mount $bootfs /boot
175echo "Preparing boot partition..."
176if [ -f /etc/grub.d/00_header ] ; then
177 echo "Preparing custom grub2 menu..."
178 GRUBCFG="/boot/grub/grub.cfg"
179 mkdir -p $(dirname $GRUBCFG)
180 cat >$GRUBCFG <<_EOF
181serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1
182terminal_input --append serial
183terminal_output --append serial
184set timeout_style=hidden
185set timeout=5
186menuentry "Linux" {
187 set root=(hd0,1)
188 linux /vmlinuz root=$rootfs $rootwait rw $5 $3 $4 quiet
189}
190_EOF
191 # Add the test label
192 echo -ne "\nmenuentry 'test' --hotkey x {\nlinux /test-kernel root=$testfs rw $rootwait quiet\n}\n" >> $GRUBCFG
193
194 chmod 0444 $GRUBCFG
195fi
196grub-install /dev/${device}
197echo "(hd0) /dev/${device}" > /boot/grub/device.map
198
199# If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst
200if [ ! -f /boot/grub/grub.cfg ] ; then
201 echo "Preparing custom grub menu..."
202 echo "default 0" > /boot/grub/menu.lst
203 echo "timeout 30" >> /boot/grub/menu.lst
204 echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst
205 echo "root (hd0,0)" >> /boot/grub/menu.lst
206 echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst
207fi
208
209cp /run/media/$1/vmlinuz /boot/
210
211umount /boot
212
213sync
214
215echo "Remove your installation media, and press ENTER"
216
217read enter
218
219echo "Rebooting..."
220reboot -f
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
diff --git a/meta/recipes-core/initrdscripts/files/init-live.sh b/meta/recipes-core/initrdscripts/files/init-live.sh
new file mode 100644
index 0000000000..d852c5737f
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-live.sh
@@ -0,0 +1,235 @@
1#!/bin/sh
2
3PATH=/sbin:/bin:/usr/sbin:/usr/bin
4
5ROOT_MOUNT="/rootfs/"
6ROOT_IMAGE="rootfs.img"
7MOUNT="/bin/mount"
8UMOUNT="/bin/umount"
9ISOLINUX=""
10
11ROOT_DISK=""
12
13# Copied from initramfs-framework. The core of this script probably should be
14# turned into initramfs-framework modules to reduce duplication.
15udev_daemon() {
16 OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd"
17
18 for o in $OPTIONS; do
19 if [ -x "$o" ]; then
20 echo $o
21 return 0
22 fi
23 done
24
25 return 1
26}
27
28_UDEV_DAEMON=`udev_daemon`
29
30early_setup() {
31 mkdir -p /proc
32 mkdir -p /sys
33 mount -t proc proc /proc
34 mount -t sysfs sysfs /sys
35 mount -t devtmpfs none /dev
36
37 # support modular kernel
38 modprobe isofs 2> /dev/null
39
40 mkdir -p /run
41 mkdir -p /var/run
42
43 $_UDEV_DAEMON --daemon
44 udevadm trigger --action=add
45}
46
47read_args() {
48 [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline`
49 for arg in $CMDLINE; do
50 optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
51 case $arg in
52 root=*)
53 ROOT_DEVICE=$optarg ;;
54 rootimage=*)
55 ROOT_IMAGE=$optarg ;;
56 rootfstype=*)
57 modprobe $optarg 2> /dev/null ;;
58 LABEL=*)
59 label=$optarg ;;
60 video=*)
61 video_mode=$arg ;;
62 vga=*)
63 vga_mode=$arg ;;
64 console=*)
65 if [ -z "${console_params}" ]; then
66 console_params=$arg
67 else
68 console_params="$console_params $arg"
69 fi ;;
70 debugshell*)
71 if [ -z "$optarg" ]; then
72 shelltimeout=30
73 else
74 shelltimeout=$optarg
75 fi
76 esac
77 done
78}
79
80boot_live_root() {
81 # Watches the udev event queue, and exits if all current events are handled
82 udevadm settle --timeout=3 --quiet
83 killall "${_UDEV_DAEMON##*/}" 2>/dev/null
84
85 # Allow for identification of the real root even after boot
86 mkdir -p ${ROOT_MOUNT}/media/realroot
87 mount -n --move "/run/media/${ROOT_DISK}" ${ROOT_MOUNT}/media/realroot
88
89 # Move the mount points of some filesystems over to
90 # the corresponding directories under the real root filesystem.
91 for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
92 mkdir -p ${ROOT_MOUNT}/media/${dir##*/}
93 mount -n --move $dir ${ROOT_MOUNT}/media/${dir##*/}
94 done
95 mount -n --move /proc ${ROOT_MOUNT}/proc
96 mount -n --move /sys ${ROOT_MOUNT}/sys
97 mount -n --move /dev ${ROOT_MOUNT}/dev
98
99 cd $ROOT_MOUNT
100
101 # busybox switch_root supports -c option
102 exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init $CMDLINE ||
103 fatal "Couldn't switch_root, dropping to shell"
104}
105
106fatal() {
107 echo $1 >$CONSOLE
108 echo >$CONSOLE
109 exec sh
110}
111
112early_setup
113
114[ -z "$CONSOLE" ] && CONSOLE="/dev/console"
115
116read_args
117
118echo "Waiting for removable media..."
119C=0
120while true
121do
122 for i in `ls /run/media 2>/dev/null`; do
123 if [ -f /run/media/$i/$ROOT_IMAGE ] ; then
124 found="yes"
125 ROOT_DISK="$i"
126 break
127 elif [ -f /run/media/$i/isolinux/$ROOT_IMAGE ]; then
128 found="yes"
129 ISOLINUX="isolinux"
130 ROOT_DISK="$i"
131 break
132 fi
133 done
134 if [ "$found" = "yes" ]; then
135 break;
136 fi
137 # don't wait for more than $shelltimeout seconds, if it's set
138 if [ -n "$shelltimeout" ]; then
139 echo -n " " $(( $shelltimeout - $C ))
140 if [ $C -ge $shelltimeout ]; then
141 echo "..."
142 echo "Mounted filesystems"
143 mount | grep media
144 echo "Available block devices"
145 cat /proc/partitions
146 fatal "Cannot find $ROOT_IMAGE file in /run/media/* , dropping to a shell "
147 fi
148 C=$(( C + 1 ))
149 fi
150 sleep 1
151done
152
153# Try to mount the root image read-write and then boot it up.
154# This function distinguishes between a read-only image and a read-write image.
155# In the former case (typically an iso), it tries to make a union mount if possible.
156# In the latter case, the root image could be mounted and then directly booted up.
157mount_and_boot() {
158 mkdir $ROOT_MOUNT
159 mknod /dev/loop0 b 7 0 2>/dev/null
160
161 if ! mount -o rw,loop,noatime,nodiratime /run/media/$ROOT_DISK/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then
162 fatal "Could not mount rootfs image"
163 fi
164
165 if touch $ROOT_MOUNT/bin 2>/dev/null; then
166 # The root image is read-write, directly boot it up.
167 boot_live_root
168 fi
169
170 # determine which unification filesystem to use
171 union_fs_type=""
172 if grep -q -w "overlayfs" /proc/filesystems; then
173 union_fs_type="overlayfs"
174 elif grep -q -w "aufs" /proc/filesystems; then
175 union_fs_type="aufs"
176 else
177 union_fs_type=""
178 fi
179
180 # make a union mount if possible
181 case $union_fs_type in
182 "overlayfs")
183 mkdir -p /rootfs.ro /rootfs.rw
184 if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
185 rm -rf /rootfs.ro /rootfs.rw
186 fatal "Could not move rootfs mount point"
187 else
188 mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
189 mount -t overlayfs -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw" overlayfs $ROOT_MOUNT
190 mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
191 mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
192 mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
193 fi
194 ;;
195 "aufs")
196 mkdir -p /rootfs.ro /rootfs.rw
197 if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
198 rm -rf /rootfs.ro /rootfs.rw
199 fatal "Could not move rootfs mount point"
200 else
201 mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
202 mount -t aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $ROOT_MOUNT
203 mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
204 mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
205 mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
206 fi
207 ;;
208 "")
209 mount -t tmpfs -o rw,noatime,mode=755 tmpfs $ROOT_MOUNT/media
210 ;;
211 esac
212
213 # boot the image
214 boot_live_root
215}
216
217case $label in
218 boot)
219 mount_and_boot
220 ;;
221 install|install-efi)
222 if [ -f /run/media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then
223 ./$label.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params
224 else
225 fatal "Could not find $label script"
226 fi
227
228 # If we're getting here, we failed...
229 fatal "Installation image failed"
230 ;;
231 *)
232 # Not sure what boot label is provided. Try to boot to avoid locking up.
233 mount_and_boot
234 ;;
235esac