{"id":193,"date":"2015-03-25T17:06:43","date_gmt":"2015-03-25T16:06:43","guid":{"rendered":"http:\/\/www.perrini.ch\/?p=193"},"modified":"2015-03-25T17:12:14","modified_gmt":"2015-03-25T16:12:14","slug":"create-binary-image-with-linux","status":"publish","type":"post","link":"https:\/\/www.perrini.ch\/?p=193","title":{"rendered":"Create Binary Image with Linux"},"content":{"rendered":"\n<div class=\"twitter-share\"><a href=\"https:\/\/twitter.com\/intent\/tweet?via=thiagoperrini\" class=\"twitter-share-button\">Tweet<\/a><\/div>\n<p>To create an image file on Linux we have various options to do the job. We have commands like dd, truncate, mkfile and others. On most linux systems we have fallocate installed by default. The command fallocate is supported\u00a0only on certain file systems such ext4, xfs, ocfs2 and btrfs. \u00a0The best choice to create a large file on a Linux system is the command fallocate. Fallocate only allocates\/reserves blocks and marking them as uninitialized without requiring I\/O and CPU time.\u00a0This is much faster than creating a file by filling it with zeros like the command dd does.<\/p>\n<p>&nbsp;<\/p>\n<p>To make sure we\u00a0have sufficient disk space to create an image file, we use the command df.<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">root@OSMIOM:\/var\/www# df -h \/var<\/pre>\n<p>Output:<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">Filesystem              Size  Used Avail Use% Mounted on\r\n\/dev\/mapper\/OSMIOM-var  6.0G  1.3G  4.4G  22% \/var\r\nroot@OSMIOM:\/var\/www#<\/pre>\n<p>We can see, that we have enough disk space to create some image files. \u00a0To create an image file we use the command fallocate.<\/p>\n<p>Syntax:<\/p>\n<pre class=\"theme:dark-terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">fallocate -d [-o offset] [-l length] filename<\/pre>\n<p>&nbsp;<\/p>\n<p>Example to create a 100 Megabyte file:<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">root@OSMIOM:\/var\/www# fallocate -l 100M myfile.img<\/pre>\n<p>Example to create a 1 Gigabyte file:<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">root@OSMIOM:\/var\/www# fallocate -l 1G myfile.img<\/pre>\n<p>Example to create a 10 Gigabyte file:<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">root@OSMIOM:\/var\/www# fallocate -l 10G myfile.img<\/pre>\n<p>Let&#8217;s verify our new file.:<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true\">root@OSMIOM:\/var\/www# ls -lh myfile.img<\/pre>\n<p>Output:<\/p>\n<pre class=\"theme:terminal font:courier-new toolbar:2 lang:default highlight:0 decode:true \">-rw-r--r-- 1 root www-data 1.0G Mar 22 11:05 myfile.img\r\nroot@OSMIOM:\/var\/www#<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To create an image file on Linux we have various<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[11],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.perrini.ch\/index.php?rest_route=\/wp\/v2\/posts\/193"}],"collection":[{"href":"https:\/\/www.perrini.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.perrini.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.perrini.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.perrini.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=193"}],"version-history":[{"count":5,"href":"https:\/\/www.perrini.ch\/index.php?rest_route=\/wp\/v2\/posts\/193\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/www.perrini.ch\/index.php?rest_route=\/wp\/v2\/posts\/193\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/www.perrini.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.perrini.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.perrini.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}