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.
 
 
 
 

76 lines
3.2 KiB

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