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
- export CYLINDERS=100
- export HEADS=16
- export SECTORS_PER_TRACK=63
- export SECTOR_SIZE=512
- #Make HDD image
- 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)
- cat <<EOF | fdisk -u -C$((CYLINDERS)) -S$((SECTORS_PER_TRACK)) -H$((HEADS)) build/moss-disk.bin
- o
- n
- p
- a
- 1
- p
- w
- EOF
- #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
- #Mount the disk image's first partition in a loop device
- # Note: normally you now would mount /dev/loop0p1 directly. But, GrUB doesn't like that?
- sudo losetup /dev/loop1 /dev/mapper/loop0p1
- #Make a file system on first partition
- # Note: source also explains how to set up FAT32
- sudo mke2fs /dev/loop1
- #Note: may have to unmount loops, restart, and then remount loops here. See http://forum.osdev.org/viewtopic.php?f=1&t=26907
- #Mount the first partition
- sudo mount /dev/loop1 /mnt
- #Setup a device map, as per S.U. question (link above)
- # Note: IDK why, but I had to create it in /tmp first.
- # Note: I haven't tested this part in the script; I typed it in by hand using CTRL+V/CTRL+I to
- # get the TAB. I based this off of the device map in the host.
- sudo mkdir -p /mnt/boot/grub
- cat > /tmp/device.map <<EOF
- (hd0)\t/dev/loop0
- (hd0,1)\t/dev/loop1
- EOF
- sudo cp /tmp/device.map /mnt/boot/grub/device.map
- #Install grub
- sudo grub-install --root-directory=/mnt /dev/loop0
- #Unmount the disk image from the loop devices
- sudo losetup -d /dev/loop0
- sudo losetup -d /dev/loop1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement