From: jlnance@eos.ncsu.edu (JAMES LEWIS NANCE)
Subject: Re: Two suggestions .. comments welcome, please!
Originator: jlnance@volt.ece.ncsu.edu
Reply-To: jlnance@eos.ncsu.edu (JAMES LEWIS NANCE)
Organization: North Carolina State University, Project Eos
Distribution: comp.os.linux
Date: Wed, 9 Sep 1992 12:51:09 GMT


In article <KFOGEL.92Sep8192936@edvac.cs.oberlin.edu>, kfogel@edvac.cs.oberlin.edu (Karl Fogel) writes:
|> 
|> 	It would be a great help to those of use who don't have a disk
|> editor for someone to upload pre-edited bootimages to the directories
|> that now normally hold bootimages and/or rootimages.  We'd need four
|> more images, I guess: one for booting partition 1, one for 2, 3, and
|> partition 4. If the space can be spared on the ftp sites, it would be
|> a great help. I can't afford to buy a disk-editor myself, and I don't 
|> want to pirate one either. Is there anyone who owns a good editor who
|> would be willing to do this for future releases? (Yes, I'm always this
|> glib when volunteering other people :-)

There is a simple Turbo C program which will set the boot device.  It was 
written by Iain Reid and I have modifided it slightly.  You just put a 
floppy which has the bootimage on it in your A drive and run the program with 
your boot device name as the first command line argument.  If you dont have
a TC compiler prehaps you can get someone to compile it for you (I dont have
one myself).  

Hope this helps

Jim Nance

/********************************************************/
/* Rootset.c - modify Linux bootdisk root device entry  */
/*           - quick Turbo C hack by Iain_Reid@ed.ac.uk */
/********************************************************/

/********************************************************/
/* Modifided to take device name in addition to         */
/* major/minor number                                   */
/*           - jlnance@eos.ncsu.edu                     */
/********************************************************/

#include "stdlib.h"
#include "stdio.h"
#include "string.h"

#ifndef DEBUG
#include "conio.h"
#include "process.h"
#include "dos.h"
#endif

#ifdef DEBUG
int absread (int a, int b, int c, char *x) { return 0; }
int abswrite(int a, int b, int c, char *x) { return 0; }
#endif

/*
    Device      Major    Minor       Device      Major    Minor
    ------      -----    -----       ------      -----    -----
    /dev/hda1     3        1         /dev/hdb1     3        65
    /dev/hda2     3        2         /dev/hdb2     3        66
    /dev/hda3     3        3         /dev/hdb3     3        67
    /dev/hda4     3        4         /dev/hdb4     3        68
    /dev/hda5     3        5         /dev/hdb5     3        69
    /dev/hda6     3        6         /dev/hdb6     3        70
    /dev/hda7     3        7         /dev/hdb7     3        71
    /dev/hda8     3        8         /dev/hdb8     3        72
*/

typedef struct {
     char                *dev;
     int                 major;
     int                 minor;
     } table;

static table look_up[] = {
     {"hda1", 3, 1 }, {"hda2", 3, 2 }, {"hda3", 3, 3 }, {"hda4", 3, 4 },
     {"hda5", 3, 5 }, {"hda6", 3, 6 }, {"hda7", 3, 7 }, {"hda8", 3, 8 },
     {"hdb1", 3, 65}, {"hdb2", 3, 66}, {"hdb3", 3, 67}, {"hdb4", 3, 68},
     {"hdb5", 3, 69}, {"hdb6", 3, 70}, {"hdb7", 3, 71}, {"hdb8", 3, 72},
     {"at0" , 2, 8 }, {"at1" , 2, 9 }, {"at2" , 2, 10}, {"at3" , 2, 11},
     {"PS0" , 2, 28}, {"PS1" , 2, 29}, {"PS2" , 2, 30}, {"PS3" , 2, 31},
     {"\0"  , 0, 0 }
     };

int main(
int                      ac,
char                     **av) {
char                     buf[512];
char                     small[16];
char                     *dev;
table                    *tp;
int                      lc;

if(ac !=2 && ac !=3) {
     fprintf(stderr,"%s: set Linux boot device\n",av[0]);
     fprintf(stderr,"Usage: %s <root fs> or %s <major> <minor>\n\n",
     av[0], av[0]);
     fprintf(stderr,"root fs may be:\n");
     for(lc=0, tp=look_up; *(tp->dev); tp++) {
          fprintf(stderr,"/dev/%-4s ", tp->dev);
          if(++lc == 7) {lc=0; fprintf(stderr,"\n");}
          }
     fprintf(stderr,"\n");
     exit(1);
     }

if(ac==2) {
     dev = strstr(av[1],"dev/");
     if(dev==NULL) dev=av[1]; else dev += 4;

     for(tp=look_up; *(tp->dev); tp++) if(!strcmp(tp->dev,dev)) break;
     if(!(*(tp->dev))) {
          fprintf(stderr,"Do not know what device %s is \n", av[1]);
          exit(2);
          }
     }

     /**************************************************************/
     /* Don't remove this keypress bit 'cos it gives you a chance  */
     /* to run this program from your dos boot floppy, remove that */
     /* disk, put your linux boot disk into the same drive, patch  */
     /* in the new root device details and save them. No HD or     */
     /* rawrite required! (v. handy if DOS is dead)                */
     /**************************************************************/

     printf ("Insert Linux boot disk into drive A and press RETURN\n");
     fgets(small, 16, stdin);

     if (absread (0, 1, 0, buf) != 0) {
          fprintf(stderr,"Disk reading problem\n");
          exit (-1);
     }

     printf ("Current rootdevice: Major %d Minor: %d\n",
     (int)buf[509], (int)buf[508]);

     buf[508] = (ac==2)? tp->minor : atoi(av[2]);
     buf[509] = (ac==2)? tp->major : atoi(av[1]);

     if (abswrite (0, 1, 0, buf) != 0) {
          fprintf(stderr,"Disk writing problem\n");
          exit (-1);
     }

     printf ("New rootdevice: Major %d Minor: %d\n",
     (int)buf[509], (int)buf[508]);

return 0;
}