Create Image Dd

broken image


This brief tutorial is about how to create your own bootable disk image. For information about partitioning see GPT and FAT.

Create Image Dd Background

Difficulty level

Beginner
  1. Creating a compressed disk image. Because dd creates the exact content of an entire disk, it means that it takes too much size. You can decide to compress the disk image with the command below # dd if=/dev/vda gzip -c /tmp/vdadisk.img.gz. The pipe operator makes the output on the left command become the input on the right command.
  2. Creating a dd Image Using AIR For this exercise, we will create a dd image of a.jpg in the root folder and copy it to a CD-ROM. AIR will run the commands behind the scenes that will create the image and copy it to the CD-ROM. (In a real scenario, this.jpg could very easily represent a compromised hard drive or other piece of evidence).
  3. You can create an empty disk image, add data to it, then use it to create disks, CDs, or DVDs. In the Disk Utility app on your Mac, choose File New Image Blank Image. Enter a filename for the disk image, add tags if necessary, then choose where to save it.
  • 2Required Steps

Sep 11, 2020 Download Freeware. Win 10/8.1/8/7/XP. Secure Download. Select Disk Backup under Backup tab. If you want to create complete system image in Windows 10, then System Backup is what you need. In the pop-up window, choose the disk to be backed up and click Add.

Requirements

you'll need the following:

  • fdisk
  • mkfs.vfat
  • bootloader (see also Rolling Your Own Bootloader and Babystep1 tutorial)
  • your kernel and maybe some other files

Required Steps

Creating an Empty Image

First of all, let's create an empty disk image file, let's say 128 megabytes in size.

Creating the Partitioning Table

As the GPT is more complex thing than MBR partitioning tables, we'll use fdisk, which has an interactive interface. Inputs (that you're supposed to type) are after the ':' colons.

The commands used were:

  • g - create a new GPT partitioning table
  • n p - new primary partition
  • 1 2048 +8M - first partition, starting sector, partition size
  • t 1 - change the type of the first partition
  • 1 - type 1 is EFI System Partition (or ESP in short)
  • w - write out changes

Creating a File System on the First Partition

Now this is not at simple as it seems, because we have to create the file system somewhere in the middle of a file. For that, we'll create a loop device.

Here the arguments are:

  • -o $[2048*512] - tells losetup that our partition is starting at the 2048th sector (one sector is 512 bytes)
  • --sizelimit $[8*1024*1024] - specifies the limit in 8 megabytes
  • -f - tells to find a suitable loopback device
  • and the last parameter is our disk image's filename.

To see which device was used for your image, you can do

which will list all loopback devices.

Now that we have a device which points inside the image file exactly to the partition, we can create a FAT filesystem on it:

Here

  • -F 16 - tells to create a FAT16
  • -n 'EFI System' - sets the label for the partition (don't change, some firmware checks for this)
  • /dev/loop0 - is the loopback device (change to the one you saw in losetup -a output)

Adding Files to the Partition

The next step is to mount our loopback device, so that we can copy files to the partition.

For simplicity, let's call our kernel MSDOS.SYS and out configuration file CONFIG.SYS:

Dd Image File

Some boot loaders are so called two-stage loaders. This means they have two parts: a boot sector and a 2nd stage file. You must copy that 2nd stage to the partition:

Create Image Dd

UEFI will need a special PE executable named EFI/BOOT/BOOT(arch).EFI, which you can create with GNU-EFI:

Once you're finished with the copy, it is important to dismount the partition:

Adding the BIOS Boot Loader

If you're planning to create a hybrid image with the PMBR (that you can also boot on legacy BIOS machines), then you need to add the legacy BIOS boot loader code:

The first command copies the code, and the second one the two magic bytes at the end of the sector. This way the bytes 446 - 510 (where the partitioning table resides) won't be overwritten. It is very important preserve the ESP entry required by UEFI.

Here the arguments mean:

  • if=boot.bin - the name of the boot loader, should be 512 bytes
  • of=diskimage.dd - the disk image
  • conv=notrunc - tells dd to update an existing image file instead of creating a new one
  • bs=446 - block size (sector size is 512 bytes, but we want to write less)
  • skip=510 - skip that many blocks (in second line bs is 1, so skip 510 bytes)
  • count=1 - tells dd to update one sector only
Large

UEFI will need a special PE executable named EFI/BOOT/BOOT(arch).EFI, which you can create with GNU-EFI:

Once you're finished with the copy, it is important to dismount the partition:

Adding the BIOS Boot Loader

If you're planning to create a hybrid image with the PMBR (that you can also boot on legacy BIOS machines), then you need to add the legacy BIOS boot loader code:

The first command copies the code, and the second one the two magic bytes at the end of the sector. This way the bytes 446 - 510 (where the partitioning table resides) won't be overwritten. It is very important preserve the ESP entry required by UEFI.

Here the arguments mean:

  • if=boot.bin - the name of the boot loader, should be 512 bytes
  • of=diskimage.dd - the disk image
  • conv=notrunc - tells dd to update an existing image file instead of creating a new one
  • bs=446 - block size (sector size is 512 bytes, but we want to write less)
  • skip=510 - skip that many blocks (in second line bs is 1, so skip 510 bytes)
  • count=1 - tells dd to update one sector only

See Also

Create Image Dism

Retrieved from 'https://wiki.osdev.org/index.php?title=Bootable_Disk&oldid=25479'




broken image