If one wants to replace offset 0x123AB of a file with the FF C0 14 hexadecimal sequence, this can be done with the command line: # printf '\xff\xc0\x14' | dd seek=$((0x123AB)) conv=notrunc bs=1 of= /path/to/file Backup and restore MBRīefore making changes to a disk, you may want to backup the partition table and partition scheme of the drive. # cat /path/to/* | gunzip -c | dd of=/dev/sda When the image has been split, use the following instead: You can also try other compression algorithms such as zstd. For large disks, this can potentially save hours. In order to leverage multicore compression and create a disk image more quickly, one could for instance install the pigz package, and simply replace the gzip -c command above with pigz -c. Tip: gzip is only able to compress data using a single CPU core, which leads to a data throughput considerably lower than the write speeds on modern storage. The most important of which is the cylinder size. # dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c | ssh dd of=įinally, save extra information about the drive geometry necessary in order to interpret the partition table stored within the image. If there is not enough disk space locally, you may send the image through ssh: # dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c | split -a3 -b2G - /path/to/ when the resulting files will be stored on a FAT32 file system) split the disk image into multiple parts (see also split(1)): # dd if=/dev/sda conv=sync,noerror bs=64K | gzip -c > /path/to/ Then mount the external hard drive and backup the drive: See fdisk#Backup and restore partition table or gdisk#Backup and restore partition table.īoot from a live medium and make sure no partitions are mounted from the source hard drive. To notify of changes without rebooting, use a utility like partprobe (part of GNU Parted). Partition table changes from dd are not registered by the kernel.If you are cloning a GPT disk, you can use sgdisk to randomize the disk and partition GUIDs and regain their uniqueness.For swap partitions, use mkswap -U random /dev/sd XY instead. To regain unique UUIDs of an ext2/3/4 filesystem, use tune2fs /dev/sd XY -U random on every partition.a single 512-byte read error will mess up the whole 64 KiB output block. But keep in mind that read errors on the source disk will end up as block errors on the destination disk, i.e. For example, changing bs from 512 to 64K changed copying speed from 35 MB/s to 120 MB/s on a simple Celeron 2.7 GHz system. If you are positive that your disk does not contain any errors, you could proceed using a larger block size, which will increase the speed of your copying several fold. This means, for a disk, that effectively the whole 1 MiB would become messed up because of a single 512 byte read error in the beginning of the read: 12ERROR89 would become 128900000 instead of 120000089. dd will, according to documentation, fill up the OBS to IBS size after completing its read, which means adding zeroes at the end of the block. Many people seem to think that dd will "fill up read errors with zeroes" if you use the noerror,sync options, but this is not what happens. But if a read error occurs, things will go wrong. Normally, if your block size is, say, 1 MiB, dd will read 1024×1024 bytes and write as many bytes. When you set bs, you effectively set both IBS and OBS. The dd utility technically has an "input block size" (IBS) and an "output block size" (OBS). Note: The block size you specify influences how read errors are handled.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |