Creating a hard disk image using the dd utility. Creating a bootable flash drive for installing Windows using the Rufus program Sector-by-sector copying of a linux dd flash drive


    Rufus- free and open source software for formatting removable USB storage media and creating bootable disks with various operating systems. The program is easy to use, high speed and supports a multilingual interface.

You can download the program on the developer's website. The page contains links to download the standard version Rufus, and portable Rufus portable, which do not differ in anything except the name of the executable file and the location where the settings are stored. The program settings include the language used and settings for checking for updates. The standard version stores these settings in the registry, while the portable version stores these settings in a file rufus.ini program directory. Rufus does not require installation on the system - just download the executable file and run it. The program interface is very simple:

Overall, the program Rufus is not something unique in the field of tools for creating bootable media and its main advantage is ease of use. In order to create a bootable flash drive with its help, it is enough to have the original image of the bootable system and be able to click on the “Start” button. All selected parameters and settings, by default, are already designed for using the program to work on a standard computer.

Easiest and most convenient to use Rufus to create a bootable flash drive (bootable USB drive) from ISO images of Windows or Linux installation disks, as well as system emergency recovery disks and diagnostic tools.

When creating a bootable Windows flash drive, you just need to select the device to be written to and the bootable ISO image file. The program will set other parameters itself.

If you do not have an ISO image file, you can create one from a physical CD (or from a set of distribution files) using CD/DVD burning programs such as the well-known Nero, Alcohol, or the free CDBurnerXP or ImgBurn.

