{"id":13,"date":"2017-08-04T22:01:00","date_gmt":"2017-08-04T22:01:00","guid":{"rendered":"https:\/\/www.barryhubbard.com\/?p=13"},"modified":"2023-12-31T01:55:14","modified_gmt":"2023-12-31T01:55:14","slug":"dd-how-to-copy-a-drive-in-linux-from-the-command-line","status":"publish","type":"post","link":"https:\/\/barryhubbard.com\/index.php\/2017\/08\/04\/dd-how-to-copy-a-drive-in-linux-from-the-command-line\/","title":{"rendered":"dd &#8211; How to copy a drive in Linux from the command line"},"content":{"rendered":"\n<p><strong>What Could Go Wrong<\/strong><\/p>\n\n\n\n<p>As always, a lot could go wrong, but the biggest thing is not having the correct input or output file specified. <strong>Nothing stops you from using dd to overwrite your current working harddrive.<\/strong> Make sure that you have the right devices specified.<\/p>\n\n\n\n<p><strong>What is dd<\/strong><\/p>\n\n\n\n<p>dd is a useful command line utility for ghosting or copying devices, including partitions, entire hard drives, or making backup copies of a cd or dvd. &nbsp;When you use dd, you basically create an identical image, you aren\u2019t copying individual files. &nbsp;Therefore, if you original drive is 1TB, your copy will be 1TB, even if only 30GB used. &nbsp;The nice thing is that dd doesn\u2019t care what the source file is, how it is formatted, or what information it contains.<\/p>\n\n\n\n<p><strong>Some uses for dd:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Creating&nbsp;a \u201cghost\u201d image of a hard drive partition \u2013 i.e. ghosting the c:\\ partition to make a whole backup of your Windows drive<\/li>\n\n\n\n<li>Making a backup copy of your favorite Grateful Dead cd<\/li>\n\n\n\n<li>Copying an entire hard drive before replacing it<\/li>\n<\/ul>\n\n\n\n<p>Note: dd will output a file that contains all of the data contained in your original file. &nbsp;Below is way I normally use it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dd if=\/dev\/sda of=\/tmp\/sda_image.img conv=noerror,sync<\/code><\/pre>\n\n\n\n<p>So, what does all of this mean:<\/p>\n\n\n\n<p>dd: This is the name of the command, always start here<\/p>\n\n\n\n<p>if: This is the name of your input file. Typically this is the name of a device. In this case, I am creating an image of the entire primary sata harddrive (available on the system as \/dev\/sda). Other alternatives:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\/dev\/sda1 (The first partition on sda)<\/li>\n\n\n\n<li>\/dev\/sr0 (Typically refers to the first CD \/ DVD sata drive)<\/li>\n<\/ul>\n\n\n\n<p>of: This is the name of the output file. This can be any file with any extension, although I normally stick to .img for disk drives and .iso for cds and dvds<\/p>\n\n\n\n<p>conv=noerror,sync: These are additional command line options. Refer to the man page for full details, but generally this allows the image to remain synced along the proper boundaries and continues even if errors are encountered<\/p>\n\n\n\n<p><strong>Other things to consider<\/strong><br>You might also consider adding<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bs=1024<\/code><\/pre>\n\n\n\n<p>which will copy 1KB at a time, as opposed to bit by bit. In many cases this can speed up the duplication significantly.<\/p>\n\n\n\n<p><strong>How to restore from the image<\/strong><\/p>\n\n\n\n<p>To restore from the previously created image, just do the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dd of=\/dev\/sda if=\/tmp\/sda_image.img conv=noerror,sync\n<\/code><\/pre>\n\n\n\n<p>Note: the only difference between these commands are the flipping of the \u201cif\u201d and \u201cof\u201d<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What Could Go Wrong As always, a lot could go wrong, but the biggest thing is not having the correct [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[4],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/comments?post=13"}],"version-history":[{"count":1,"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/posts\/13\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/media?parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/categories?post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barryhubbard.com\/index.php\/wp-json\/wp\/v2\/tags?post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}