home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / linux / 10279 < prev    next >
Encoding:
Text File  |  1992-09-09  |  5.7 KB  |  159 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!decwrl!concert!rock!taco!jlnance
  3. From: jlnance@eos.ncsu.edu (JAMES LEWIS NANCE)
  4. Subject: Re: Two suggestions .. comments welcome, please!
  5. Message-ID: <1992Sep9.125109.29966@ncsu.edu>
  6. Originator: jlnance@volt.ece.ncsu.edu
  7. Lines: 144
  8. Sender: news@ncsu.edu (USENET News System)
  9. Reply-To: jlnance@eos.ncsu.edu (JAMES LEWIS NANCE)
  10. Organization: North Carolina State University, Project Eos
  11. References:  <KFOGEL.92Sep8192936@edvac.cs.oberlin.edu>
  12. Distribution: comp.os.linux
  13. Date: Wed, 9 Sep 1992 12:51:09 GMT
  14.  
  15.  
  16. In article <KFOGEL.92Sep8192936@edvac.cs.oberlin.edu>, kfogel@edvac.cs.oberlin.edu (Karl Fogel) writes:
  17. |> 
  18. |>     It would be a great help to those of use who don't have a disk
  19. |> editor for someone to upload pre-edited bootimages to the directories
  20. |> that now normally hold bootimages and/or rootimages.  We'd need four
  21. |> more images, I guess: one for booting partition 1, one for 2, 3, and
  22. |> partition 4. If the space can be spared on the ftp sites, it would be
  23. |> a great help. I can't afford to buy a disk-editor myself, and I don't 
  24. |> want to pirate one either. Is there anyone who owns a good editor who
  25. |> would be willing to do this for future releases? (Yes, I'm always this
  26. |> glib when volunteering other people :-)
  27.  
  28. There is a simple Turbo C program which will set the boot device.  It was 
  29. written by Iain Reid and I have modifided it slightly.  You just put a 
  30. floppy which has the bootimage on it in your A drive and run the program with 
  31. your boot device name as the first command line argument.  If you dont have
  32. a TC compiler prehaps you can get someone to compile it for you (I dont have
  33. one myself).  
  34.  
  35. Hope this helps
  36.  
  37. Jim Nance
  38.  
  39. /********************************************************/
  40. /* Rootset.c - modify Linux bootdisk root device entry  */
  41. /*           - quick Turbo C hack by Iain_Reid@ed.ac.uk */
  42. /********************************************************/
  43.  
  44. /********************************************************/
  45. /* Modifided to take device name in addition to         */
  46. /* major/minor number                                   */
  47. /*           - jlnance@eos.ncsu.edu                     */
  48. /********************************************************/
  49.  
  50. #include "stdlib.h"
  51. #include "stdio.h"
  52. #include "string.h"
  53.  
  54. #ifndef DEBUG
  55. #include "conio.h"
  56. #include "process.h"
  57. #include "dos.h"
  58. #endif
  59.  
  60. #ifdef DEBUG
  61. int absread (int a, int b, int c, char *x) { return 0; }
  62. int abswrite(int a, int b, int c, char *x) { return 0; }
  63. #endif
  64.  
  65. /*
  66.     Device      Major    Minor       Device      Major    Minor
  67.     ------      -----    -----       ------      -----    -----
  68.     /dev/hda1     3        1         /dev/hdb1     3        65
  69.     /dev/hda2     3        2         /dev/hdb2     3        66
  70.     /dev/hda3     3        3         /dev/hdb3     3        67
  71.     /dev/hda4     3        4         /dev/hdb4     3        68
  72.     /dev/hda5     3        5         /dev/hdb5     3        69
  73.     /dev/hda6     3        6         /dev/hdb6     3        70
  74.     /dev/hda7     3        7         /dev/hdb7     3        71
  75.     /dev/hda8     3        8         /dev/hdb8     3        72
  76. */
  77.  
  78. typedef struct {
  79.      char                *dev;
  80.      int                 major;
  81.      int                 minor;
  82.      } table;
  83.  
  84. static table look_up[] = {
  85.      {"hda1", 3, 1 }, {"hda2", 3, 2 }, {"hda3", 3, 3 }, {"hda4", 3, 4 },
  86.      {"hda5", 3, 5 }, {"hda6", 3, 6 }, {"hda7", 3, 7 }, {"hda8", 3, 8 },
  87.      {"hdb1", 3, 65}, {"hdb2", 3, 66}, {"hdb3", 3, 67}, {"hdb4", 3, 68},
  88.      {"hdb5", 3, 69}, {"hdb6", 3, 70}, {"hdb7", 3, 71}, {"hdb8", 3, 72},
  89.      {"at0" , 2, 8 }, {"at1" , 2, 9 }, {"at2" , 2, 10}, {"at3" , 2, 11},
  90.      {"PS0" , 2, 28}, {"PS1" , 2, 29}, {"PS2" , 2, 30}, {"PS3" , 2, 31},
  91.      {"\0"  , 0, 0 }
  92.      };
  93.  
  94. int main(
  95. int                      ac,
  96. char                     **av) {
  97. char                     buf[512];
  98. char                     small[16];
  99. char                     *dev;
  100. table                    *tp;
  101. int                      lc;
  102.  
  103. if(ac !=2 && ac !=3) {
  104.      fprintf(stderr,"%s: set Linux boot device\n",av[0]);
  105.      fprintf(stderr,"Usage: %s <root fs> or %s <major> <minor>\n\n",
  106.      av[0], av[0]);
  107.      fprintf(stderr,"root fs may be:\n");
  108.      for(lc=0, tp=look_up; *(tp->dev); tp++) {
  109.           fprintf(stderr,"/dev/%-4s ", tp->dev);
  110.           if(++lc == 7) {lc=0; fprintf(stderr,"\n");}
  111.           }
  112.      fprintf(stderr,"\n");
  113.      exit(1);
  114.      }
  115.  
  116. if(ac==2) {
  117.      dev = strstr(av[1],"dev/");
  118.      if(dev==NULL) dev=av[1]; else dev += 4;
  119.  
  120.      for(tp=look_up; *(tp->dev); tp++) if(!strcmp(tp->dev,dev)) break;
  121.      if(!(*(tp->dev))) {
  122.           fprintf(stderr,"Do not know what device %s is \n", av[1]);
  123.           exit(2);
  124.           }
  125.      }
  126.  
  127.      /**************************************************************/
  128.      /* Don't remove this keypress bit 'cos it gives you a chance  */
  129.      /* to run this program from your dos boot floppy, remove that */
  130.      /* disk, put your linux boot disk into the same drive, patch  */
  131.      /* in the new root device details and save them. No HD or     */
  132.      /* rawrite required! (v. handy if DOS is dead)                */
  133.      /**************************************************************/
  134.  
  135.      printf ("Insert Linux boot disk into drive A and press RETURN\n");
  136.      fgets(small, 16, stdin);
  137.  
  138.      if (absread (0, 1, 0, buf) != 0) {
  139.           fprintf(stderr,"Disk reading problem\n");
  140.           exit (-1);
  141.      }
  142.  
  143.      printf ("Current rootdevice: Major %d Minor: %d\n",
  144.      (int)buf[509], (int)buf[508]);
  145.  
  146.      buf[508] = (ac==2)? tp->minor : atoi(av[2]);
  147.      buf[509] = (ac==2)? tp->major : atoi(av[1]);
  148.  
  149.      if (abswrite (0, 1, 0, buf) != 0) {
  150.           fprintf(stderr,"Disk writing problem\n");
  151.           exit (-1);
  152.      }
  153.  
  154.      printf ("New rootdevice: Major %d Minor: %d\n",
  155.      (int)buf[509], (int)buf[508]);
  156.  
  157. return 0;
  158. }
  159.