The procedure for creating a bootable USB flash drive with Windows is as follows:

  • select the flash drive on which the image will be written. Unlike many similar programs, Rufus displays the volume label, drive letter and size, so if you have several removable drives on the system, it is easy to select the one to write to.

  • select the partition scheme and system interface type. Rufus allows you to create flash drives for booting in a regular BIOS interface and for booting in a UEFI environment, create boot records for MBR volumes and GPT volumes. The default mode is "MBR for computers with BIOS or UEFI" - the most common mode for bootable flash drives today.

  • select the file system that will be used on the bootable flash drive to be created. By default, bootable Windows flash drives use the file system FAT32, but if necessary, you can choose NTFS, if you need to use files larger than 4 GB.

  • set the cluster size. The cluster size is selected by the program based on the image data and file system type, but if necessary, it can be changed.

  • specify the volume label that will be specified for the created flash drive.

  • set formatting options. It's best to leave these options at default and just select the ISO image file. For images created by the program dd on Linux, you need to select the option DD image.

    After pressing the button Start the program will format the flash drive, set the sign of the active partition, record the master boot record and partition boot record, as well as bootable media data from the ISO image. After completion of work Rufus You can boot using the resulting bootable flash drive.

    Using virtualization technology to test bootable flash drives. Links for downloading free and convenient programs to simplify the process of creating, debugging and testing the created bootable media.

    Team dd is designed to use the utility of the same name, designed for low-level copying and conversion of data. Its name stands for “data duplicator” or “data duplicator”. This utility is used mainly for writing images of installation disks of Linux distributions to flash drives and creating images of optical media, however, its range of functions is not limited to the listed operations. For example, dd can be used to simply copy files or change the case of text strings. In general, the utility in question is to some extent unique, because it involves the use of its own format for passing parameters.

    The standard command syntax is as follows:

    $dd if=<имя исходного файла>of=<имя целевого файла>[options]

    It is easy to notice that the recording format is used to pass parameters to the utility <имя параметра>=<значение параметра> . The utility can read source data from standard input and output the resulting data using standard output if parameters are not used if And of, but in the vast majority of cases these parameters are necessary to specify file names with the corresponding data. The utility reads and writes data in blocks, and the block size can be changed using the parameter bs(Blocks of 512 KB are used by default). There are separate parameters for setting the sizes of readable and writable blocks, namely, ibs And obs. The number of blocks read can be limited using the parameter count. The parameter can be used to skip a specified number of blocks in the source file. skip, target file - parameter seek. The parameter can be used to specify read and write flags separated by commas iflag

    • append- activation of the mode of appending data to the target file.
    • direct- data processing mode bypassing the file system cache (increases speed).
    • dsync- data recording mode with synchronization (increases reliability).
    • sync- data and metadata recording mode with synchronization (increases reliability).
    • fullblock- reading only complete blocks.
    • nonblock- activation of non-blocking I/O mode (increases speed).
    • noatime- disabling the mechanism for updating file system element timestamps (increases speed).
    • nofollow- refusal to follow symbolic links.

    Finally, the parameter can be used to specify comma-separated conversion flags conv. The most commonly used flags are:

    • lcase- converting string characters in ASCII encoding to lowercase.
    • ucase- converting string characters in ASCII encoding to upper case.
    • nocreat- display an error message if the target file is missing.
    • excl- display an error message if the target file exists.
    • notrunc- refusal to trim the target file.
    • swab- changing the locations of every two bytes from the source file.
    • noerror- continuation of work even if errors occur.
    • fdatasync- activation of the mode of writing data to the target file before completing the utility.
    • fsync- activation of the mode of writing data and metadata to the target file before completing the utility.

    Examples of using

    Backing up disk drive data

    Let's assume we are using a hard drive represented by a device file /dev/sda, and we need to create a sector-by-sector backup of all the data located on it, saving it in a file in the partition of the removable USB drive represented by the device file /dev/sdb1 and mounted in the directory /mnt/sdb1. These backup files are usually called dumps or disk images. Our disk image file will be named backup.img. This is the command with which you can create it:

    # dd if=/dev/sda of=/mnt/sdb1/backup.img

    In this command, using the parameter if the path to the source file is specified, and using the parameter of- to the target.

    Restoring data from a backup

    To restore data from the created backup copy, you must boot the system from the distribution installation disk and execute the reverse command.

    # dd if=/mnt/sdb1/backup1.img of=/dev/sda

    Warning: executing this command will overwrite the entire contents of the specified hard drive, so you should treat such commands with special attention.

    Hard drive cloning

    Before cloning a hard drive, you must ensure that you have a hard drive that is the same size as the original one. The same operation can be performed in the case of flash drives with a USB interface of similar sizes. Let's assume that the source flash drive is represented by a device file /dev/sdb, and the target - the device file /dev/sdc. In this case, you can clone the source drive using the following command:

    # dd if=/dev/sdb of=/dev/sdc

    Even if the target drive has a larger capacity, you will only have access to the size of the source flash drive stored at the file system level.

    Transferring a disk image file to another computer

    To transfer a disk image file over a network to another computer named target the following command can be used:

    # dd if=/dev/sdb | ssh root@target "(cat >backup.img)"

    Compressing a Disk Image File

    To make the backup disk partition take up less space, you can compress it using a compressor such as bzip2 :

    # dd if=/dev/sdb | bzip2 backup.img.bz2

    Creating an ISO optical disc image

    To create an image of an optical disk CD, DVD or BD, simply read its contents block by block and save this contents in a file:

    # dd if=/dev/sr0 of=image.iso bs=2048

    Saving a file from damaged media or creating an image of such media

    If your favorite movie or music track is no longer readable due to media corruption, you can try to copy it using the utility dd, ignoring bad blocks:

    # dd if=movie.avi of=/home/alex/movie.avi conv=noerror,sync

    You can also create an image file of the damaged media and try to extract files from it:

    # dd if=/dev/sdb of=/home/alex/movie.iso bs=2048 conv=noerror,sync

    Burning an installation disk image to a USB flash drive

    To install a Linux distribution from a USB flash drive, you must burn an ISO installation disk image to the flash drive. A similar command can be used for this purpose:

    # dd if=/home/alex/Fedora-Workstation-Live-x86_64-26_Alpha-1.7.iso of=/dev/sdc

    It is important to remember that even if there are partitions on the flash drive, you should not specify the path to the device file of one of the partitions, but the path to the device file of the drive itself, in our case this is /dev/sdc.

    Hard drive content analysis

    Utility dd is an excellent tool for exploring file systems. To analyze the contents of a hard drive with data output from individual blocks, in our case, a block 1001 on the partition represented by the device file /dev/sdc1, just use the following command:

    # dd if=/dev/sdc1 count=1 skip=1000

    In order to see the first 40 bytes of your hard drive in hexadecimal notation, use the command:

    # dd if=/dev/sda bs=1 count=40 | hexdump -C

    In this case, using the parameter bs sets the disk block size.

    Testing disk drive performance

    To test the performance of a disk drive represented, for example, by a device file /dev/sda When reading blocks of different sizes, a similar command can be used:


    1000000+0 records in
    1000000+0 records out

    # dd if=/dev/sda of=/dev/null bs=4096 count=1000000
    1000000+0 records in
    1000000+0 records out
    4096000000 bytes (4.1 GB) copied, 29.8747 s, 137 MB/s

    Thanks to the file system caching mechanism, you may encounter a mystical speedup of read operations that should not be surprising:

    # dd if=/dev/sda of=/dev/null bs=512 count=1000000
    1000000+0 records in
    1000000+0 records out
    512000000 bytes (512 MB) copied, 4.25186 s, 120 MB/s

    # dd if=/dev/sda of=/dev/null bs=512 count=1000000
    1000000+0 records in
    1000000+0 records out
    512000000 bytes (512 MB) copied, 0.417317 s, 1.2 GB/s

    To obtain correct test results, it is recommended to bypass the file system caching mechanism altogether by using I/O mode without caching:

    # dd if=/dev/sda of=/dev/null bs=512 count=100000 iflag=direct
    100000+0 records in
    100000+0 records out
    51200000 bytes (51 MB) copied, 5.01053 s, 10.2 MB/s

    Copying files

    Yes, utility dd can even be used for regular file copying. Of course, for this purpose it is better to use a utility specially designed for this purpose, namely, cp. In any case, you can copy the file using a similar command:

    $ dd if=/home/alex/test.txt /home/alex/test_copy.txt

    The dd command does just one simple thing: it copies data from a file to another file. But since in Linux many entities are represented precisely as files, dd has many uses. Let's look at the most useful of them.

    What does dd mean?

    dd is short for data duplicator. But because in the wrong hands the dd command can lead to complete loss of all data, the program is often jokingly called disk destroyer. Let's try to figure out how not only not to destroy your data, but even to benefit from using dd.

    General use case for dd

    The command syntax is as follows:

    Dd if=$input_data of=$output_data

    The command will copy the data from the $input_data file to the $output_data file, taking into account the options. It would seem that everything is simple. Now let’s look at what opportunities this simple copying opens up.

    Examples of using dd

    1. Destruction of all data on the disk without the possibility of recovery:

    Dd if=/dev/urandom of=/dev/sda bs=4k

    2. Complete byte-by-byte copying of one disk to another (cloning):

    Dd if=/dev/sda of=/dev/sdb bs=4096

    3. Copying one partition to another:

    Dd if=/dev/sda3 of=/dev/sdb3 bs=4096 conv=notrunc,noerror

    4. Display a list of available file systems:

    Dd if=/proc/filesystems | hexdump -C | less

    5. Copying data on devices with different block sizes (1 KB at the source and 2 KB at the destination):

    Dd if=/dev/st0 ibs=1024 obs=2048 of=/dev/st1

    6. Create a bootable USB flash drive:

    Dd if=/home/$user/bootimage.img of=/dev/sdc

    7. Check the disk for bad sectors:

    Dd if=/dev/sda of=/dev/null bs=1m

    8. Create a backup copy of the MBR disk and save to a floppy disk

    Dd if=/dev/sda of=/dev/fd0 bs=512 count=1

    9. Removing an ISO image from a CD:

    Dd if=/dev/sr0 of=/home/$user/mycdimage.iso bs=2048 conv=nosync

    10. Checking the file for viruses (of course, ClamAV is required):

    Dd if=/home/$user/suspicious.doc | clamscan -

    11. Saving the contents of RAM to a file:

    Dd if=/dev/mem of=/home/$user/mem.bin bs=1024

    12. Converting an image from Nero NRG format to a standard ISO image:

    Dd bs=1k if=imagefile.nrg of=imagefile.iso skip=300k

    13. View MBR contents:

    Dd if=/dev/sda count=1 | hexdump -C

    Where are the promised million applications?

    An observant reader will probably notice that the article does not list a million useful applications, but several fewer. But the power of the dd program lies in the fact that the user can find other applications on his own, combining different files as if, of parameters and selecting the necessary options. Just remember that working with dd requires extra attention. If you do not know exactly what actions will be performed, then it is better to refrain from experiments. Try not to give dd superuser rights when you can do without these rights.

    Your own examples of using this wonderful program are welcome in the comments.

    dd is a simple utility that is included in most Unix-like operating systems - Linux, FreeBSD, Solaris, etc.
    Its purpose is to read data from one device or file and write to another.

    dd can be effectively used to create an image of a hard drive, without using commercial utilities like Acronis True Image or Norton Ghost.

    Let's assume we have two disks:

    • /dev/sda - the disk whose image needs to be created;
    • /dev/sdb - the disk on which the image will be written.

    If necessary, you need to substitute your own values.

    The first step is to boot from any available Live-CD disk that has the dd utility and enter the command line as a superuser. Create a mount point for backup.

    mkdir /mnt/backup

    We mount the hard drive on which you want to save the image.

    Creating a hard drive image

    dd if=/dev/sda of=/mnt/backup/sda.img bs=8M conv=sync,noerror

    • if=/dev/sda - copy the entire hard drive sda;
    • of=/mnt/backup/sda.img - copy to /mnt/backup/sda.img;
    • bs=8M — set the size of the hard drive cache to speed up the copying procedure (otherwise the data will be reset in small portions of 512 bytes);
    • conv=sync,noerror - we indicate to dd the need for bit-for-bit copying and ignoring read errors.

    To reduce the size of a hard disk image, you can compress it with any archiver.

    dd if=/dev/sda bs=8M conv=sync,noerror | gzip -c > /mnt/backup/sda.img

    Recovering a hard drive image

    To restore a hard disk image, you must follow the reverse procedure to the procedure for creating this image.

    dd if=/mnt/backup/sda.img of=/dev/sda bs=8M conv=sync,noerror

    When using compression, you must unzip the image in parallel.

    gunzip -c /mnt/backup/sda.img | dd of=/dev/sda conv=sync,noerror bs=8M

    Migrating the system to another hard drive

    To migrate the entire system to another hard drive, you must set the location of the new drive as the destination.

    dd if=/dev/sda of=/dev/sdb bs=8M conv=sync,noerror

    Then, if necessary, install booting from this hard drive. Provided that the new hard drive is larger than the old one, there will be an unallocated area on it. It should be marked up and formatted according to existing requirements.

    Copy statistics in dd

    The main disadvantage of dd is the lack of a visual representation of the statistics of the copying procedure. However, this disadvantage can be easily circumvented. All you need to do is connect to another terminal.

    Determine the process number under which dd is running.

    Periodically send the command kill -USR1 process_number_dd to this process.

    watch -n 5 kill -USR1 process_number_dd

    • watch -n 5 - execute the command every 5 seconds;
    • kill -USR1 process_number_dd — show copy statistics.

    Cons of using dd to create disk images

    Everything has pros and cons. dd is a free and very flexible tool, but it can only make a full copy of a volume. Special programs can only copy data that is stored on disk.

    Thus, the volume of a disk image created using dd will be equal to the volume of the disk itself - regardless of how much data is on the disk.





  • 

    2024 gtavrl.ru.