Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Sets up a common disk image that is used for building the VM disk or
- #installing to USB
- #See: http://wiki.osdev.org/Loopback_Device
- #See: http://superuser.com/questions/130955/how-to-install-grub-into-an-img-file
- echo "######## MOSS beginning setup for release . . ."
- export remake_disk=0
- export remake_fs=0
- export remake_grub=0
- #Note: on changing these, change also the Bochs configuration files.
- export CYLINDERS=100
- export HEADS=16
- export SECTORS_PER_TRACK=63
- export SECTOR_SIZE=512
- if [ $remake_disk -eq 1 ]
- then
- #Make HDD image
- echo "######## Making HDD file . . ."
- dd if=/dev/zero of=build/moss-disk.bin bs=$((HEADS*SECTORS_PER_TRACK*SECTOR_SIZE)) count=$CYLINDERS
- #Make partition on disk file (re-enable as necessary)
- echo "######## Making partition thereon . . ."
- cat <<EOF | fdisk -u -C$((CYLINDERS)) -S$((SECTORS_PER_TRACK)) -H$((HEADS)) build/moss-disk.bin
- o
- n
- p
- a
- 1
- p
- w
- EOF
- fi
- echo "######## Filling disk . . ."
- #This next section actually puts a file system and GrUB on the disk. It took a lot of work to get to work
- #since GrUB apparently wasn't intended (or at least tested sufficiently) to do this. A lot is based on
- #http://www.slideshare.net/sukhdotin/installing-grub-on-virtual-hard-disk-images-5094625, but I found
- #http://www.omninerd.com/articles/Installing_GRUB_on_a_Hard_Disk_Image_File, which should be just about
- #the same.
- #Also, this section puts the kernel and all of the needed files on the disk.
- #Mount the disk image in a loop device
- sudo losetup /dev/loop0 build/moss-disk.bin
- #Make the disk image's partitions into devices
- sudo kpartx -v -a /dev/loop0
- #Make a file system on first partition
- # Note: source also explains how to set up FAT32
- if [ $remake_fs -eq 1 ]
- then
- echo "######## Making a filesystem . . ."
- sudo mke2fs /dev/mapper/loop0p1
- #Note: may have to unmount loops, restart, and then remount loops here. See http://forum.osdev.org/viewtopic.php?f=1&t=26907
- else
- echo "######## NOT making a filesystem."
- fi
- #Mount the first partition
- sudo mount -t ext2 /dev/mapper/loop0p1 /mnt
- #Set up first partition's /boot directory
- echo "######## Copying over GrUB files . . ."
- sudo mkdir -p /mnt/boot/grub
- #I tried. I really did, to use grub-install. It just kept failing:
- # http://forum.osdev.org/viewtopic.php?f=1&t=26907
- # http://ebroder.net/2009/08/04/installing-grub-onto-a-disk-image/
- # http://superuser.com/questions/619571/installing-grub-legacy-on-virtual-disk
- #At the suggestion of http://www.slideshare.net/sukhdotin/installing-grub-on-virtual-hard-disk-images-5094625,
- #just copy the needed files over.
- sudo cp source/grub/stage1 /mnt/boot/grub/stage1
- sudo cp source/grub/stage2 /mnt/boot/grub/stage2
- sudo cp source/grub/e2fs_stage1_5 /mnt/boot/grub/e2fs_stage1_5
- #Copy the kernel over and the facility to boot it
- echo "######## Copying over kernel files . . ."
- sudo cp build/MOSS.bin /mnt/boot/MOSS.bin
- sudo cp source/grub/menu.lst /mnt/boot/grub/menu.lst
- #Unmount the first partition
- sudo umount /dev/mapper/loop0p1
- #Unmake the first partition as a device
- sudo kpartx -d /dev/loop0
- #Setup GrUB device map. I've done this before, but never passing /dev/null in . . .
- if [ $remake_grub -eq 1 ]
- then
- echo "######## Setting up GrUB . . ."
- grub --device-map=/dev/null <<EOF
- device (hd0) build/moss-disk.bin
- geometry (hd0) $((CYLINDERS)) $((HEADS)) $((SECTORS_PER_TRACK))
- root (hd0,0)
- setup (hd0)
- quit
- EOF
- else
- echo "######## NOT setting up GrUB."
- fi
- #Unmount the disk image
- sudo losetup -d /dev/loop0
- echo "######## Preparation for release complete!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement