diff options
Diffstat (limited to 'meta/recipes-core/initrdscripts/files')
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init-boot.sh | 10 | ||||
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init-install-efi.sh | 178 | ||||
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init-install.sh | 208 | ||||
-rw-r--r-- | meta/recipes-core/initrdscripts/files/init-live.sh | 218 |
4 files changed, 614 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 | |||
3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
4 | |||
5 | mkdir /proc | ||
6 | mkdir /sys | ||
7 | mount -t proc proc /proc | ||
8 | mount -t sysfs sysfs /sys | ||
9 | |||
10 | exec sh | ||
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..9846637316 --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-install-efi.sh | |||
@@ -0,0 +1,178 @@ | |||
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 | |||
9 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
10 | |||
11 | # We need 20 Mb for the boot partition | ||
12 | boot_size=20 | ||
13 | |||
14 | # 5% for swap | ||
15 | swap_ratio=5 | ||
16 | |||
17 | found="no" | ||
18 | |||
19 | echo "Searching for a hard drive..." | ||
20 | for device in 'hda' 'hdb' 'sda' 'sdb' 'mmcblk0' 'mmcblk1' | ||
21 | do | ||
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 | |||
50 | done | ||
51 | |||
52 | if [ "$found" = "no" ]; then | ||
53 | exit 1 | ||
54 | fi | ||
55 | |||
56 | echo "Installing image on /dev/${device}" | ||
57 | |||
58 | # | ||
59 | # The udev automounter can cause pain here, kill it | ||
60 | # | ||
61 | rm -f /etc/udev/rules.d/automount.rules | ||
62 | rm -f /etc/udev/scripts/mount* | ||
63 | |||
64 | # | ||
65 | # Unmount anything the automounter had mounted | ||
66 | # | ||
67 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
68 | |||
69 | mkdir -p /tmp | ||
70 | cat /proc/mounts > /etc/mtab | ||
71 | |||
72 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
73 | |||
74 | swap_size=$((disk_size*swap_ratio/100)) | ||
75 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
76 | |||
77 | rootfs_start=$((boot_size)) | ||
78 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
79 | swap_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) | ||
84 | rootwait="" | ||
85 | part_prefix="" | ||
86 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
87 | part_prefix="p" | ||
88 | rootwait="rootwait" | ||
89 | fi | ||
90 | bootfs=/dev/${device}${part_prefix}1 | ||
91 | rootfs=/dev/${device}${part_prefix}2 | ||
92 | swap=/dev/${device}${part_prefix}3 | ||
93 | |||
94 | echo "*****************" | ||
95 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
96 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
97 | echo "Swap partition size: $swap_size MB ($swap)" | ||
98 | echo "*****************" | ||
99 | echo "Deleting partition table on /dev/${device} ..." | ||
100 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
101 | |||
102 | echo "Creating new partition table on /dev/${device} ..." | ||
103 | parted /dev/${device} mklabel gpt | ||
104 | |||
105 | echo "Creating boot partition on $bootfs" | ||
106 | parted /dev/${device} mkpart primary 0% $boot_size | ||
107 | |||
108 | echo "Creating rootfs partition on $rootfs" | ||
109 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
110 | |||
111 | echo "Creating swap partition on $swap" | ||
112 | parted /dev/${device} mkpart primary $swap_start 100% | ||
113 | |||
114 | parted /dev/${device} print | ||
115 | |||
116 | echo "Formatting $bootfs to vfat..." | ||
117 | mkfs.vfat $bootfs | ||
118 | |||
119 | echo "Formatting $rootfs to ext3..." | ||
120 | mkfs.ext3 $rootfs | ||
121 | |||
122 | echo "Formatting swap partition...($swap)" | ||
123 | mkswap $swap | ||
124 | |||
125 | mkdir /ssd | ||
126 | mkdir /rootmnt | ||
127 | mkdir /bootmnt | ||
128 | |||
129 | mount $rootfs /ssd | ||
130 | mount -o rw,loop,noatime,nodiratime /media/$1/$2 /rootmnt | ||
131 | |||
132 | echo "Copying rootfs files..." | ||
133 | cp -a /rootmnt/* /ssd | ||
134 | |||
135 | if [ -d /ssd/etc/ ] ; then | ||
136 | echo "$swap swap swap defaults 0 0" >> /ssd/etc/fstab | ||
137 | |||
138 | # We dont want udev to mount our root device while we're booting... | ||
139 | if [ -d /ssd/etc/udev/ ] ; then | ||
140 | echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist | ||
141 | fi | ||
142 | fi | ||
143 | |||
144 | umount /ssd | ||
145 | umount /rootmnt | ||
146 | |||
147 | echo "Preparing boot partition..." | ||
148 | mount $bootfs /ssd | ||
149 | |||
150 | EFIDIR="/ssd/EFI/BOOT" | ||
151 | mkdir -p $EFIDIR | ||
152 | GRUBCFG="$EFIDIR/grub.cfg" | ||
153 | |||
154 | cp /media/$1/vmlinuz /ssd | ||
155 | # Copy the efi loader and config (booti*.efi and grub.cfg) | ||
156 | cp /media/$1/EFI/BOOT/* $EFIDIR | ||
157 | |||
158 | # Update grub config for the installed image | ||
159 | # Delete the install entry | ||
160 | sed -i "/menuentry 'install'/,/^}/d" $GRUBCFG | ||
161 | # Delete the initrd lines | ||
162 | sed -i "/initrd /d" $GRUBCFG | ||
163 | # Delete any LABEL= strings | ||
164 | sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG | ||
165 | # Delete any root= strings | ||
166 | sed -i "s/ root=[^ ]*/ /" $GRUBCFG | ||
167 | # Add the root= and other standard boot options | ||
168 | sed -i "s@linux /vmlinuz *@linux /vmlinuz root=$rootfs rw $rootwait quiet @" $GRUBCFG | ||
169 | |||
170 | umount /ssd | ||
171 | sync | ||
172 | |||
173 | echo "Remove your installation media, and press ENTER" | ||
174 | |||
175 | read enter | ||
176 | |||
177 | echo "Rebooting..." | ||
178 | reboot -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 | |||
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 | |||
20 | echo "Searching for hard drives ..." | ||
21 | |||
22 | for 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 | ||
38 | done | ||
39 | |||
40 | TARGET_DEVICE_NAME="" | ||
41 | for 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 | ||
66 | done | ||
67 | |||
68 | if [ -n "$TARGET_DEVICE_NAME" ]; then | ||
69 | echo "Installing image on /dev/$TARGET_DEVICE_NAME ..." | ||
70 | else | ||
71 | echo "No hard drive selected. Installation aborted." | ||
72 | exit 1 | ||
73 | fi | ||
74 | |||
75 | device=$TARGET_DEVICE_NAME | ||
76 | |||
77 | # | ||
78 | # The udev automounter can cause pain here, kill it | ||
79 | # | ||
80 | rm -f /etc/udev/rules.d/automount.rules | ||
81 | rm -f /etc/udev/scripts/mount* | ||
82 | |||
83 | # | ||
84 | # Unmount anything the automounter had mounted | ||
85 | # | ||
86 | umount /dev/${device}* 2> /dev/null || /bin/true | ||
87 | |||
88 | if [ ! -b /dev/loop0 ] ; then | ||
89 | mknod /dev/loop0 b 7 0 | ||
90 | fi | ||
91 | |||
92 | mkdir -p /tmp | ||
93 | cat /proc/mounts > /etc/mtab | ||
94 | |||
95 | disk_size=$(parted /dev/${device} unit mb print | grep Disk | cut -d" " -f 3 | sed -e "s/MB//") | ||
96 | |||
97 | swap_size=$((disk_size*swap_ratio/100)) | ||
98 | rootfs_size=$((disk_size-boot_size-swap_size)) | ||
99 | |||
100 | rootfs_start=$((boot_size)) | ||
101 | rootfs_end=$((rootfs_start+rootfs_size)) | ||
102 | swap_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) | ||
107 | rootwait="" | ||
108 | part_prefix="" | ||
109 | if [ ! "${device#mmcblk}" = "${device}" ]; then | ||
110 | part_prefix="p" | ||
111 | rootwait="rootwait" | ||
112 | fi | ||
113 | bootfs=/dev/${device}${part_prefix}1 | ||
114 | rootfs=/dev/${device}${part_prefix}2 | ||
115 | swap=/dev/${device}${part_prefix}3 | ||
116 | |||
117 | echo "*****************" | ||
118 | echo "Boot partition size: $boot_size MB ($bootfs)" | ||
119 | echo "Rootfs partition size: $rootfs_size MB ($rootfs)" | ||
120 | echo "Swap partition size: $swap_size MB ($swap)" | ||
121 | echo "*****************" | ||
122 | echo "Deleting partition table on /dev/${device} ..." | ||
123 | dd if=/dev/zero of=/dev/${device} bs=512 count=2 | ||
124 | |||
125 | echo "Creating new partition table on /dev/${device} ..." | ||
126 | parted /dev/${device} mklabel msdos | ||
127 | |||
128 | echo "Creating boot partition on $bootfs" | ||
129 | parted /dev/${device} mkpart primary 0% $boot_size | ||
130 | |||
131 | echo "Creating rootfs partition on $rootfs" | ||
132 | parted /dev/${device} mkpart primary $rootfs_start $rootfs_end | ||
133 | |||
134 | echo "Creating swap partition on $swap" | ||
135 | parted /dev/${device} mkpart primary $swap_start 100% | ||
136 | |||
137 | parted /dev/${device} print | ||
138 | |||
139 | echo "Formatting $bootfs to ext3..." | ||
140 | mkfs.ext3 $bootfs | ||
141 | |||
142 | echo "Formatting $rootfs to ext3..." | ||
143 | mkfs.ext3 $rootfs | ||
144 | |||
145 | echo "Formatting swap partition...($swap)" | ||
146 | mkswap $swap | ||
147 | |||
148 | mkdir /tgt_root | ||
149 | mkdir /src_root | ||
150 | mkdir -p /boot | ||
151 | |||
152 | # Handling of the target root partition | ||
153 | mount $rootfs /tgt_root | ||
154 | mount -o rw,loop,noatime,nodiratime /media/$1/$2 /src_root | ||
155 | echo "Copying rootfs files..." | ||
156 | cp -a /src_root/* /tgt_root | ||
157 | if [ -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 | ||
164 | fi | ||
165 | umount /tgt_root | ||
166 | umount /src_root | ||
167 | |||
168 | # Handling of the target boot partition | ||
169 | mount $bootfs /boot | ||
170 | echo "Preparing boot partition..." | ||
171 | if [ -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 | ||
183 | fi | ||
184 | grub-install /dev/${device} | ||
185 | echo "(hd0) /dev/${device}" > /boot/grub/device.map | ||
186 | |||
187 | # If grub.cfg doesn't exist, assume GRUB 0.97 and create a menu.lst | ||
188 | if [ ! -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 | ||
195 | fi | ||
196 | |||
197 | cp /media/$1/vmlinuz /boot/ | ||
198 | |||
199 | umount /boot | ||
200 | |||
201 | sync | ||
202 | |||
203 | echo "Remove your installation media, and press ENTER" | ||
204 | |||
205 | read enter | ||
206 | |||
207 | echo "Rebooting..." | ||
208 | reboot -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..3f5fde83bf --- /dev/null +++ b/meta/recipes-core/initrdscripts/files/init-live.sh | |||
@@ -0,0 +1,218 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | ||
4 | |||
5 | ROOT_MOUNT="/rootfs/" | ||
6 | ROOT_IMAGE="rootfs.img" | ||
7 | MOUNT="/bin/mount" | ||
8 | UMOUNT="/bin/umount" | ||
9 | ISOLINUX="" | ||
10 | |||
11 | # Copied from initramfs-framework. The core of this script probably should be | ||
12 | # turned into initramfs-framework modules to reduce duplication. | ||
13 | udev_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 | |||
28 | early_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 | |||
45 | read_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 | rootfstype=*) | ||
53 | modprobe $optarg 2> /dev/null ;; | ||
54 | LABEL=*) | ||
55 | label=$optarg ;; | ||
56 | video=*) | ||
57 | video_mode=$arg ;; | ||
58 | vga=*) | ||
59 | vga_mode=$arg ;; | ||
60 | console=*) | ||
61 | if [ -z "${console_params}" ]; then | ||
62 | console_params=$arg | ||
63 | else | ||
64 | console_params="$console_params $arg" | ||
65 | fi ;; | ||
66 | debugshell*) | ||
67 | if [ -z "$optarg" ]; then | ||
68 | shelltimeout=30 | ||
69 | else | ||
70 | shelltimeout=$optarg | ||
71 | fi | ||
72 | esac | ||
73 | done | ||
74 | } | ||
75 | |||
76 | boot_live_root() { | ||
77 | # Watches the udev event queue, and exits if all current events are handled | ||
78 | udevadm settle --timeout=3 --quiet | ||
79 | killall "${_UDEV_DAEMON##*/}" 2>/dev/null | ||
80 | |||
81 | # Move the mount points of some filesystems over to | ||
82 | # the corresponding directories under the real root filesystem. | ||
83 | for dir in `awk '/\/dev.* \/media/{print $2}' /proc/mounts`; do | ||
84 | mkdir -p ${ROOT_MOUNT}/$dir | ||
85 | mount -n --move $dir ${ROOT_MOUNT}/$dir | ||
86 | done | ||
87 | mount -n --move /proc ${ROOT_MOUNT}/proc | ||
88 | mount -n --move /sys ${ROOT_MOUNT}/sys | ||
89 | mount -n --move /dev ${ROOT_MOUNT}/dev | ||
90 | |||
91 | cd $ROOT_MOUNT | ||
92 | exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init | ||
93 | } | ||
94 | |||
95 | fatal() { | ||
96 | echo $1 >$CONSOLE | ||
97 | echo >$CONSOLE | ||
98 | exec sh | ||
99 | } | ||
100 | |||
101 | early_setup | ||
102 | |||
103 | [ -z "$CONSOLE" ] && CONSOLE="/dev/console" | ||
104 | |||
105 | read_args | ||
106 | |||
107 | echo "Waiting for removable media..." | ||
108 | C=0 | ||
109 | while true | ||
110 | do | ||
111 | for i in `ls /media 2>/dev/null`; do | ||
112 | if [ -f /media/$i/$ROOT_IMAGE ] ; then | ||
113 | found="yes" | ||
114 | break | ||
115 | elif [ -f /media/$i/isolinux/$ROOT_IMAGE ]; then | ||
116 | found="yes" | ||
117 | ISOLINUX="isolinux" | ||
118 | break | ||
119 | fi | ||
120 | done | ||
121 | if [ "$found" = "yes" ]; then | ||
122 | break; | ||
123 | fi | ||
124 | # don't wait for more than $shelltimeout seconds, if it's set | ||
125 | if [ -n "$shelltimeout" ]; then | ||
126 | echo -n " " $(( $shelltimeout - $C )) | ||
127 | if [ $C -ge $shelltimeout ]; then | ||
128 | echo "..." | ||
129 | echo "Mounted filesystems" | ||
130 | mount | grep media | ||
131 | echo "Available block devices" | ||
132 | ls /dev/sd* | ||
133 | fatal "Cannot find rootfs.img file in /media/* , dropping to a shell " | ||
134 | fi | ||
135 | C=$(( C + 1 )) | ||
136 | fi | ||
137 | sleep 1 | ||
138 | done | ||
139 | |||
140 | # Try to mount the root image read-write and then boot it up. | ||
141 | # This function distinguishes between a read-only image and a read-write image. | ||
142 | # In the former case (typically an iso), it tries to make a union mount if possible. | ||
143 | # In the latter case, the root image could be mounted and then directly booted up. | ||
144 | mount_and_boot() { | ||
145 | mkdir $ROOT_MOUNT | ||
146 | mknod /dev/loop0 b 7 0 2>/dev/null | ||
147 | |||
148 | if ! mount -o rw,loop,noatime,nodiratime /media/$i/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then | ||
149 | fatal "Could not mount rootfs image" | ||
150 | fi | ||
151 | |||
152 | if touch $ROOT_MOUNT/bin 2>/dev/null; then | ||
153 | # The root image is read-write, directly boot it up. | ||
154 | boot_live_root | ||
155 | fi | ||
156 | |||
157 | # determine which unification filesystem to use | ||
158 | union_fs_type="" | ||
159 | if grep -q -w "overlayfs" /proc/filesystems; then | ||
160 | union_fs_type="overlayfs" | ||
161 | elif grep -q -w "aufs" /proc/filesystems; then | ||
162 | union_fs_type="aufs" | ||
163 | else | ||
164 | union_fs_type="" | ||
165 | fi | ||
166 | |||
167 | # make a union mount if possible | ||
168 | case $union_fs_type in | ||
169 | "overlayfs") | ||
170 | mkdir -p /rootfs.ro /rootfs.rw | ||
171 | if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then | ||
172 | rm -rf /rootfs.ro /rootfs.rw | ||
173 | fatal "Could not move rootfs mount point" | ||
174 | else | ||
175 | mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw | ||
176 | mount -t overlayfs -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw" overlayfs $ROOT_MOUNT | ||
177 | mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw | ||
178 | mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro | ||
179 | mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw | ||
180 | fi | ||
181 | ;; | ||
182 | "aufs") | ||
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 aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $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 | "") | ||
196 | mount -t tmpfs -o rw,noatime,mode=755 tmpfs $ROOT_MOUNT/media | ||
197 | ;; | ||
198 | esac | ||
199 | |||
200 | # boot the image | ||
201 | boot_live_root | ||
202 | } | ||
203 | |||
204 | case $label in | ||
205 | boot) | ||
206 | mount_and_boot | ||
207 | ;; | ||
208 | install|install-efi) | ||
209 | if [ -f /media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then | ||
210 | ./$label.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params | ||
211 | else | ||
212 | fatal "Could not find $label script" | ||
213 | fi | ||
214 | |||
215 | # If we're getting here, we failed... | ||
216 | fatal "Installation image failed" | ||
217 | ;; | ||
218 | esac | ||