{"id":1013,"date":"2013-05-06T14:31:20","date_gmt":"2013-05-06T18:31:20","guid":{"rendered":"https:\/\/infotechguy.net\/?p=1013"},"modified":"2025-02-22T12:45:53","modified_gmt":"2025-02-22T17:45:53","slug":"linux-dd-operations","status":"publish","type":"post","link":"https:\/\/infotechguy.net\/?p=1013","title":{"rendered":"Linux &#8212; dd Operations Notes"},"content":{"rendered":"<p>I recently was helping a friend with some computer trouble which resulting in me first creating a full disk Image backup using &#8220;dd&#8221;. I&#8217;ve done this before years ago, but I wanted to add some of the common dd backup\/restore methods to my notepad. There are so many articles online on how to use dd to do a Full disk backup and restore it. I will be using similar methods.<\/p>\n<h3>dd Terms<\/h3>\n<ul>\n<li><strong>if &#8212;<\/strong> input device (file,hardware,CD,etc).<\/li>\n<li><strong>of &#8212;<\/strong> output device (file,hardware,CD,etc).<\/li>\n<li><strong>bs &#8212;<\/strong> sets &#8220;dd&#8221; read and write size.<\/li>\n<li><strong>noerror &#8212;<\/strong> continues after read errors.<\/li>\n<li><strong>readom &#8212;<\/strong> CD to ISO utility.<\/li>\n<li><strong>mount &#8212;<\/strong> Linux command to mount file-systems<\/li>\n<li><strong>gz &#8212;<\/strong> gunzip is a compression utility which helps to reduce the size of images created with dd.<\/li>\n<li><strong>md5sum &#8212;<\/strong> a checksum utility to ensure integrity when moving large image files.<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<h3>Direct Hard Drive to Hard Drive clone:<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">dd if=\/dev\/sda of=\/dev\/sdb<\/pre>\n<h3>Hard Drive to Image<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">dd if=\/dev\/sda conv=sync,noerror bs=64K | gzip -c &gt; image.gz<\/pre>\n<h3>Partition to Image<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">dd if=\/dev\/sda1 conv=sync,noerror bs=64K | gzip -c &gt; image.gz<\/pre>\n<p>NOTICE: This is the same command as the above example except it specifies the <strong>sda1 partition.<\/strong>.<\/p>\n<h3>Get dd Status<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">watch -n 5 killall -USR1 dd<\/pre>\n<p>This will monitor the status of the running <strong>dd<\/strong> process every 5 seconds.<br \/>\n<img decoding=\"async\" src=\"http:\/\/s6.postimg.org\/gjuul3c3l\/ddstatus.png\" alt=\"\" \/><\/p>\n<h3>CD to ISO<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">umount \/dev\/sr0 \nreadom dev=\/dev\/sr0 f=\/path\/to\/image.iso<\/pre>\n<p><strong>NOTICE:<\/strong> <em>Read <a href=\"http:\/\/www.commandlinefu.com\/commands\/view\/1396\/create-a-cddvd-iso-image-from-disk.\" target=\"_blank\" rel=\"noopener noreferrer\">this page<\/a> as to why readom is better than using dd for reading CDs.<br \/>\n<\/em><\/p>\n<h3>Zero a Drive<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">dd if=\/dev\/zero of=\/dev\/sda bs=4k conv=notrunc<\/pre>\n<p><strong>NOTICE:<\/strong> This will write zeros to each block on the drive. Using <strong>\/dev\/random<\/strong> is safer to ensure data cannot be recovered ,however it is more CPU and time intensive.<br \/>\n<strong>**notrunc <\/strong>&#8212; Does not truncate the output file. This is important as you want the entire drive zero&#8217;d<\/p>\n<h3>Benchmarking<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">dd if=\/dev\/zero bs=1024 count=1000000 of=testfile \ndd if=testfile of=\/dev\/null bs=1024<\/pre>\n<ul>\n<li>First part tests the write performance of the drive by growing a file of &#8220;zeros&#8221; to a file size of 1GB. The bs=1024 will use a block size of 1024bytes. This is really a cool utility, I remember using it to perform a benchmark test of my home RAID server when I completed the RAID set up.<\/li>\n<li>Second part tests the read performance of the drvie by re-reading the file we just created.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"http:\/\/s6.postimg.org\/4gpixj11d\/ddreadwrite.png\" alt=\"\" \/><br \/>\nNOTICE: The differences in read\/write is to be expected as performance benefits of RAID.<\/p>\n<h3>Mounting Single Partition Image File<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mount -t vfat -o loop,ro,noexec image.file \/mount\/point<\/pre>\n<p><strong>NOTICE:<\/strong> <em>Replace vfat with the filesystem type.<\/em><\/p>\n<h3>Mounting Full Disk Image Partition<\/h3>\n<p>**If the image to be restored contains multiple partitions, you will need to offset the image file to single out a partition to mount.<br \/>\nFirst use fdisk to read the image file and get the starting sector of the partition you want to mount.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">fdisk -l hd.img<\/pre>\n<p>**image missing, sorry \ud83d\ude41 ****<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mount -o loop,ro,offset=$((x*y)) hd.img \/mount\/point<\/pre>\n<p><strong>x =<\/strong> sector size (usually 1024)<br \/>\n<strong>y =<\/strong> starting sector (from fdisk -l)<\/p>\n<p>For my case:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mount -o loop,ro,offset=$((512*206848)) hd.img \/tmp\/temp\/<\/pre>\n<h3>Compression<\/h3>\n<p>Assuming image file name is <strong>hd.img<\/strong>, get <strong>md5sum<\/strong> of uncompressed Image. This will ensure integrity when compressing\/decompressing.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">md5sum hd.img<\/pre>\n<p>This may take a while depending on how large a file, and will generate a checksum string. I would save this string with the image file.<\/p>\n<p>Compress the image file.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">gzip -9 -c hd.img &gt; hd.img.gz<\/pre>\n<p><strong>NOTICE:<\/strong> This will compress the hd.img file using best compression. Time of compression will vary based on file size and bit complexity.<\/p>\n<p><strong>Sources:<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.commandlinefu.com\/commands\/view\/4158\/mount-a-partition-from-dd-disk-image\">http:\/\/www.commandlinefu.com\/commands\/view\/4158\/mount-a-partition-from-dd-disk-image<\/a><\/li>\n<li><a href=\"http:\/\/en.wikipedia.org\/wiki\/Dd_%28Unix%29\">http:\/\/en.wikipedia.org\/wiki\/Dd_%28Unix%29<\/a><\/li>\n<li><a href=\"http:\/\/www.mill-yard.com\/2011\/12\/using-dd-to-image-hard-disks\/\">http:\/\/www.mill-yard.com\/2011\/12\/using-dd-to-image-hard-disks\/<\/a><\/li>\n<li><a href=\"http:\/\/www.linuxweblog.com\/dd-image\">http:\/\/www.linuxweblog.com\/dd-image<\/a><\/li>\n<li><a href=\"http:\/\/linux.about.com\/od\/commands\/l\/blcmdl1_dd.htm\">http:\/\/linux.about.com\/od\/commands\/l\/blcmdl1_dd.htm<\/a><\/li>\n<li><a href=\"http:\/\/www.commandlinefu.com\/commands\/matching\/readom\/cmVhZG9t\/sort-by-votes\">http:\/\/www.commandlinefu.com\/commands\/matching\/readom\/cmVhZG9t\/sort-by-votes<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I recently was helping a friend with some computer trouble which resulting in me first creating a full disk Image backup using &#8220;dd&#8221;. I&#8217;ve done this before years ago, but I wanted to add some&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":4240,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[110],"class_list":["post-1013","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-san"],"_links":{"self":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1013"}],"version-history":[{"count":1,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":4171,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1013\/revisions\/4171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/media\/4240"}],"wp:attachment":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}