The blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

75 lines
3.1 KiB

  1. ---
  2. title: Building bhyve Images using makefs and mkimg
  3. description: >
  4. this is a test blog post and a sample for things
  5. created: !!timestamp '2014-10-29'
  6. time: 8:57 PM
  7. tags:
  8. - bhyve
  9. - FreeBSD
  10. ---
  11. Recently Neel Natu [committed](https://svnweb.freebsd.org/changeset/base/r273375)
  12. work to enable bhyve to run on AMD processors. My main development
  13. machine is an AMD A10-5700, so the commit enables me to use bhyve for
  14. testing.
  15. EDIT: Anish Gupta did the work that Neel Natu commited. Thanks Anish!
  16. I had previously built images using `makefs` and `mkimg` for a CF card for
  17. use in another machine, so being able to build images to use with bhyve
  18. makes sense.
  19. First, you need to make sure that you have a complete source check out
  20. along with a completed buildworld and buildkernel. Then follow these steps:
  21. 1. Install world and distribution into a temporary directory using the `NO_ROOT` option:
  22. <pre class="fullwidth"><code>
  23. make installworld DESTDIR=<tmpdir> -DDB_FROM_SRC -DNO_ROOT
  24. make distribution DESTDIR=<tmpdir> -DDB_FROM_SRC -DNO_ROOT
  25. </code></pre>
  26. This preps everything with the defaults as necessary.
  27. 2. Install a kernel either into a different directory (I do this) or into the same directory above:
  28. <pre class="fullwidth"><code>
  29. make installkernel DESTDIR=<tmpkerndir> -DNO_ROOT KERNCONF=<conf>
  30. </code></pre>
  31. 3. Make a directory with your custom configuration files. The basics
  32. are `/etc/rc.conf` and `/etc/fstab` and you might want `/firstboot` on
  33. there too. You will also need a `METALOG` file which contains the
  34. permissions for the files. This is just a standard `mtree` file, so
  35. you could use `mtree` to generate this instead of creating it by hand.
  36. The file contents are below.
  37. 4. Build the ufs image using the `makeroot.sh` script in the src tree at `tools/tools/makeroot/makeroot.sh`:
  38. <pre class="fullwidth"><code>
  39. /usr/src/tools/tools/makeroot/makeroot.sh -e <custdir>/METALOG -e <tmpkerndir>/METALOG -p <tmpdir>/etc/master.passwd -s 2g ufs.img root
  40. </code></pre>
  41. 5. Build the disc image:
  42. <pre class="fullwidth"><code>
  43. mkimg -s gpt -b <tmpdir>/boot/pmbr -p freebsd-boot:=<tmpdir>/boot/gptboot -p freebsd-swap::1G -p freebsd-ufs:=ufs.img -o disc.img
  44. </code></pre>
  45. 6. Run the image:
  46. <pre class="fullwidth"><code>
  47. sh /usr/share/examples/bhyve/vmrun.sh -d disc.img vm0
  48. </code></pre>
  49. There you have it. Besides running the image, all the other steps can
  50. be done as a normal user w/o root access.
  51. EDIT: You also might want to include an `/entropy` file (populated with 4k
  52. from `/dev/random`) in your custom directory so that the image has a good
  53. seed for entropy at first boot for things such as sshd key generation.
  54. File contents:
  55. * `/etc/fstab`:
  56. <pre class="fullwidth"><code>
  57. /dev/vtbd0p3 / ufs rw 1 1
  58. </code></pre>
  59. * Custom `METALOG`:
  60. <pre class="fullwidth"><code>
  61. #mtree 2.0
  62. ./etc/rc.conf type=file uname=root gname=wheel mode=0644
  63. ./etc/fstab type=file uname=root gname=wheel mode=0644
  64. ./firstboot type=file uname=root gname=wheel mode=0644
  65. </code></pre>