partdisk 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/rc
  2. # desc: edit partition tables (e.g., to create a plan 9 partition)
  3. # prereq: configfs
  4. switch($1){
  5. case go
  6. disks=`{ls /dev/sd*/data >[2]/dev/null | sed 's!/dev/(sd..)/data!\1!'}
  7. if(~ $#disks 0) {
  8. echo 'No disk devices were found on your system.'
  9. echo 'The installation process cannot continue.'
  10. exit giveup
  11. }
  12. echo 'The following disk devices were found.'
  13. echo
  14. for(i in $disks) {
  15. desc=`{cat /dev/$i/ctl | sed 1q | sed 's/inquiry //'}
  16. echo $i '-' $desc
  17. echo e | disk/fdisk -r /dev/$i/data >[2]/dev/null | grep -v '^ mbr'
  18. echo
  19. }
  20. okay=no
  21. defdisk=$disks(1)
  22. if(~ $#disks 1)
  23. default=(-d $disks)
  24. if not
  25. default=()
  26. prompt $default 'Disk to partition' $disks
  27. disk=$rd
  28. if(! hasmbr /dev/$disk/data) {
  29. echo 'The disk you selected HAS NO master boot record on its first sector.'
  30. echo '(Perhaps it is a completely blank disk.)'
  31. echo 'You need a master boot record to use the disk.'
  32. echo 'Should we install a default master boot record?'
  33. echo
  34. prompt 'Install mbr' y n
  35. switch($rd) {
  36. case y
  37. disk/mbr -m /386/mbr /dev/$disk/data
  38. pickdisk=done
  39. }
  40. }
  41. echo
  42. echo 'This is disk/fdisk; use it to create a Plan 9 partition.'
  43. echo 'If there is enough room, a Plan 9 partition will be'
  44. echo 'suggested; you can probably just type ''w'' and then ''q''.'
  45. echo
  46. disk/fdisk -a /dev/$disk/data
  47. disk/fdisk -p /dev/$disk/data >/dev/$disk/ctl >[2]/dev/null
  48. for(i in /dev/sd*/plan9*){
  49. if(test -f $i){
  50. d=`{basename -d $i}
  51. disk/prep -p $i >$d/ctl >[2]/dev/null
  52. }
  53. }
  54. case checkdone
  55. # we want at least one disk with both an mbr and a plan9 partition
  56. mbrandplan9=0
  57. disks=`{ls /dev/sd*/plan9 >[2]/dev/null | sed 's!/dev/(sd..)/plan9!\1!'}
  58. for(disk in $disks) {
  59. if(hasmbr /dev/$disk/data)
  60. mbrandplan9=1
  61. }
  62. if(~ $mbrandplan9 0){
  63. partdisk=notdone
  64. export partdisk
  65. }
  66. }