wic.rst 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Creating Partitioned Images Using Wic
  3. *************************************
  4. Creating an image for a particular hardware target using the
  5. OpenEmbedded build system does not necessarily mean you can boot that
  6. image as is on your device. Physical devices accept and boot images in
  7. various ways depending on the specifics of the device. Usually,
  8. information about the hardware can tell you what image format the device
  9. requires. Should your device require multiple partitions on an SD card,
  10. flash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to
  11. create the properly partitioned image.
  12. The ``wic`` command generates partitioned images from existing
  13. OpenEmbedded build artifacts. Image generation is driven by partitioning
  14. commands contained in an OpenEmbedded kickstart file (``.wks``)
  15. specified either directly on the command line or as one of a selection
  16. of canned kickstart files as shown with the ``wic list images`` command
  17. in the
  18. ":ref:`dev-manual/wic:generate an image using an existing kickstart file`"
  19. section. When you apply the command to a given set of build artifacts, the
  20. result is an image or set of images that can be directly written onto media and
  21. used on a particular system.
  22. .. note::
  23. For a kickstart file reference, see the
  24. ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`"
  25. Chapter in the Yocto Project Reference Manual.
  26. The ``wic`` command and the infrastructure it is based on is by
  27. definition incomplete. The purpose of the command is to allow the
  28. generation of customized images, and as such, was designed to be
  29. completely extensible through a plugin interface. See the
  30. ":ref:`dev-manual/wic:using the wic plugin interface`" section
  31. for information on these plugins.
  32. This section provides some background information on Wic, describes what
  33. you need to have in place to run the tool, provides instruction on how
  34. to use the Wic utility, provides information on using the Wic plugins
  35. interface, and provides several examples that show how to use Wic.
  36. Background
  37. ==========
  38. This section provides some background on the Wic utility. While none of
  39. this information is required to use Wic, you might find it interesting.
  40. - The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The
  41. "oe" diphthong in "oeic" was promoted to the letter "w", because
  42. "oeic" is both difficult to remember and to pronounce.
  43. - Wic is loosely based on the Meego Image Creator (``mic``) framework.
  44. The Wic implementation has been heavily modified to make direct use
  45. of OpenEmbedded build artifacts instead of package installation and
  46. configuration, which are already incorporated within the OpenEmbedded
  47. artifacts.
  48. - Wic is a completely independent standalone utility that initially
  49. provides easier-to-use and more flexible replacements for an existing
  50. functionality in OE-Core's
  51. :ref:`image-live <ref-classes-image-live>`
  52. class. The difference between Wic and those examples is that with Wic
  53. the functionality of those scripts is implemented by a
  54. general-purpose partitioning language, which is based on Redhat
  55. kickstart syntax.
  56. Requirements
  57. ============
  58. In order to use the Wic utility with the OpenEmbedded Build system, your
  59. system needs to meet the following requirements:
  60. - The Linux distribution on your development host must support the
  61. Yocto Project. See the ":ref:`detailed-supported-distros`"
  62. section in the Yocto Project Reference Manual for the list of
  63. distributions that support the Yocto Project.
  64. - The standard system utilities, such as ``cp``, must be installed on
  65. your development host system.
  66. - You must have sourced the build environment setup script (i.e.
  67. :ref:`structure-core-script`) found in the :term:`Build Directory`.
  68. - You need to have the build artifacts already available, which
  69. typically means that you must have already created an image using the
  70. OpenEmbedded build system (e.g. ``core-image-minimal``). While it
  71. might seem redundant to generate an image in order to create an image
  72. using Wic, the current version of Wic requires the artifacts in the
  73. form generated by the OpenEmbedded build system.
  74. - You must build several native tools, which are built to run on the
  75. build system::
  76. $ bitbake parted-native dosfstools-native mtools-native
  77. - Include "wic" as part of the
  78. :term:`IMAGE_FSTYPES`
  79. variable.
  80. - Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>`
  81. as part of the :term:`WKS_FILE` variable. If multiple candidate files can
  82. be provided by different layers, specify all the possible names through the
  83. :term:`WKS_FILES` variable instead.
  84. Getting Help
  85. ============
  86. You can get general help for the ``wic`` command by entering the ``wic``
  87. command by itself or by entering the command with a help argument as
  88. follows::
  89. $ wic -h
  90. $ wic --help
  91. $ wic help
  92. Currently, Wic supports seven commands: ``cp``, ``create``, ``help``,
  93. ``list``, ``ls``, ``rm``, and ``write``. You can get help for all these
  94. commands except "help" by using the following form::
  95. $ wic help command
  96. For example, the following command returns help for the ``write``
  97. command::
  98. $ wic help write
  99. Wic supports help for three topics: ``overview``, ``plugins``, and
  100. ``kickstart``. You can get help for any topic using the following form::
  101. $ wic help topic
  102. For example, the following returns overview help for Wic::
  103. $ wic help overview
  104. There is one additional level of help for Wic. You can get help on
  105. individual images through the ``list`` command. You can use the ``list``
  106. command to return the available Wic images as follows::
  107. $ wic list images
  108. genericx86 Create an EFI disk image for genericx86*
  109. edgerouter Create SD card image for Edgerouter
  110. beaglebone-yocto Create SD card image for Beaglebone
  111. qemux86-directdisk Create a qemu machine 'pcbios' direct disk image
  112. systemd-bootdisk Create an EFI disk image with systemd-boot
  113. mkhybridiso Create a hybrid ISO image
  114. mkefidisk Create an EFI disk image
  115. sdimage-bootpart Create SD card image with a boot partition
  116. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  117. directdisk Create a 'pcbios' direct disk image
  118. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  119. qemuriscv Create qcow2 image for RISC-V QEMU machines
  120. directdisk-gpt Create a 'pcbios' direct disk image
  121. efi-bootdisk
  122. Once you know the list of available
  123. Wic images, you can use ``help`` with the command to get help on a
  124. particular image. For example, the following command returns help on the
  125. "beaglebone-yocto" image::
  126. $ wic list beaglebone-yocto help
  127. Creates a partitioned SD card image for Beaglebone.
  128. Boot files are located in the first vfat partition.
  129. Operational Modes
  130. =================
  131. You can use Wic in two different modes, depending on how much control
  132. you need for specifying the OpenEmbedded build artifacts that are used
  133. for creating the image: Raw and Cooked:
  134. - *Raw Mode:* You explicitly specify build artifacts through Wic
  135. command-line arguments.
  136. - *Cooked Mode:* The current
  137. :term:`MACHINE` setting and image
  138. name are used to automatically locate and provide the build
  139. artifacts. You just supply a kickstart file and the name of the image
  140. from which to use artifacts.
  141. Regardless of the mode you use, you need to have the build artifacts
  142. ready and available.
  143. Raw Mode
  144. --------
  145. Running Wic in raw mode allows you to specify all the partitions through
  146. the ``wic`` command line. The primary use for raw mode is if you have
  147. built your kernel outside of the Yocto Project :term:`Build Directory`.
  148. In other words, you can point to arbitrary kernel, root filesystem locations,
  149. and so forth. Contrast this behavior with cooked mode where Wic looks in the
  150. :term:`Build Directory` (e.g. ``tmp/deploy/images/``\ machine).
  151. The general form of the ``wic`` command in raw mode is::
  152. $ wic create wks_file options ...
  153. Where:
  154. wks_file:
  155. An OpenEmbedded kickstart file. You can provide
  156. your own custom file or use a file from a set of
  157. existing files as described by further options.
  158. optional arguments:
  159. -h, --help show this help message and exit
  160. -o OUTDIR, --outdir OUTDIR
  161. name of directory to create image in
  162. -e IMAGE_NAME, --image-name IMAGE_NAME
  163. name of the image to use the artifacts from e.g. core-
  164. image-sato
  165. -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR
  166. path to the /rootfs dir to use as the .wks rootfs
  167. source
  168. -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR
  169. path to the dir containing the boot artifacts (e.g.
  170. /EFI or /syslinux dirs) to use as the .wks bootimg
  171. source
  172. -k KERNEL_DIR, --kernel-dir KERNEL_DIR
  173. path to the dir containing the kernel to use in the
  174. .wks bootimg
  175. -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT
  176. path to the native sysroot containing the tools to use
  177. to build the image
  178. -s, --skip-build-check
  179. skip the build check
  180. -f, --build-rootfs build rootfs
  181. -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz}
  182. compress image with specified compressor
  183. -m, --bmap generate .bmap
  184. --no-fstab-update Do not change fstab file.
  185. -v VARS_DIR, --vars VARS_DIR
  186. directory with <image>.env files that store bitbake
  187. variables
  188. -D, --debug output debug information
  189. .. note::
  190. You do not need root privileges to run Wic. In fact, you should not
  191. run as root when using the utility.
  192. Cooked Mode
  193. -----------
  194. Running Wic in cooked mode leverages off artifacts in the
  195. :term:`Build Directory`. In other words, you do not have to specify kernel or
  196. root filesystem locations as part of the command. All you need to provide is
  197. a kickstart file and the name of the image from which to use artifacts
  198. by using the "-e" option. Wic looks in the :term:`Build Directory` (e.g.
  199. ``tmp/deploy/images/``\ machine) for artifacts.
  200. The general form of the ``wic`` command using Cooked Mode is as follows::
  201. $ wic create wks_file -e IMAGE_NAME
  202. Where:
  203. wks_file:
  204. An OpenEmbedded kickstart file. You can provide
  205. your own custom file or use a file from a set of
  206. existing files provided with the Yocto Project
  207. release.
  208. required argument:
  209. -e IMAGE_NAME, --image-name IMAGE_NAME
  210. name of the image to use the artifacts from e.g. core-
  211. image-sato
  212. Using an Existing Kickstart File
  213. ================================
  214. If you do not want to create your own kickstart file, you can use an
  215. existing file provided by the Wic installation. As shipped, kickstart
  216. files can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the
  217. following two locations::
  218. poky/meta-yocto-bsp/wic
  219. poky/scripts/lib/wic/canned-wks
  220. Use the following command to list the available kickstart files::
  221. $ wic list images
  222. genericx86 Create an EFI disk image for genericx86*
  223. beaglebone-yocto Create SD card image for Beaglebone
  224. edgerouter Create SD card image for Edgerouter
  225. qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image
  226. directdisk-gpt Create a 'pcbios' direct disk image
  227. mkefidisk Create an EFI disk image
  228. directdisk Create a 'pcbios' direct disk image
  229. systemd-bootdisk Create an EFI disk image with systemd-boot
  230. mkhybridiso Create a hybrid ISO image
  231. sdimage-bootpart Create SD card image with a boot partition
  232. directdisk-multi-rootfs Create multi rootfs image using rootfs plugin
  233. directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config
  234. When you use an existing file, you
  235. do not have to use the ``.wks`` extension. Here is an example in Raw
  236. Mode that uses the ``directdisk`` file::
  237. $ wic create directdisk -r rootfs_dir -b bootimg_dir \
  238. -k kernel_dir -n native_sysroot
  239. Here are the actual partition language commands used in the
  240. ``genericx86.wks`` file to generate an image::
  241. # short-description: Create an EFI disk image for genericx86*
  242. # long-description: Creates a partitioned EFI disk image for genericx86* machines
  243. part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
  244. part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
  245. part swap --ondisk sda --size 44 --label swap1 --fstype=swap
  246. bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0"
  247. Using the Wic Plugin Interface
  248. ==============================
  249. You can extend and specialize Wic functionality by using Wic plugins.
  250. This section explains the Wic plugin interface.
  251. .. note::
  252. Wic plugins consist of "source" and "imager" plugins. Imager plugins
  253. are beyond the scope of this section.
  254. Source plugins provide a mechanism to customize partition content during
  255. the Wic image generation process. You can use source plugins to map
  256. values that you specify using ``--source`` commands in kickstart files
  257. (i.e. ``*.wks``) to a plugin implementation used to populate a given
  258. partition.
  259. .. note::
  260. If you use plugins that have build-time dependencies (e.g. native
  261. tools, bootloaders, and so forth) when building a Wic image, you need
  262. to specify those dependencies using the :term:`WKS_FILE_DEPENDS`
  263. variable.
  264. Source plugins are subclasses defined in plugin files. As shipped, the
  265. Yocto Project provides several plugin files. You can see the source
  266. plugin files that ship with the Yocto Project
  267. :yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`.
  268. Each of these plugin files contains source plugins that are designed to
  269. populate a specific Wic image partition.
  270. Source plugins are subclasses of the ``SourcePlugin`` class, which is
  271. defined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example,
  272. the ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py``
  273. file is a subclass of the ``SourcePlugin`` class, which is found in the
  274. ``pluginbase.py`` file.
  275. You can also implement source plugins in a layer outside of the Source
  276. Repositories (external layer). To do so, be sure that your plugin files
  277. are located in a directory whose path is
  278. ``scripts/lib/wic/plugins/source/`` within your external layer. When the
  279. plugin files are located there, the source plugins they contain are made
  280. available to Wic.
  281. When the Wic implementation needs to invoke a partition-specific
  282. implementation, it looks for the plugin with the same name as the
  283. ``--source`` parameter used in the kickstart file given to that
  284. partition. For example, if the partition is set up using the following
  285. command in a kickstart file::
  286. part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
  287. The methods defined as class
  288. members of the matching source plugin (i.e. ``bootimg-pcbios``) in the
  289. ``bootimg-pcbios.py`` plugin file are used.
  290. To be more concrete, here is the corresponding plugin definition from
  291. the ``bootimg-pcbios.py`` file for the previous command along with an
  292. example method called by the Wic implementation when it needs to prepare
  293. a partition using an implementation-specific function::
  294. .
  295. .
  296. .
  297. class BootimgPcbiosPlugin(SourcePlugin):
  298. """
  299. Create MBR boot partition and install syslinux on it.
  300. """
  301. name = 'bootimg-pcbios'
  302. .
  303. .
  304. .
  305. @classmethod
  306. def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
  307. oe_builddir, bootimg_dir, kernel_dir,
  308. rootfs_dir, native_sysroot):
  309. """
  310. Called to do the actual content population for a partition i.e. it
  311. 'prepares' the partition to be incorporated into the image.
  312. In this case, prepare content for legacy bios boot partition.
  313. """
  314. .
  315. .
  316. .
  317. If a
  318. subclass (plugin) itself does not implement a particular function, Wic
  319. locates and uses the default version in the superclass. It is for this
  320. reason that all source plugins are derived from the ``SourcePlugin``
  321. class.
  322. The ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines
  323. a set of methods that source plugins can implement or override. Any
  324. plugins (subclass of ``SourcePlugin``) that do not implement a
  325. particular method inherit the implementation of the method from the
  326. ``SourcePlugin`` class. For more information, see the ``SourcePlugin``
  327. class in the ``pluginbase.py`` file for details:
  328. The following list describes the methods implemented in the
  329. ``SourcePlugin`` class:
  330. - ``do_prepare_partition()``: Called to populate a partition with
  331. actual content. In other words, the method prepares the final
  332. partition image that is incorporated into the disk image.
  333. - ``do_configure_partition()``: Called before
  334. ``do_prepare_partition()`` to create custom configuration files for a
  335. partition (e.g. syslinux or grub configuration files).
  336. - ``do_install_disk()``: Called after all partitions have been
  337. prepared and assembled into a disk image. This method provides a hook
  338. to allow finalization of a disk image (e.g. writing an MBR).
  339. - ``do_stage_partition()``: Special content-staging hook called
  340. before ``do_prepare_partition()``. This method is normally empty.
  341. Typically, a partition just uses the passed-in parameters (e.g. the
  342. unmodified value of ``bootimg_dir``). However, in some cases, things
  343. might need to be more tailored. As an example, certain files might
  344. additionally need to be taken from ``bootimg_dir + /boot``. This hook
  345. allows those files to be staged in a customized fashion.
  346. .. note::
  347. ``get_bitbake_var()`` allows you to access non-standard variables that
  348. you might want to use for this behavior.
  349. You can extend the source plugin mechanism. To add more hooks, create
  350. more source plugin methods within ``SourcePlugin`` and the corresponding
  351. derived subclasses. The code that calls the plugin methods uses the
  352. ``plugin.get_source_plugin_methods()`` function to find the method or
  353. methods needed by the call. Retrieval of those methods is accomplished
  354. by filling up a dict with keys that contain the method names of
  355. interest. On success, these will be filled in with the actual methods.
  356. See the Wic implementation for examples and details.
  357. Wic Examples
  358. ============
  359. This section provides several examples that show how to use the Wic
  360. utility. All the examples assume the list of requirements in the
  361. ":ref:`dev-manual/wic:requirements`" section have been met. The
  362. examples assume the previously generated image is
  363. ``core-image-minimal``.
  364. Generate an Image using an Existing Kickstart File
  365. --------------------------------------------------
  366. This example runs in Cooked Mode and uses the ``mkefidisk`` kickstart
  367. file::
  368. $ wic create mkefidisk -e core-image-minimal
  369. INFO: Building wic-tools...
  370. .
  371. .
  372. .
  373. INFO: The new image(s) can be found here:
  374. ./mkefidisk-201804191017-sda.direct
  375. The following build artifacts were used to create the image(s):
  376. ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  377. BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  378. KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
  379. NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  380. INFO: The image(s) were created using OE kickstart file:
  381. /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks
  382. The previous example shows the easiest way to create an image by running
  383. in cooked mode and supplying a kickstart file and the "-e" option to
  384. point to the existing build artifacts. Your ``local.conf`` file needs to
  385. have the :term:`MACHINE` variable set
  386. to the machine you are using, which is "qemux86" in this example.
  387. Once the image builds, the output provides image location, artifact use,
  388. and kickstart file information.
  389. .. note::
  390. You should always verify the details provided in the output to make
  391. sure that the image was indeed created exactly as expected.
  392. Continuing with the example, you can now write the image from the
  393. :term:`Build Directory` onto a USB stick, or whatever media for which you
  394. built your image, and boot from the media. You can write the image by using
  395. ``bmaptool`` or ``dd``::
  396. $ oe-run-native bmap-tools-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX
  397. or ::
  398. $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX
  399. .. note::
  400. For more information on how to use the ``bmaptool``
  401. to flash a device with an image, see the
  402. ":ref:`dev-manual/bmaptool:flashing images using \`\`bmaptool\`\``"
  403. section.
  404. Using a Modified Kickstart File
  405. -------------------------------
  406. Because partitioned image creation is driven by the kickstart file, it
  407. is easy to affect image creation by changing the parameters in the file.
  408. This next example demonstrates that through modification of the
  409. ``directdisk-gpt`` kickstart file.
  410. As mentioned earlier, you can use the command ``wic list images`` to
  411. show the list of existing kickstart files. The directory in which the
  412. ``directdisk-gpt.wks`` file resides is
  413. ``scripts/lib/image/canned-wks/``, which is located in the
  414. :term:`Source Directory` (e.g. ``poky``).
  415. Because available files reside in this directory, you can create and add
  416. your own custom files to the directory. Subsequent use of the
  417. ``wic list images`` command would then include your kickstart files.
  418. In this example, the existing ``directdisk-gpt`` file already does most
  419. of what is needed. However, for the hardware in this example, the image
  420. will need to boot from ``sdb`` instead of ``sda``, which is what the
  421. ``directdisk-gpt`` kickstart file uses.
  422. The example begins by making a copy of the ``directdisk-gpt.wks`` file
  423. in the ``scripts/lib/image/canned-wks`` directory and then by changing
  424. the lines that specify the target disk from which to boot.
  425. ::
  426. $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \
  427. /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  428. Next, the example modifies the ``directdisksdb-gpt.wks`` file and
  429. changes all instances of "``--ondisk sda``" to "``--ondisk sdb``". The
  430. example changes the following two lines and leaves the remaining lines
  431. untouched::
  432. part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024
  433. part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid
  434. Once the lines are changed, the
  435. example generates the ``directdisksdb-gpt`` image. The command points
  436. the process at the ``core-image-minimal`` artifacts for the Next Unit of
  437. Computing (nuc) :term:`MACHINE` the
  438. ``local.conf``.
  439. ::
  440. $ wic create directdisksdb-gpt -e core-image-minimal
  441. INFO: Building wic-tools...
  442. .
  443. .
  444. .
  445. Initialising tasks: 100% |#######################################| Time: 0:00:01
  446. NOTE: Executing SetScene Tasks
  447. NOTE: Executing RunQueue Tasks
  448. NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded.
  449. INFO: Creating image(s)...
  450. INFO: The new image(s) can be found here:
  451. ./directdisksdb-gpt-201710090938-sdb.direct
  452. The following build artifacts were used to create the image(s):
  453. ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  454. BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  455. KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
  456. NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  457. INFO: The image(s) were created using OE kickstart file:
  458. /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks
  459. Continuing with the example, you can now directly ``dd`` the image to a
  460. USB stick, or whatever media for which you built your image, and boot
  461. the resulting media::
  462. $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb
  463. 140966+0 records in
  464. 140966+0 records out
  465. 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s
  466. $ sudo eject /dev/sdb
  467. Using a Modified Kickstart File and Running in Raw Mode
  468. -------------------------------------------------------
  469. This next example manually specifies each build artifact (runs in Raw
  470. Mode) and uses a modified kickstart file. The example also uses the
  471. ``-o`` option to cause Wic to create the output somewhere other than the
  472. default output directory, which is the current directory::
  473. $ wic create test.wks -o /home/stephano/testwic \
  474. --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \
  475. --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \
  476. --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \
  477. --native-sysroot /home/stephano/yocto/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native
  478. INFO: Creating image(s)...
  479. INFO: The new image(s) can be found here:
  480. /home/stephano/testwic/test-201710091445-sdb.direct
  481. The following build artifacts were used to create the image(s):
  482. ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs
  483. BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
  484. KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86
  485. NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native
  486. INFO: The image(s) were created using OE kickstart file:
  487. test.wks
  488. For this example,
  489. :term:`MACHINE` did not have to be
  490. specified in the ``local.conf`` file since the artifact is manually
  491. specified.
  492. Using Wic to Manipulate an Image
  493. --------------------------------
  494. Wic image manipulation allows you to shorten turnaround time during
  495. image development. For example, you can use Wic to delete the kernel
  496. partition of a Wic image and then insert a newly built kernel. This
  497. saves you time from having to rebuild the entire image each time you
  498. modify the kernel.
  499. .. note::
  500. In order to use Wic to manipulate a Wic image as in this example,
  501. your development machine must have the ``mtools`` package installed.
  502. The following example examines the contents of the Wic image, deletes
  503. the existing kernel, and then inserts a new kernel:
  504. 1. *List the Partitions:* Use the ``wic ls`` command to list all the
  505. partitions in the Wic image::
  506. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic
  507. Num Start End Size Fstype
  508. 1 1048576 25041919 23993344 fat16
  509. 2 25165824 72157183 46991360 ext4
  510. The previous output shows two partitions in the
  511. ``core-image-minimal-qemux86.wic`` image.
  512. 2. *Examine a Particular Partition:* Use the ``wic ls`` command again
  513. but in a different form to examine a particular partition.
  514. .. note::
  515. You can get command usage on any Wic command using the following
  516. form::
  517. $ wic help command
  518. For example, the following command shows you the various ways to
  519. use the
  520. wic ls
  521. command::
  522. $ wic help ls
  523. The following command shows what is in partition one::
  524. $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1
  525. Volume in drive : is boot
  526. Volume Serial Number is E894-1809
  527. Directory for ::/
  528. libcom32 c32 186500 2017-10-09 16:06
  529. libutil c32 24148 2017-10-09 16:06
  530. syslinux cfg 220 2017-10-09 16:06
  531. vesamenu c32 27104 2017-10-09 16:06
  532. vmlinuz 6904608 2017-10-09 16:06
  533. 5 files 7 142 580 bytes
  534. 16 582 656 bytes free
  535. The previous output shows five files, with the
  536. ``vmlinuz`` being the kernel.
  537. .. note::
  538. If you see the following error, you need to update or create a
  539. ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1"
  540. in the file. Then, run the Wic command again::
  541. ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0
  542. output: Total number of sectors (47824) not a multiple of sectors per track (32)!
  543. Add mtools_skip_check=1 to your .mtoolsrc file to skip this test
  544. 3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the
  545. ``vmlinuz`` file (kernel)::
  546. $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  547. 4. *Add In the New Kernel:* Use the ``wic cp`` command to add the
  548. updated kernel to the Wic image. Depending on how you built your
  549. kernel, it could be in different places. If you used ``devtool`` and
  550. an SDK to build your kernel, it resides in the ``tmp/work`` directory
  551. of the extensible SDK. If you used ``make`` to build the kernel, the
  552. kernel will be in the ``workspace/sources`` area.
  553. The following example assumes ``devtool`` was used to build the
  554. kernel::
  555. $ wic cp poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \
  556. poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz
  557. Once the new kernel is added back into the image, you can use the
  558. ``dd`` command or :ref:`bmaptool
  559. <dev-manual/bmaptool:flashing images using \`\`bmaptool\`\`>`
  560. to flash your wic image onto an SD card or USB stick and test your
  561. target.
  562. .. note::
  563. Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``.