Advertisement
Geometrian

Untitled

Jul 16th, 2013
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.54 KB | None | 0 0
  1. #Sets up a common disk image that is used for building the VM disk or
  2. #installing to USB
  3.  
  4. #See: http://wiki.osdev.org/Loopback_Device
  5. #See: http://superuser.com/questions/130955/how-to-install-grub-into-an-img-file
  6.  
  7. echo "######## MOSS beginning setup for release . . ."
  8.  
  9. export remake_disk=0
  10. export remake_fs=0
  11. export remake_grub=0
  12.  
  13. #Note: on changing these, change also the Bochs configuration files.
  14. export CYLINDERS=100
  15. export HEADS=16
  16. export SECTORS_PER_TRACK=63
  17. export SECTOR_SIZE=512
  18.  
  19. if [ $remake_disk -eq 1 ]
  20. then
  21.  
  22. #Make HDD image
  23. echo "######## Making HDD file . . ."
  24. dd if=/dev/zero of=build/moss-disk.bin bs=$((HEADS*SECTORS_PER_TRACK*SECTOR_SIZE)) count=$CYLINDERS
  25.  
  26. #Make partition on disk file (re-enable as necessary)
  27. echo "######## Making partition thereon . . ."
  28. cat <<EOF | fdisk -u -C$((CYLINDERS)) -S$((SECTORS_PER_TRACK)) -H$((HEADS)) build/moss-disk.bin
  29. o
  30. n
  31. p
  32.  
  33.  
  34.  
  35. a
  36. 1
  37. p
  38. w
  39. EOF
  40.  
  41. fi
  42.  
  43.  
  44. echo "######## Filling disk . . ."
  45. #This next section actually puts a file system and GrUB on the disk.  It took a lot of work to get to work
  46. #since GrUB apparently wasn't intended (or at least tested sufficiently) to do this.  A lot is based on
  47. #http://www.slideshare.net/sukhdotin/installing-grub-on-virtual-hard-disk-images-5094625, but I found
  48. #http://www.omninerd.com/articles/Installing_GRUB_on_a_Hard_Disk_Image_File, which should be just about
  49. #the same.
  50.  
  51. #Also, this section puts the kernel and all of the needed files on the disk.
  52.  
  53. #Mount the disk image in a loop device
  54. sudo losetup /dev/loop0 build/moss-disk.bin
  55.  
  56. #Make the disk image's partitions into devices
  57. sudo kpartx -v -a /dev/loop0
  58. #Make a file system on first partition
  59. #   Note: source also explains how to set up FAT32
  60. if [ $remake_fs -eq 1 ]
  61. then
  62. echo "######## Making a filesystem . . ."
  63. sudo mke2fs /dev/mapper/loop0p1
  64. #Note: may have to unmount loops, restart, and then remount loops here.  See http://forum.osdev.org/viewtopic.php?f=1&t=26907
  65. else
  66. echo "######## NOT making a filesystem."
  67. fi
  68. #Mount the first partition
  69. sudo mount -t ext2 /dev/mapper/loop0p1 /mnt
  70. #Set up first partition's /boot directory
  71. echo "######## Copying over GrUB files . . ."
  72. sudo mkdir -p /mnt/boot/grub
  73. #I tried.  I really did, to use grub-install.  It just kept failing:
  74. #   http://forum.osdev.org/viewtopic.php?f=1&t=26907
  75. #   http://ebroder.net/2009/08/04/installing-grub-onto-a-disk-image/
  76. #   http://superuser.com/questions/619571/installing-grub-legacy-on-virtual-disk
  77. #At the suggestion of http://www.slideshare.net/sukhdotin/installing-grub-on-virtual-hard-disk-images-5094625,
  78. #just copy the needed files over.
  79. sudo cp source/grub/stage1 /mnt/boot/grub/stage1
  80. sudo cp source/grub/stage2 /mnt/boot/grub/stage2
  81. sudo cp source/grub/e2fs_stage1_5 /mnt/boot/grub/e2fs_stage1_5
  82. #Copy the kernel over and the facility to boot it
  83. echo "######## Copying over kernel files . . ."
  84. sudo cp build/MOSS.bin /mnt/boot/MOSS.bin
  85. sudo cp source/grub/menu.lst /mnt/boot/grub/menu.lst
  86. #Unmount the first partition
  87. sudo umount /dev/mapper/loop0p1
  88. #Unmake the first partition as a device
  89. sudo kpartx -d /dev/loop0
  90.  
  91. #Setup GrUB device map.  I've done this before, but never passing /dev/null in . . .
  92. if [ $remake_grub -eq 1 ]
  93. then
  94. echo "######## Setting up GrUB . . ."
  95. grub --device-map=/dev/null <<EOF
  96. device (hd0) build/moss-disk.bin
  97. geometry (hd0) $((CYLINDERS)) $((HEADS)) $((SECTORS_PER_TRACK))
  98. root (hd0,0)
  99. setup (hd0)
  100. quit
  101. EOF
  102. else
  103. echo "######## NOT setting up GrUB."
  104. fi
  105.  
  106. #Unmount the disk image
  107. sudo losetup -d /dev/loop0
  108.  
  109. echo "######## Preparation for release complete!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement