From: der.eremit@email.de
To: Randy Dunlap <rddunlap@osdl.org>
Cc: spam99@2thebatcave.com, linux-kernel@vger.kernel.org
Subject: Re: getting usb mass storage to finish before running init?
Date: Fri, 13 Feb 2004 13:55:15 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.58.0402131348530.163@neptune.local> (raw)
In-Reply-To: <2181.4.5.45.142.1076645210.squirrel@www.osdl.org>
On Thu, 12 Feb 2004, Randy Dunlap wrote:
> > Check available devices for root filesystem (in case you're booting from
> > IDE). If it's not there, wait a moment, then look for additional
> > devices. If nothing shows up, repeat.
>
> That's basically what my usb-boot patch for 2.4.22 does:
> http://www.xenotime.net/linux/usb/usbboot-2422.patch
>
> I haven't tried to port it to 2.6.x.
I don't think this requires in-kernel code once an initrd or
initramfs is going.
Here's what I use for CD-ROM booting (compiles to 370k statically
linked code using glibc):
#include <sys/klog.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int pivot_root(const char *new_root, const char *put_old);
#define KLOG_GET_MESSAGES 3
#define KLOG_SET_LOGLEVEL 8
#define BUFSIZE 65536
#define DEVNAMEMAX 16
#define UNIQUEFILE "/mnt/etc/rc.d/rc.cdrom"
void halt_system(void)
{
while (1)
;
}
void check_okay(int res, const char *errmsg)
{
if (res < 0) {
printf("Error: %s\n", errmsg);
halt_system();
}
}
int correct_medium(const char *devname)
{
int res;
struct stat buf;
res = mount(devname, "/mnt", "iso9660", (0xC0ED << 16) | MS_RDONLY, 0);
if (res == -1) {
printf("No suitable medium on %s\n", devname);
return 0;
}
res = stat(UNIQUEFILE, &buf);
if (res == -1) {
umount("/mnt");
printf("Unrelated filesystem on %s\n", devname);
return 0;
}
printf("Root filesystem found on %s\n", devname);
return 1;
}
void change_root(void)
{
int res;
res = chdir("/mnt");
check_okay(res, "could not cd into CD-ROM root filesystem");
res = pivot_root("/mnt", "/mnt/initrd");
check_okay(res, "could not change / to CD-ROM root filesystem");
execl("/sbin/init", "/sbin/init");
check_okay(-1, "could not execute /sbin/init");
}
int main(int argc, char **argv)
{
char buf[BUFSIZE];
char devname[DEVNAMEMAX];
char *work, *line, *sub;
int res, found = 0;
puts("Attempting to locate CD-ROM device");
klogctl(KLOG_SET_LOGLEVEL, NULL, 1);
memset(buf, 0, BUFSIZE);
res = klogctl(KLOG_GET_MESSAGES, buf, BUFSIZE);
check_okay(res, "could not read kernel messages");
work = buf;
while (work) {
line = strsep(&work, "\n");
sub = strstr(line, "ATAPI CD/DVD-ROM drive");
if (sub) {
memset(devname, 0, DEVNAMEMAX);
strcpy(devname, "/dev/");
memcpy(devname+5, line+3, 3);
printf("ATAPI CD-ROM at: %s\n", devname);
if (correct_medium(devname))
change_root();
found = 1;
}
sub = strstr(line, "Attached scsi CD-ROM sr");
if (sub) {
memset(devname, 0, DEVNAMEMAX);
strcpy(devname, "/dev/scd");
memcpy(devname+8, line+26, 1);
printf("SCSI CD-ROM at: %s\n", devname);
if (correct_medium(devname))
change_root();
found = 1;
}
}
if (!found)
puts("No CD-ROM device found");
else
puts("Root filesystem not found on CD-ROM device(s)");
halt_system();
/* NOT REACHED */
return 0;
}
--
Ciao,
Pascal
next prev parent reply other threads:[~2004-02-13 12:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1oAMR-6St-13@gated-at.bofh.it>
2004-02-13 2:09 ` der.eremit
2004-02-13 2:34 ` Nick Bartos
2004-02-13 12:48 ` der.eremit
2004-02-13 12:56 ` Nick Bartos
2004-02-13 4:06 ` Randy Dunlap
2004-02-13 12:55 ` der.eremit [this message]
2004-02-13 1:54 Nick Bartos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0402131348530.163@neptune.local \
--to=der.eremit@email.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rddunlap@osdl.org \
--cc=spam99@2thebatcave.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®