bootplan9 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/rc
  2. rfork e
  3. . /rc/bin/pc/defs
  4. if(! ~ $#* 1) {
  5. echo 'usage: bootplan9 /dev/sdC0' >[1=2]
  6. echo 'sets active the plan 9 partition on the named disk.' >[1=2]
  7. exit usage
  8. }
  9. disk=$1
  10. fn x {
  11. if(! test -f $disk/$1) {
  12. echo 'could not find '$disk/$1
  13. exit disk
  14. }
  15. }
  16. x plan9
  17. x data
  18. x ctl
  19. diskbase=`{basename `{cleanname $disk}}
  20. first=`{ls -p '#S' | sed 1q}
  21. if(! ~ $first $diskbase) {
  22. echo 'warning: The plan 9 partition is not on the boot disk,' >[1=2]
  23. echo 'so making it the active partition will have no effect.' >[1=2]
  24. }
  25. p9offset=`{disk/fdisk -p $disk/data |grep '^part plan9 ' | awk '{print $4}'}
  26. if(! ~ $#p9offset 1) {
  27. echo 'could not find plan 9 partition.' >[1=2]
  28. echo 'cannot happen' >[1=2]
  29. exit bad
  30. }
  31. if(test $p9offset -gt 4128705) { # 65536 * 63
  32. echo >[1=2]
  33. echo 'Your Plan 9 partition is more than 2GB into your disk,' >[1=2]
  34. echo 'and the master boot records used by most operating systems' >[1=2]
  35. echo 'cannot access it (and thus cannot boot it).' >[1=2]
  36. echo >[1=2]
  37. echo 'Would you like to install a master boot record' >[1=2]
  38. echo 'that will be able to access partitions more than 2GB into the disk?' >[1=2]
  39. echo >[1=2]
  40. prompt 'Install a new mbr' y n
  41. switch($rd) {
  42. case n
  43. echo >[1=2]
  44. echo 'Not setting Plan 9 partition active, then.' >[1=2]
  45. echo >[1=2]
  46. exit bad
  47. case y
  48. disk/mbr -m /386/mbr $disk/data
  49. }
  50. }
  51. p9part=`{disk/fdisk $disk/data >[2]/dev/null </dev/null |
  52. grep PLAN9 | sed 1q | sed 's/ *(p.) .*/\1/'}
  53. if(~ $#p9part 1) {
  54. { echo 'A '^$p9part; echo w } | disk/fdisk $disk/data >[2]/dev/null >/dev/null
  55. }
  56. if not {
  57. echo 'Could not find Plan 9 partition.'
  58. exit notdone
  59. }
  60. exit