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.sh197
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install-testfs.sh211
-rw-r--r--meta/recipes-core/initrdscripts/files/init-install.sh208
-rw-r--r--meta/recipes-core/initrdscripts/files/init-live.sh223
6 files changed, 1048 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..2fea7610f9
--- /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 /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 /media/$1/vmlinuz /ssd
154# Copy the efi loader
155cp /media/$1/EFI/BOOT/*.efi $EFIDIR
156
157if [ -f /media/$1/EFI/BOOT/grub.cfg ]; then
158 GRUBCFG="$EFIDIR/grub.cfg"
159 cp /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 /media/$1/loader ]; then
174 GUMMIBOOT_CFGS="/ssd/loader/entries/*.conf"
175 # copy config files for gummiboot
176 cp -dr /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..ed3221b0a6
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-install-efi.sh
@@ -0,0 +1,197 @@
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
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
74swap_size=$((disk_size*swap_ratio/100))
75rootfs_size=$((disk_size-boot_size-swap_size))
76
77rootfs_start=$((boot_size))
78rootfs_end=$((rootfs_start+rootfs_size))
79swap_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
92swap=/dev/${device}${part_prefix}3
93
94echo "*****************"
95echo "Boot partition size: $boot_size MB ($bootfs)"
96echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
97echo "Swap partition size: $swap_size MB ($swap)"
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 swap partition on $swap"
113parted /dev/${device} mkpart primary $swap_start 100%
114
115parted /dev/${device} print
116
117echo "Formatting $bootfs to vfat..."
118mkfs.vfat $bootfs
119
120echo "Formatting $rootfs to ext3..."
121mkfs.ext3 $rootfs
122
123echo "Formatting swap partition...($swap)"
124mkswap $swap
125
126mkdir /ssd
127mkdir /rootmnt
128mkdir /bootmnt
129
130mount $rootfs /ssd
131mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt
132
133echo "Copying rootfs files..."
134cp -a /rootmnt/* /ssd
135
136if [ -d /ssd/etc/ ] ; then
137 echo "$swap swap swap defaults 0 0" >> /ssd/etc/fstab
138
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 /media/$1/vmlinuz /ssd
154# Copy the efi loader
155cp /media/$1/EFI/BOOT/*.efi $EFIDIR
156
157if [ -f /media/$1/EFI/BOOT/grub.cfg ]; then
158 GRUBCFG="$EFIDIR/grub.cfg"
159 cp /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 /media/$1/loader ]; then
174 GUMMIBOOT_CFGS="/ssd/loader/entries/*.conf"
175 # copy config files for gummiboot
176 cp -dr /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
187fi
188
189umount /ssd
190sync
191
192echo "Remove your installation media, and press ENTER"
193
194read enter
195
196echo "Rebooting..."
197reboot -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..d2f2420498
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh
@@ -0,0 +1,211 @@
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
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
97testfs_size=$((disk_size*testfs_ratio/100))
98rootfs_size=$((disk_size-boot_size-testfs_size))
99
100rootfs_start=$((boot_size))
101rootfs_end=$((rootfs_start+rootfs_size))
102testfs_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
115testfs=/dev/${device}${part_prefix}3
116
117echo "*****************"
118echo "Boot partition size: $boot_size MB ($bootfs)"
119echo "Rootfs partition size: $rootfs_size MB ($rootfs)"
120echo "Testfs partition size: $testfs_size MB ($testfs)"
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 testfs partition on $testfs"
135parted /dev/${device} mkpart primary $testfs_start 100%
136
137parted /dev/${device} print
138
139echo "Formatting $bootfs to ext3..."
140mkfs.ext3 -L "boot" $bootfs
141
142echo "Formatting $rootfs to ext3..."
143mkfs.ext3 -L "rootfs" $rootfs
144
145echo "Formatting $testfs to ext3..."
146mkfs.ext3 -L "testrootfs" $testfs
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 "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab
159 # We dont want udev to mount our root device while we're booting...
160 if [ -d /tgt_root/etc/udev/ ] ; then
161 echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist
162 fi
163fi
164umount /tgt_root
165umount /src_root
166
167# Handling of the target boot partition
168mount $bootfs /boot
169echo "Preparing boot partition..."
170if [ -f /etc/grub.d/40_custom ] ; then
171 echo "Preparing custom grub2 menu..."
172 GRUBCFG="/boot/grub/grub.cfg"
173 mkdir -p $(dirname $GRUBCFG)
174 cp /etc/grub.d/40_custom $GRUBCFG
175 sed -i "s@__ROOTFS__@$rootfs $rootwait@g" $GRUBCFG
176 sed -i "s/__VIDEO_MODE__/$3/g" $GRUBCFG
177 sed -i "s/__VGA_MODE__/$4/g" $GRUBCFG
178 sed -i "s/__CONSOLE__/$5/g" $GRUBCFG
179 sed -i "/#/d" $GRUBCFG
180 sed -i "/exec tail/d" $GRUBCFG
181
182 # Add the test label
183 echo -ne "\nmenuentry 'test' {\nlinux /test-kernel root=$testfs rw $rootwait quiet\n}\n" >> $GRUBCFG
184
185 chmod 0444 $GRUBCFG
186fi
187grub-install /dev/${device}
188echo "(hd0) /dev/${device}" > /boot/grub/device.map
189
190# If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst
191if [ ! -f /boot/grub/grub.cfg ] ; then
192 echo "Preparing custom grub menu..."
193 echo "default 0" > /boot/grub/menu.lst
194 echo "timeout 30" >> /boot/grub/menu.lst
195 echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst
196 echo "root (hd0,0)" >> /boot/grub/menu.lst
197 echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst
198fi
199
200cp /media/$1/vmlinuz /boot/
201
202umount /boot
203
204sync
205
206echo "Remove your installation media, and press ENTER"
207
208read enter
209
210echo "Rebooting..."
211reboot -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..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
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..9e53a25a51
--- /dev/null
+++ b/meta/recipes-core/initrdscripts/files/init-live.sh
@@ -0,0 +1,223 @@
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
11# Copied from initramfs-framework. The core of this script probably should be
12# turned into initramfs-framework modules to reduce duplication.
13udev_daemon() {
14 OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd"
15
16 for o in $OPTIONS; do
17 if [ -x "$o" ]; then
18 echo $o
19 return 0
20 fi
21 done
22
23 return 1
24}
25
26_UDEV_DAEMON=`udev_daemon`
27
28early_setup() {
29 mkdir -p /proc
30 mkdir -p /sys
31 mount -t proc proc /proc
32 mount -t sysfs sysfs /sys
33 mount -t devtmpfs none /dev
34
35 # support modular kernel
36 modprobe isofs 2> /dev/null
37
38 mkdir -p /run
39 mkdir -p /var/run
40
41 $_UDEV_DAEMON --daemon
42 udevadm trigger --action=add
43}
44
45read_args() {
46 [ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline`
47 for arg in $CMDLINE; do
48 optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
49 case $arg in
50 root=*)
51 ROOT_DEVICE=$optarg ;;
52 rootimage=*)
53 ROOT_IMAGE=$optarg ;;
54 rootfstype=*)
55 modprobe $optarg 2> /dev/null ;;
56 LABEL=*)
57 label=$optarg ;;
58 video=*)
59 video_mode=$arg ;;
60 vga=*)
61 vga_mode=$arg ;;
62 console=*)
63 if [ -z "${console_params}" ]; then
64 console_params=$arg
65 else
66 console_params="$console_params $arg"
67 fi ;;
68 debugshell*)
69 if [ -z "$optarg" ]; then
70 shelltimeout=30
71 else
72 shelltimeout=$optarg
73 fi
74 esac
75 done
76}
77
78boot_live_root() {
79 # Watches the udev event queue, and exits if all current events are handled
80 udevadm settle --timeout=3 --quiet
81 killall "${_UDEV_DAEMON##*/}" 2>/dev/null
82
83 # Move the mount points of some filesystems over to
84 # the corresponding directories under the real root filesystem.
85 for dir in `awk '/\/dev.* \/media/{print $2}' /proc/mounts`; do
86 mkdir -p ${ROOT_MOUNT}/$dir
87 mount -n --move $dir ${ROOT_MOUNT}/$dir
88 done
89 mount -n --move /proc ${ROOT_MOUNT}/proc
90 mount -n --move /sys ${ROOT_MOUNT}/sys
91 mount -n --move /dev ${ROOT_MOUNT}/dev
92
93 cd $ROOT_MOUNT
94
95 # busybox switch_root supports -c option
96 exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init $CMDLINE ||
97 fatal "Couldn't switch_root, dropping to shell"
98}
99
100fatal() {
101 echo $1 >$CONSOLE
102 echo >$CONSOLE
103 exec sh
104}
105
106early_setup
107
108[ -z "$CONSOLE" ] && CONSOLE="/dev/console"
109
110read_args
111
112echo "Waiting for removable media..."
113C=0
114while true
115do
116 for i in `ls /media 2>/dev/null`; do
117 if [ -f /media/$i/$ROOT_IMAGE ] ; then
118 found="yes"
119 break
120 elif [ -f /media/$i/isolinux/$ROOT_IMAGE ]; then
121 found="yes"
122 ISOLINUX="isolinux"
123 break
124 fi
125 done
126 if [ "$found" = "yes" ]; then
127 break;
128 fi
129 # don't wait for more than $shelltimeout seconds, if it's set
130 if [ -n "$shelltimeout" ]; then
131 echo -n " " $(( $shelltimeout - $C ))
132 if [ $C -ge $shelltimeout ]; then
133 echo "..."
134 echo "Mounted filesystems"
135 mount | grep media
136 echo "Available block devices"
137 ls /dev/sd*
138 fatal "Cannot find $ROOT_IMAGE file in /media/* , dropping to a shell "
139 fi
140 C=$(( C + 1 ))
141 fi
142 sleep 1
143done
144
145# Try to mount the root image read-write and then boot it up.
146# This function distinguishes between a read-only image and a read-write image.
147# In the former case (typically an iso), it tries to make a union mount if possible.
148# In the latter case, the root image could be mounted and then directly booted up.
149mount_and_boot() {
150 mkdir $ROOT_MOUNT
151 mknod /dev/loop0 b 7 0 2>/dev/null
152
153 if ! mount -o rw,loop,noatime,nodiratime /media/$i/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then
154 fatal "Could not mount rootfs image"
155 fi
156
157 if touch $ROOT_MOUNT/bin 2>/dev/null; then
158 # The root image is read-write, directly boot it up.
159 boot_live_root
160 fi
161
162 # determine which unification filesystem to use
163 union_fs_type=""
164 if grep -q -w "overlayfs" /proc/filesystems; then
165 union_fs_type="overlayfs"
166 elif grep -q -w "aufs" /proc/filesystems; then
167 union_fs_type="aufs"
168 else
169 union_fs_type=""
170 fi
171
172 # make a union mount if possible
173 case $union_fs_type in
174 "overlayfs")
175 mkdir -p /rootfs.ro /rootfs.rw
176 if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
177 rm -rf /rootfs.ro /rootfs.rw
178 fatal "Could not move rootfs mount point"
179 else
180 mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
181 mount -t overlayfs -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw" overlayfs $ROOT_MOUNT
182 mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
183 mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
184 mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
185 fi
186 ;;
187 "aufs")
188 mkdir -p /rootfs.ro /rootfs.rw
189 if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
190 rm -rf /rootfs.ro /rootfs.rw
191 fatal "Could not move rootfs mount point"
192 else
193 mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
194 mount -t aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $ROOT_MOUNT
195 mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
196 mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
197 mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
198 fi
199 ;;
200 "")
201 mount -t tmpfs -o rw,noatime,mode=755 tmpfs $ROOT_MOUNT/media
202 ;;
203 esac
204
205 # boot the image
206 boot_live_root
207}
208
209case $label in
210 boot)
211 mount_and_boot
212 ;;
213 install|install-efi)
214 if [ -f /media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then
215 ./$label.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params
216 else
217 fatal "Could not find $label script"
218 fi
219
220 # If we're getting here, we failed...
221 fatal "Installation image failed"
222 ;;
223esac