{"id":449,"date":"2011-03-07T15:03:14","date_gmt":"2011-03-07T21:03:14","guid":{"rendered":"http:\/\/www.nathanhunstad.com\/blog\/?p=449"},"modified":"2011-03-07T20:22:52","modified_gmt":"2011-03-08T02:22:52","slug":"customizing-clonezillas-custom-ocs","status":"publish","type":"post","link":"https:\/\/www.nathanhunstad.com\/blog\/2011\/03\/customizing-clonezillas-custom-ocs\/","title":{"rendered":"Customizing Clonezilla&#8217;s custom-ocs"},"content":{"rendered":"<p>In a (very popular by search engine standards) <a href=\"http:\/\/www.nathanhunstad.com\/blog\/2010\/03\/moving-from-ghost-to-clonezilla\/\" target=\"_blank\">previous post<\/a>, I talked about moving from Norton Ghost to Clonezilla. Part of the move from Ghost to Clonezilla was creating a method of automatically determining the computer model I was imaging, and selecting the right image. This is possible by changing the custom-ocs file, and here are the changes I made to do it.<\/p>\n<p><!--more--><\/p>\n<p>I made a number of minor changes to the stock custom-ocs file, but they were powerful enough to get the job done.<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New';\">mount \/dev\/sdb2 \/home\/partimag\/ <\/span><\/p><\/blockquote>\n<p>This is often overlooked, but make sure that you mount the proper location for your image files! On the external hard drive I used for imaging, I have two partitions: the first is tiny and has the Clonezilla software, the second is huge and holds the images. Hence, I want the second one (\/sdb2) mounted as the image store.<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New';\">echo &#8220;Type c to create image; defaults to imaging computer if nothing typed.&#8221;<br \/>\nread -n 1 -t 7 createimg<br \/>\necho<br \/>\nif [[ $createimg == &#8220;c&#8221; ]] &amp;&amp; [[ -n &#8220;${createimg}&#8221; ]]<br \/>\nthen<br \/>\necho &#8220;Image will be created from current machine.&#8221;<br \/>\nelse<br \/>\necho &#8220;Hard drive will be overwritten with disk image.&#8221;<br \/>\ncreateimg=&#8221;g&#8221;<br \/>\nfi<\/span><\/p><\/blockquote>\n<p>This code determines if I want to create a new image from the current machine, or push an image onto the current machine. The \u201cread \u2013n 1 \u2013t 7 createimg\u201d line reads one character (-n 1) into the variable createimg, with a 7 second timeout (-t 7). The \u201cif [[ $createimg == &#8220;c&#8221; ]] &amp;&amp; [[ -n &#8220;${createimg}&#8221; ]]\u201d line tests to see if createimg is equal to \u2018c\u2019 and not empty. If so, a reassurance that the image will be created from the current machine is displayed.<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New';\">x=`sudo dmidecode -t 1 | grep -i Product | tr -d &#8216;\\n&#8217;`<br \/>\ny=${x#*: }<br \/>\ny=${y\/\/ \/}<\/span><\/p><\/blockquote>\n<p>Here is the most important section. This determines the model of the attached computer. It looks hairy (like a lot of bash scripts), but it\u2019s not too bad. It pipes the dmidecode output of system info (-t 1) to grep, which pulls out the line containing \u201cProduct\u201d, and then trims the newline. The next line (y=${x#*: }) removes everything before the colon, and the following line (y=${y\/\/ \/}) removes all the spaces. You are left with a variable containing the Product Name as stored in the BIOS, without spaces. Very convenient.<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New';\">echo The following model has been detected:<br \/>\necho $y<br \/>\necho Please press q to abort.<br \/>\nread -n 1 -t 5 abort<br \/>\nif [[ $abort == &#8220;q&#8221; ]] &amp;&amp; [[ -n &#8220;${abort}&#8221; ]]<br \/>\nthen<br \/>\necho Aborting!<br \/>\nexit 1<br \/>\nelse<br \/>\necho Continuing&#8230;<br \/>\nfi<\/span><\/p><\/blockquote>\n<p>This displays the just-detected model information, and once pauses for input, this time for 5 seconds (-t 5). This way, if something terrible has gone wrong and the wrong model has been detected, or you made a mistake, you can abort. I set it up with timeouts like these so when I plug my external HD into a computer and boot from it, it will automatically push the image onto that machine without any further intervention from me. If you are nervous, then remove the timeouts and do things manually.<\/p>\n<blockquote><p><span style=\"font-family: 'Courier New';\">echo Running Clonezilla<br \/>\ncase $y in<br \/>\nOptiPlex780*)<br \/>\nif [[ $createimg == &#8220;c&#8221; ]]<br \/>\nthen<br \/>\necho Now saving image&#8230;<br \/>\necho y | \/opt\/drbl\/sbin\/ocs-sr -q2 -c -j2 -rm-win-swap-hib -z1 -i 2000 -p poweroff savedisk &#8220;Dell780&#8221; &#8220;sda&#8221;<br \/>\nelse<br \/>\necho Now ghosting machine&#8230;<br \/>\necho y | \/opt\/drbl\/sbin\/ocs-sr -g auto -e1 auto -r -j2 -p reboot restoredisk &#8220;Dell780&#8221; &#8220;sda&#8221;<br \/>\nfi<br \/>\nexit 0<br \/>\n;;<\/span><\/p>\n<p><span style=\"font-family: 'Courier New';\">*)<br \/>\necho The computer could not be correctly identified!<br \/>\nexit 1<br \/>\n;;<br \/>\nesac<\/span><\/p><\/blockquote>\n<p>Here\u2019s where each individual model is handled. In this sample case block, the only listed model is an OptiPlext780. If \u2018c\u2019 was pressed earlier to signal the creation of a new image from the current machine, then the line <span style=\"font-family: 'Courier New';\">echo y | \/opt\/drbl\/sbin\/ocs-sr -q2 -c -j2 -rm-win-swap-hib -z1 -i 2000 -p poweroff savedisk &#8220;Dell780&#8221; &#8220;sda&#8221; <span style=\"font-family: Arial;\">does that for us. Going through, it echoes \u2018y\u2019 (so we don\u2019t have to hit it manually) to the Clonezilla script that creates an image using partclone, with confirmation, with the hidden data between the MBR and 1st partition, removing the swap and hibernation files, with gzip compression, with the image split into 2000 MB pieces, power off after completion, save the entire disk, call it \u201cDell780\u201d, and save device \u201csda\u201d. If c was not pressed, and the image is put onto the machine, then it\u2019s almost the exact same thing, with a few different parameters (\u201crestoredisk\u201d instead of \u201csavedisk\u201d, for example).<\/span><\/span><\/p>\n<p><span style=\"font-family: 'Courier New';\"><span style=\"font-family: Arial;\">The default block is run if none of the model numbers match. Always a good sanity check.<\/span><\/span><\/p>\n<p><span style=\"font-family: 'Courier New';\"><span style=\"font-family: Arial;\">If you had several different image types for each model, you could add additional prompts with read and case in each model block. The functionality is limited only by your needs and technical expertise.<\/span><\/span><\/p>\n<p>Ever since I set up this custom-ocs file, it has run beautifully, needing only tweaks to add new models as necessary. It makes imaging a breeze.<\/p>\n<p><span style=\"font-family: 'Courier New';\"><span style=\"font-family: Arial;\"> <\/span><br \/>\n<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In a (very popular by search engine standards) previous post, I talked about moving from Norton Ghost to Clonezilla. Part of the move from Ghost to Clonezilla was creating a method of automatically determining the computer model I was imaging, and selecting the right image. This is possible by changing the custom-ocs file, and here&hellip; <a class=\"more-link\" href=\"https:\/\/www.nathanhunstad.com\/blog\/2011\/03\/customizing-clonezillas-custom-ocs\/\">Continue reading <span class=\"screen-reader-text\">Customizing Clonezilla&#8217;s custom-ocs<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[19],"tags":[157,21],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-tech-2","tag-clonezilla","tag-linux","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts\/449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/comments?post=449"}],"version-history":[{"count":1,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions"}],"predecessor-version":[{"id":450,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/posts\/449\/revisions\/450"}],"wp:attachment":[{"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/media?parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/categories?post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nathanhunstad.com\/blog\/wp-json\/wp\/v2\/tags?post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}