Advertisement
Geometrian

MOSS Disk Image Shell Script

Jul 14th, 2013
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.84 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. export CYLINDERS=100
  8. export HEADS=16
  9. export SECTORS_PER_TRACK=63
  10. export SECTOR_SIZE=512
  11.  
  12. #Make HDD image
  13. dd if=/dev/zero of=build/moss-disk.bin bs=$((HEADS*SECTORS_PER_TRACK*SECTOR_SIZE)) count=$CYLINDERS
  14.  
  15. #Make partition on disk file (re-enable as necessary)
  16. cat <<EOF | fdisk -u -C$((CYLINDERS)) -S$((SECTORS_PER_TRACK)) -H$((HEADS)) build/moss-disk.bin
  17. o
  18. n
  19. p
  20.  
  21.  
  22.  
  23. a
  24. 1
  25. p
  26. w
  27. EOF
  28.  
  29. #Mount the disk image in a loop device
  30. sudo losetup /dev/loop0 build/moss-disk.bin
  31. #Make the disk image's partitions into devices
  32. sudo kpartx -v -a /dev/loop0
  33. #Mount the disk image's first partition in a loop device
  34. #   Note: normally you now would mount /dev/loop0p1 directly.  But, GrUB doesn't like that?
  35. sudo losetup /dev/loop1 /dev/mapper/loop0p1
  36.  
  37. #Make a file system on first partition
  38. #   Note: source also explains how to set up FAT32
  39. sudo mke2fs /dev/loop1
  40.  
  41. #Note: may have to unmount loops, restart, and then remount loops here.  See http://forum.osdev.org/viewtopic.php?f=1&t=26907
  42.  
  43. #Mount the first partition
  44. sudo mount /dev/loop1 /mnt
  45. #Setup a device map, as per S.U. question (link above)
  46. #   Note: IDK why, but I had to create it in /tmp first.
  47. #   Note: I haven't tested this part in the script; I typed it in by hand using CTRL+V/CTRL+I to
  48. #         get the TAB. I based this off of the device map in the host.
  49. sudo mkdir -p /mnt/boot/grub
  50. cat > /tmp/device.map <<EOF
  51. (hd0)\t/dev/loop0
  52. (hd0,1)\t/dev/loop1
  53.  
  54. EOF
  55. sudo cp /tmp/device.map /mnt/boot/grub/device.map
  56.  
  57. #Install grub
  58. sudo grub-install --root-directory=/mnt /dev/loop0
  59.  
  60. #Unmount the disk image from the loop devices
  61. sudo losetup -d /dev/loop0
  62. sudo losetup -d /dev/loop1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement