dd tool (data duplicator) Linux DD Command - 15 Examples with All Options ( https://linoxide.com/linux-dd-command-create-1gb-file/ ) 1. Backing up and restoring an entire disk or a partition a. Backup entire disk to disk # dd if=/dev/sda of=/dev/sdb bs=4096 conv=noerror,sync b. Creating dd disk image (file image) # dd if=/dev/sda of=/tmp/sdadisk.img c. Creating a compressed disk image # dd if=/dev/vda | gzip -c >/tmp/vdadisk.img.gz The -c option writes output on standard output and keeps original files unchanged. d. Backup a partition or clone one partition to another # dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=noerror,sync 2. Creating virtual filesystem/Backup images of CD or DVDs as iso files a. Creating a virtual filesystem # dd if=/dev/zero of=/file bs=1024K count=500 b. Modify the first 512 bytes of a file with null data If during the operation you indicate an existing output file, you will lose its data. For some reasons, you can need to replace a block size of the output file. dd if=/dev/zero of=file1 bs=512 count=1 conv=notrunc The notrunc option refers to do not truncate the file, only replace the first 512 bytes, if it exists. Otherwise, you will get a 512 byte file c. Creating a backup iso image of CD or DVD # dd if=/dev/cdrom of=/mycd.iso # mount -o loop /mycd.iso /mnt/cd d) Create a bootable USB Drive # dd if=~/Downloads/CentOS-8-x86_64-1905-dvd1.iso of=/dev/sdb bs=1M 3. Backing up and restoring MBR a. Backing up MBR Because the MBR makes up the first 512 bytes of the disk, we just need to copy that block size # dd if=/dev/sda of=/tmp/sdambr.img bs=512 count=1 With the count=1 and bs=512, only 512 bytes will be copied which correspond to the size of our MBR. You can display the saved MBR with the od command which dump files in octal and other formats as below # od -xa /tmp/sdambr.img 0000000 bf52 81f4 8b66 832d 087d 0f00 e284 8000 R ? t soh f vt - etx } bs nul si eot b nul nul 0000020 ff7c 7400 6646 1d8b 8b66 044d 3166 b0c0 | del nul t F f vt gs f vt M eot f 1 @ 0 -a option selects named characters and -x selects hexadecimal 2-byte units b. Backing up the boot data of MBR excluding the partition table # dd if=/dev/sda of=/tmp/sdambr2.img bs=446 count=1 c. Restoring MBR from MBR image You can restore your MBR as shown on the previous commands with # dd if=/tmp/sdambr.img of=/dev/sda 3. Converting data formats If an input file uses a character set that is not the native character set of the host computer, the import operator must perform a conversion. For example, if ASCII is the native format for strings on your host computer, but the input data file represents strings using EBCDIC, you must convert EBCDIC to ASCII and vice versa. a. Convert the data format of a file from EBCDIC to ASCII 3. Converting data formats If an input file uses a character set that is not the native character set of the host computer, the import operator must perform a conversion. For example, if ASCII is the native format for strings on your host computer, but the input data file represents strings using EBCDIC, you must convert EBCDIC to ASCII and vice versa. a. Convert the data format of a file from EBCDIC to ASCII If there’s an ebcdic file with you, mostly retrieved from mainframe systems, then, you would like to convert them to ASCII for making modifications using text editors on UNIX servers # dd if=textfile.ebcdic of=textfile.ascii conv=ascii