2008-09-10 21:21:23 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2011-09-15 22:41:37 +00:00
|
|
|
PATH=/sbin:/bin:/usr/sbin:/usr/bin
|
|
|
|
|
2008-09-10 21:21:23 +00:00
|
|
|
ROOT_MOUNT="/rootfs/"
|
2011-08-24 07:36:22 +00:00
|
|
|
ROOT_IMAGE="rootfs.img"
|
2008-09-10 21:21:23 +00:00
|
|
|
MOUNT="/bin/mount"
|
|
|
|
UMOUNT="/bin/umount"
|
2011-08-24 07:36:22 +00:00
|
|
|
ISOLINUX=""
|
2008-09-10 21:21:23 +00:00
|
|
|
|
2014-06-28 15:48:24 +00:00
|
|
|
ROOT_DISK=""
|
|
|
|
|
2013-01-17 16:29:39 +00:00
|
|
|
# Copied from initramfs-framework. The core of this script probably should be
|
|
|
|
# turned into initramfs-framework modules to reduce duplication.
|
|
|
|
udev_daemon() {
|
2013-09-16 14:19:33 +00:00
|
|
|
OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd"
|
2013-01-17 16:29:39 +00:00
|
|
|
|
|
|
|
for o in $OPTIONS; do
|
|
|
|
if [ -x "$o" ]; then
|
|
|
|
echo $o
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
_UDEV_DAEMON=`udev_daemon`
|
|
|
|
|
2008-09-10 21:21:23 +00:00
|
|
|
early_setup() {
|
2012-09-27 14:20:51 +00:00
|
|
|
mkdir -p /proc
|
|
|
|
mkdir -p /sys
|
2008-09-10 21:21:23 +00:00
|
|
|
mount -t proc proc /proc
|
2008-10-08 14:34:50 +00:00
|
|
|
mount -t sysfs sysfs /sys
|
2012-11-12 16:18:35 +00:00
|
|
|
mount -t devtmpfs none /dev
|
2011-10-11 19:18:50 +00:00
|
|
|
|
|
|
|
# support modular kernel
|
|
|
|
modprobe isofs 2> /dev/null
|
|
|
|
|
2012-09-27 14:20:51 +00:00
|
|
|
mkdir -p /run
|
2012-11-12 16:18:35 +00:00
|
|
|
mkdir -p /var/run
|
2013-01-17 16:29:39 +00:00
|
|
|
|
|
|
|
$_UDEV_DAEMON --daemon
|
2011-09-15 22:41:37 +00:00
|
|
|
udevadm trigger --action=add
|
2008-09-10 21:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
read_args() {
|
|
|
|
[ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline`
|
|
|
|
for arg in $CMDLINE; do
|
|
|
|
optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
|
|
|
|
case $arg in
|
|
|
|
root=*)
|
|
|
|
ROOT_DEVICE=$optarg ;;
|
2014-02-26 07:19:41 +00:00
|
|
|
rootimage=*)
|
|
|
|
ROOT_IMAGE=$optarg ;;
|
2008-09-10 21:21:23 +00:00
|
|
|
rootfstype=*)
|
2011-10-11 19:18:50 +00:00
|
|
|
modprobe $optarg 2> /dev/null ;;
|
|
|
|
LABEL=*)
|
|
|
|
label=$optarg ;;
|
|
|
|
video=*)
|
|
|
|
video_mode=$arg ;;
|
|
|
|
vga=*)
|
|
|
|
vga_mode=$arg ;;
|
2012-07-19 11:59:52 +00:00
|
|
|
console=*)
|
|
|
|
if [ -z "${console_params}" ]; then
|
|
|
|
console_params=$arg
|
|
|
|
else
|
|
|
|
console_params="$console_params $arg"
|
2012-12-18 12:38:27 +00:00
|
|
|
fi ;;
|
|
|
|
debugshell*)
|
|
|
|
if [ -z "$optarg" ]; then
|
|
|
|
shelltimeout=30
|
|
|
|
else
|
|
|
|
shelltimeout=$optarg
|
|
|
|
fi
|
2008-09-10 21:21:23 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
boot_live_root() {
|
2013-06-18 12:14:14 +00:00
|
|
|
# Watches the udev event queue, and exits if all current events are handled
|
|
|
|
udevadm settle --timeout=3 --quiet
|
|
|
|
killall "${_UDEV_DAEMON##*/}" 2>/dev/null
|
2011-10-11 19:18:50 +00:00
|
|
|
|
2014-06-28 15:48:24 +00:00
|
|
|
# Allow for identification of the real root even after boot
|
|
|
|
mkdir -p ${ROOT_MOUNT}/media/realroot
|
|
|
|
mount -n --move "/run/media/${ROOT_DISK}" ${ROOT_MOUNT}/media/realroot
|
|
|
|
|
2012-12-31 07:55:20 +00:00
|
|
|
# Move the mount points of some filesystems over to
|
|
|
|
# the corresponding directories under the real root filesystem.
|
2014-05-15 09:36:17 +00:00
|
|
|
for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
|
|
|
|
mkdir -p ${ROOT_MOUNT}/media/${dir##*/}
|
|
|
|
mount -n --move $dir ${ROOT_MOUNT}/media/${dir##*/}
|
init-live.sh: fix media automount failed after booting from usb-drive
1, This issue happens to BSP only.
After a BSP board is booted with Yocto linux from USB drive, "cat /proc/mounts" shows:
...
/dev/sda3 /media/sda3 ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 0 0
/dev/sda1 /media/sda1 ext3 rw,relatime,errors=continue,barrier=1,data=ordered 0 0
/dev/sda2 /media/sda2 ext3 rw,relatime,errors=continue,user_xattr,acl,barrier=1,data=ordered 0 0
...
but actually the directory /media/sda1 doesn't exist at all, "df" shows:
...
df: /media/sda3: No such file or directory
df: /media/sda1: No such file or directory
df: /media/sda2: No such file or directory
...
2, This is because the mount data comes from proc setup during early boot
before the change root, which then uses a different root filesystem, the
media is not in the new root filesystem.
3, During early boot before switch_root, use `mount --move' to move all
medias to the new root filesystem could also fix this issue.
[YOCTO #2064]
[YOCTO #3705]
(From OE-Core rev: 79bd773cc5e8b8e873cabeb2b9a91f460501dad7)
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2013-06-06 06:31:17 +00:00
|
|
|
done
|
2012-12-31 07:55:20 +00:00
|
|
|
mount -n --move /proc ${ROOT_MOUNT}/proc
|
|
|
|
mount -n --move /sys ${ROOT_MOUNT}/sys
|
|
|
|
mount -n --move /dev ${ROOT_MOUNT}/dev
|
2011-10-11 19:18:50 +00:00
|
|
|
|
2008-09-10 21:21:23 +00:00
|
|
|
cd $ROOT_MOUNT
|
2014-01-15 11:27:04 +00:00
|
|
|
|
|
|
|
# busybox switch_root supports -c option
|
|
|
|
exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init $CMDLINE ||
|
|
|
|
fatal "Couldn't switch_root, dropping to shell"
|
2008-09-10 21:21:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fatal() {
|
|
|
|
echo $1 >$CONSOLE
|
|
|
|
echo >$CONSOLE
|
|
|
|
exec sh
|
|
|
|
}
|
|
|
|
|
|
|
|
early_setup
|
|
|
|
|
|
|
|
[ -z "$CONSOLE" ] && CONSOLE="/dev/console"
|
|
|
|
|
|
|
|
read_args
|
|
|
|
|
2008-10-08 14:34:50 +00:00
|
|
|
echo "Waiting for removable media..."
|
2012-12-18 12:38:27 +00:00
|
|
|
C=0
|
2008-09-10 21:21:23 +00:00
|
|
|
while true
|
|
|
|
do
|
2014-05-15 09:36:17 +00:00
|
|
|
for i in `ls /run/media 2>/dev/null`; do
|
|
|
|
if [ -f /run/media/$i/$ROOT_IMAGE ] ; then
|
2011-08-24 07:36:22 +00:00
|
|
|
found="yes"
|
2014-06-28 15:48:24 +00:00
|
|
|
ROOT_DISK="$i"
|
2011-08-24 07:36:22 +00:00
|
|
|
break
|
2014-05-15 09:36:17 +00:00
|
|
|
elif [ -f /run/media/$i/isolinux/$ROOT_IMAGE ]; then
|
2011-08-24 07:36:22 +00:00
|
|
|
found="yes"
|
|
|
|
ISOLINUX="isolinux"
|
2014-06-28 15:48:24 +00:00
|
|
|
ROOT_DISK="$i"
|
2011-08-24 07:36:22 +00:00
|
|
|
break
|
2008-09-10 21:21:23 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$found" = "yes" ]; then
|
|
|
|
break;
|
|
|
|
fi
|
2012-12-18 12:38:27 +00:00
|
|
|
# don't wait for more than $shelltimeout seconds, if it's set
|
|
|
|
if [ -n "$shelltimeout" ]; then
|
|
|
|
echo -n " " $(( $shelltimeout - $C ))
|
|
|
|
if [ $C -ge $shelltimeout ]; then
|
|
|
|
echo "..."
|
|
|
|
echo "Mounted filesystems"
|
|
|
|
mount | grep media
|
|
|
|
echo "Available block devices"
|
2014-05-15 07:05:18 +00:00
|
|
|
cat /proc/partitions
|
2014-05-15 09:36:17 +00:00
|
|
|
fatal "Cannot find $ROOT_IMAGE file in /run/media/* , dropping to a shell "
|
2012-12-18 12:38:27 +00:00
|
|
|
fi
|
|
|
|
C=$(( C + 1 ))
|
|
|
|
fi
|
2008-09-10 21:21:23 +00:00
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2013-09-11 05:01:55 +00:00
|
|
|
# Try to mount the root image read-write and then boot it up.
|
|
|
|
# This function distinguishes between a read-only image and a read-write image.
|
|
|
|
# In the former case (typically an iso), it tries to make a union mount if possible.
|
|
|
|
# In the latter case, the root image could be mounted and then directly booted up.
|
2013-06-28 07:48:53 +00:00
|
|
|
mount_and_boot() {
|
|
|
|
mkdir $ROOT_MOUNT
|
|
|
|
mknod /dev/loop0 b 7 0 2>/dev/null
|
|
|
|
|
2014-06-28 15:48:24 +00:00
|
|
|
if ! mount -o rw,loop,noatime,nodiratime /run/media/$ROOT_DISK/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then
|
2013-09-11 05:01:55 +00:00
|
|
|
fatal "Could not mount rootfs image"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if touch $ROOT_MOUNT/bin 2>/dev/null; then
|
|
|
|
# The root image is read-write, directly boot it up.
|
|
|
|
boot_live_root
|
|
|
|
fi
|
|
|
|
|
2013-06-28 07:48:53 +00:00
|
|
|
# determine which unification filesystem to use
|
|
|
|
union_fs_type=""
|
|
|
|
if grep -q -w "overlayfs" /proc/filesystems; then
|
|
|
|
union_fs_type="overlayfs"
|
|
|
|
elif grep -q -w "aufs" /proc/filesystems; then
|
|
|
|
union_fs_type="aufs"
|
|
|
|
else
|
|
|
|
union_fs_type=""
|
|
|
|
fi
|
|
|
|
|
|
|
|
# make a union mount if possible
|
|
|
|
case $union_fs_type in
|
|
|
|
"overlayfs")
|
|
|
|
mkdir -p /rootfs.ro /rootfs.rw
|
2013-09-11 05:01:55 +00:00
|
|
|
if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
|
2013-06-28 07:48:53 +00:00
|
|
|
rm -rf /rootfs.ro /rootfs.rw
|
2013-09-11 05:01:55 +00:00
|
|
|
fatal "Could not move rootfs mount point"
|
2013-06-28 07:48:53 +00:00
|
|
|
else
|
|
|
|
mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
|
|
|
|
mount -t overlayfs -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw" overlayfs $ROOT_MOUNT
|
|
|
|
mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
|
|
|
|
mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
|
|
|
|
mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"aufs")
|
|
|
|
mkdir -p /rootfs.ro /rootfs.rw
|
2013-09-11 05:01:55 +00:00
|
|
|
if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
|
2013-06-28 07:48:53 +00:00
|
|
|
rm -rf /rootfs.ro /rootfs.rw
|
2013-09-11 05:01:55 +00:00
|
|
|
fatal "Could not move rootfs mount point"
|
2013-06-28 07:48:53 +00:00
|
|
|
else
|
|
|
|
mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
|
|
|
|
mount -t aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $ROOT_MOUNT
|
|
|
|
mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
|
|
|
|
mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
|
|
|
|
mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
"")
|
2013-09-11 05:01:55 +00:00
|
|
|
mount -t tmpfs -o rw,noatime,mode=755 tmpfs $ROOT_MOUNT/media
|
2013-06-28 07:48:53 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# boot the image
|
|
|
|
boot_live_root
|
|
|
|
}
|
|
|
|
|
2008-10-08 14:34:50 +00:00
|
|
|
case $label in
|
|
|
|
boot)
|
2013-06-28 07:48:53 +00:00
|
|
|
mount_and_boot
|
2008-10-08 14:34:50 +00:00
|
|
|
;;
|
2012-07-04 04:05:46 +00:00
|
|
|
install|install-efi)
|
2014-05-15 09:36:17 +00:00
|
|
|
if [ -f /run/media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then
|
2012-07-04 04:05:46 +00:00
|
|
|
./$label.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params
|
2008-10-08 14:34:50 +00:00
|
|
|
else
|
2012-07-04 04:05:46 +00:00
|
|
|
fatal "Could not find $label script"
|
2008-10-08 14:34:50 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If we're getting here, we failed...
|
|
|
|
fatal "Installation image failed"
|
|
|
|
;;
|
2014-06-28 21:57:34 +00:00
|
|
|
*)
|
|
|
|
# Not sure what boot label is provided. Try to boot to avoid locking up.
|
|
|
|
mount_and_boot
|
|
|
|
;;
|
2008-10-08 14:34:50 +00:00
|
|
|
esac
|