Re: Use a CD-ROM as root?
Michele,
Well, I tried your program out on my Aptive S90. Its got some
pathological hardware which causes the cdrom not to be detected at boot
unless I specify the I/O addresses and IRQ's on the boot cmdline.
(a) Under a kernel which had been booted with the correct cmdline, the
program worked correctly.
(b) Under a kernel which had not been booted with the cmdline specifying
the I/O addresses and the IRQ's, the program failed. This proves - if it
proves anything at all - that the program will not work on all hardware.
However, here is an interesting question. Here is my ide setup :
hda ---------> hard disk 1
hdb ---------> hard disk 2
hdc ---------> hard disk 3
hdd ---------> nothing
hde ---------> cdrom drive
Here is the result of me putting a 'perror("fopen ")' after the
'fopen' in the function 'testdevice' of your program :
fopen : Success
Device open/test failed for /dev/hda <---- Debugging msg printing *l
fopen : Success
Device open/test failed for /dev/hdb
fopen : Success
Device open/test failed for /dev/hdc
fopen : Device not configured
Device open/test failed for /dev/hdd
fopen : Operation not supported by device
Device open/test failed for /dev/hde
fopen : No such file or directory
(1) Why does /dev/hdc get the message 'Device not configured'? This
disk contains the Debian install that I booted into to run this program.
(2) The obvious question : why doesnt it work for /dev/hde?
Regards,
Jor-el
On Sun, 4 Apr 1999, Michele Dalla Silvestra wrote:
> On Sat, 3 Apr 1999, Jor-el wrote:
>
> > I tried to clip out the gzipped program you sent in your mail, but
> > it didnt work. Could you either put in the source code, or send it as a
> > MIME atachment please?
>
> Ok
>
> ciao
>
> Michele
>
>
> /*
> isodetect.c
>
> Looks in first block of an block-device and checks if there is an ISO9660-
> filesystem on it. This is done by checking for a string "CD001".
>
> Also reads certain information out of the block.
>
> 14.11.95 T.Niederreiter (based on cdlabel.c by aeb)
>
> Copyright (C) 1999 - Michele Dalla Silvestra <dalla@debian.org>
> Join detectcd, set_loop and mount function
> */
>
> #include <stdio.h>
> #include <ctype.h>
> #include <unistd.h>
> #include <fcntl.h>
> #include <termio.h>
> #include <string.h>
> #include <sys/mount.h>
> #include <linux/loop.h>
>
>
> char *devlist[]={"/dev/hda","/dev/hdb","/dev/hdc","/dev/hdd",
> "/dev/hde","/dev/hdf","/dev/scd0","/dev/scd1",NULL};
>
>
>
> int symlink(const char *oldpath, const char *newpath);
> int fileno( FILE *stream);
>
>
> int testdevice(char *dev)
> {
> FILE *infile;
> char buf[1024];
> infile = fopen(dev,"rb");
> if (infile == NULL)
> return 1;
> if (lseek(fileno(infile), 32768, SEEK_SET) < 0)
> return 1;
> if (read(fileno(infile), buf, sizeof(buf)) != sizeof(buf))
> return 1;
> if (strncmp(buf, "\001CD001\001", 8) != 0)
> return 1;
> else
> return 0;
> }
>
>
> int set_loop(const char *device, const char *file)
> {
> struct loop_info loopinfo;
> int fd, ffd;
> if ((ffd=open(file,O_RDONLY))<0)
> return 1;
> if ((fd=open(device,O_RDONLY))<0)
> return 1;
> memset(&loopinfo, 0, sizeof(loopinfo));
> strncpy(loopinfo.lo_name, file, LO_NAME_SIZE);
> loopinfo.lo_name[LO_NAME_SIZE-1] = 0;
> loopinfo.lo_encrypt_type = 0;
> loopinfo.lo_offset = 0;
> loopinfo.lo_encrypt_key_size = 0;
> if (ioctl(fd, LOOP_SET_FD, ffd) < 0)
> {
> perror("ioctl: LOOP_SET_FD");
> return 1;
> }
> if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0)
> {
> (void) ioctl(fd, LOOP_CLR_FD, 0);
> perror("ioctl: LOOP_SET_STATUS");
> return 1;
> }
> close(fd);
> close(ffd);
> return 0;
> }
>
>
> int main(int argc, char **argv)
> {
> char **l=devlist;
> while ((*l)!=NULL)
> if (testdevice(*l)==0)
> break;
> else
> l++;
> if ((*l)!=NULL)
> {
> symlink(*l,"/dev/cdrom");
> mount(*l,"/cdrom","iso9660",MS_MGC_VAL | MS_RDONLY,"");
> set_loop("/dev/loop7","/cdrom/i386/debian-live.isofs");
> mount("/dev/loop7","/looproot","iso9660",MS_MGC_VAL | MS_RDONLY,"");
> mount("proc","/proc","proc",MS_MGC_VAL,"");
> }
> return 0;
> }
>
>
Reply to: