Coolstream - Booten vom USB-Stick

Fremd-Buildsysteme
Antworten
Striper
Erleuchteter
Erleuchteter
Beiträge: 625
Registriert: Samstag 8. September 2007, 16:17

Coolstream - Booten vom USB-Stick

Beitrag von Striper »

THX seife!

Um vom USB-Stick booten zu können muss man nicht wirklich viel tun.
Naja, eigentlich wird ja nicht vom Stick gebootet, aber das Filesystem vom USB-Stick wird als root-FS benutzt.

Zu tun ist das folgende:

1. USB-Stick partitionieren, auf Partition /dev/sda1 ein ext3 FS anlegen (ich würde übrigens nicht das mkfs.ext3 auf der Coolstream dafür benutzen, das busybox mkfs.ext3 ist bekanntermassen buggy).

2. Den USB-Stick auf der Coolstream mounten, alles rüberkopieren:

Code: Alles auswählen

cd /tmp/sda1
cp -a /bin /dev /etc /lib /media /root /sbin /share /usr /var ./
mkdir mnt proc sys tmp
3. eine Datei "/linuxrc" mit folgendem Inhalt anlegen (nicht auf dem stick!):

Code: Alles auswählen

#!/bin/sh
#
# /linuxrc script for USB booting
#
# (C) 2009 Stefan Seyfried, License: GPL V2
#
# this is a hack for booting the coolstream HD1 from USB
# put this script into the original root fs as /linuxrc,
# chmod it to 0755 and add "init=/linuxrc" to the bootargs of
# U-Boot
#
# the usb stick should have an "/oldroot" directory, so you
# can unmount the jffs2 "old" root later.
#
e="/bin/echo linuxrc:"

$e "***** linuxrc ******"
/bin/mkdir -p /tmp/newroot

$e mounting sda1...

if ! /bin/mount -n /dev/sda1 /tmp/newroot; then
	$e "mount failed, doing normal init. Goodbye!"
	exec /sbin/init
fi

if /bin/test -e /tmp/newroot/sbin/pivot_root; then
	$e "using pivot_root to enter new root"
	cd /tmp/newroot
	sbin/pivot_root . oldroot
	bin/mknod dev/console c 5 1
	exec sbin/chroot . sbin/init < dev/console > dev/console 2>&1
fi

$e "no /sbin/pivot_root on sda1, trying normal chroot"

if /bin/test -x /tmp/newroot/sbin/init; then
	exec /sbin/chroot /tmp/newroot /sbin/init
fi

$e "no /sbin/init on sda1, booting from flash."
exec /sbin/init
Das war's schon. Um nun vom USB-Stick zu booten, einfach im u-boot anhalten und

Code: Alles auswählen

setenv bootargs console=ttyRI0 mtdparts=cx2450xflash:512k(U-Boot)ro,4096k(kernel),28160k(systemFS) root=mtd2 rootfstype=jffs2 rw mem=384M init=/linuxrc
Wenn ihr dann im / *kein* linuxrc und dafür lost+found habt, hat es geklappt :-)

Weil die /linuxrc ein fallback hat, macht es auch nichts aus, wenn der stick nicht steckt. Und weil der Kernel ein fallback hat, macht es auch nichts aus, wenn kein /linuxrc da ist. Insofern könnte man das per "saveenv" zum default machen, die Kiste würde sogar nach dem nächsten Image-Update noch booten. Das soll aber jeder machen wie er will.
det-box
Einsteiger
Einsteiger
Beiträge: 211
Registriert: Samstag 24. Januar 2004, 18:11

Re: Coolstream - Booten vom USB-Stick

Beitrag von det-box »

halo,

kann die /linuxrc erweitert werden, das auch auf sdb1 nach den System geucht wird?
wenn ja, wie ?

Det
det-box
Einsteiger
Einsteiger
Beiträge: 211
Registriert: Samstag 24. Januar 2004, 18:11

Re: Coolstream - Booten vom USB-Stick

Beitrag von det-box »

Hallo,
mit dieser "linuxrc" bootet das System auch von "/dev/sdb1":
(zumindest bei mir"

Code: Alles auswählen

#!/bin/sh
#
# /linuxrc script for USB booting
#
# (C) 2009 Stefan Seyfried, License: GPL V2
#
# this is a hack for booting the coolstream HD1 from USB
# put this script into the original root fs as /linuxrc,
# chmod it to 0755 and add "init=/linuxrc" to the bootargs of
# U-Boot
#
# the usb stick should have an "/oldroot" directory, so you
# can unmount the jffs2 "old" root later.
#
e="/bin/echo linuxrc:"

$e "***** linuxrc ******"
/bin/mkdir -p /tmp/newroot

$e mounting sda1...

if ! /bin/mount -n /dev/sda1 /tmp/newroot; then
	if ! /bin/mount -n /dev/sdb1 /tmp/newroot; then
		$e "mount failed, doing normal init. Goodbye!"
		exec /sbin/init
   	fi
fi

if /bin/test -e /tmp/newroot/sbin/pivot_root; then
	$e "using pivot_root to enter new root"
	cd /tmp/newroot
	sbin/pivot_root . oldroot
	bin/mknod dev/console c 5 1
	exec sbin/chroot . sbin/init < dev/console > dev/console 2>&1
fi

$e "no /sbin/pivot_root on sda1, trying normal chroot"

if /bin/test -x /tmp/newroot/sbin/init; then
	exec /sbin/chroot /tmp/newroot /sbin/init
fi

$e "no /sbin/init on sda1, booting from flash."
exec /sbin/init 
Antworten