Discussion

How to create a bootable img file

1 3921
Post Last Edited by popboy126 at 2014-5-9 01:50

Post Last Edited by popboy126 at 2014-5-9 01:43

There are two ways to create a bootable img file.
1. Simply using dd command create img file from sd card.
  1. sudo dd if=/dev/sdx of=your_img_file_path bs=xxx
Copy the Code
you can get the device node by using
  1. sudo fdisk -l
Copy the Code
DeepinScreenshot20140509141549.png
in the screenshot, the device node is sdb, so the command sdx should be replaced by sdb.
bs is the optional parameter which can speed up the coping velocity. but bs should be integral multiple of 512 bytes.

2. Using series of command to specify a image.
     A. using dd command to create a image of defined size.
  1. dd if=/dev/zero of=/tmp/xxx.img bs=1M count=4000
Copy the Code
/tmp/xxx.img is the path of image file you want to create
          bs=1M and count =4000 specify the size of the image. you can refer to the help of dd to find more infomation about these two parameters.
 B. using losetup command to load the image.
  1. sudo losetup /dev/loop0 /tmp/xxx.img
Copy the Code
C. using fdisk to create partitions
  1. sudo fdisk /dev/loop0
Copy the Code
Follow the picture to create the first partition.
3.png
        and the second partition can be created by following the same steps.
  Then hit “w” to save the partition information and exit.
4.png
  D. using kpartx command to load the partition information.
  1. sudo kpartx -av /dev/loop0
Copy the Code
We can see the partition information after we input this command
5.png
  E. Format the partitions.
  1. sudo mkfs -t XXX /dev/mapper/loop0pX
Copy the Code
6.png
  F. dd uboot
  1. sudo dd if=uboot-with-spl.bin of=/dev/loop0 bs=1024 seek=8
Copy the Code
7.png
  G. Mount partitions and copy files
  1. sudo mount /dev/mapper/loop0pX /mnt
  2.   sudo cp -av XXX /mnt
Copy the Code
H. After copy the files you need, then umount the image.
  1. sudo kpartx -d /dev/loop0
  2.   sudo losetup -d /dev/loop0
Copy the Code
I. The bootable image is done!
It is very useful!

You have to log in before you can reply Login | Sign Up

Points Rules