{"id":1401,"date":"2019-03-11T06:28:11","date_gmt":"2019-03-11T00:58:11","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1401"},"modified":"2019-03-25T07:56:49","modified_gmt":"2019-03-25T02:26:49","slug":"how-to-create-a-virtual-harddisk-volume-using-a-file-in-linux-2","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/how-to-create-a-virtual-harddisk-volume-using-a-file-in-linux-2\/","title":{"rendered":"How to create a virtual HardDisk volume using a File in Linux"},"content":{"rendered":"\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>Description<\/strong><\/p>\n\n\n\n<p><strong>Virtual Hard Disk<\/strong>&nbsp;(<strong>VHD<\/strong>) is a disk image file format which represents a virtual hard disk drive, capable of storing the complete contents of a physical hard drive. <\/p>\n\n\n\n<p>It\u2019s a container file that acts similar to a physical hard drive. <\/p>\n\n\n\n<p>The disk image replicates an existing hard drive and includes all data and structural features. <\/p>\n\n\n\n<p> Just like a physical hard drive, a <strong>VHD<\/strong>&nbsp;can contains a file system, and you can use it to store and run an operating system, applications, as well as store data. <\/p>\n\n\n\n<p>One of the typical uses of&nbsp;<strong>VHDs<\/strong>&nbsp;in&nbsp;VirtualBox Virtual Machines (VMs)&nbsp;to store operating systems and application, and data. <\/p>\n\n\n\n<p> In this article, we will demonstrate how to create a virtual hard disk volume using a file in Linux. <\/p>\n\n\n\n<p>For the purpose of this guide, we will create a VHD volume of size <strong>1GB<\/strong>, and format it with&nbsp;<strong>EXT4<\/strong>&nbsp;file system type. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create a New Image to Hold Virtual Drive Volume<\/strong><\/p>\n\n\n\n<p>There are number of ways you can do this, but the most easiest way is using the following&nbsp;<strong>dd command<\/strong>. <\/p>\n\n\n\n<p>In this example, we will be creating a VHD volume of size&nbsp;<strong>1GB<\/strong>&nbsp;image.<\/p>\n\n\n\n<p> Where: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> <strong>if=\/dev\/zero<\/strong>: input file to provide a character stream for initializing data storage <\/li><li> <strong>of=VHD.img<\/strong>: image file to be created as storage volume <\/li><li> <strong>bs=1M<\/strong>: read and write up to 1M at a time <\/li><li> <strong>count=1200<\/strong>: copy only 1200M (1GB) input blocks <\/li><\/ul>\n\n\n\n<p>We need to format the <strong>EXT4<\/strong>&nbsp;file system type in the&nbsp;<strong>VHD<\/strong>&nbsp;image file with the&nbsp;<strong>mkfs utility<\/strong>. <\/p>\n\n\n\n<p>Answer&nbsp;<code>y<\/code>, when prompted that&nbsp;<strong>\/media\/VHD.img<\/strong> is not a block special device<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>sudo mkfs -t ext4 \/media\/VHD.img<\/em><\/strong><br><\/pre>\n\n\n\n<p>In order to access the&nbsp;<strong>VHD<\/strong>&nbsp;volume, we need to mount to a directory (mount point). <\/p>\n\n\n\n<p>Run these commands to create the mount point and mount the VHD volume, respectively. <\/p>\n\n\n\n<p>The&nbsp;<code>-o<\/code>&nbsp;is used to specify options for mounting, here, the option loop indicates the device node under the&nbsp;<strong>\/dev\/<\/strong>&nbsp;directory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>sudo mkdir \/mnt\/VHD\/<\/em><\/strong><br> <br><strong><em>sudo mount -t auto -o loop \/media\/VHD.img \/mnt\/VHD\/ <\/em><\/strong><br><\/pre>\n\n\n\n<p><strong>Note<\/strong>: The&nbsp;<strong>VHD<\/strong>&nbsp;filesystem will only remain mounted until the next reboot, to mount it at system boot, add this entry in the&nbsp;<strong>\/etc\/fstab<\/strong> file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>\/media\/VHD.img  \/mnt\/VHD\/  ext4    defaults        0  0<\/em><\/strong><\/pre>\n\n\n\n<p>Now you can verify the newly created VHD filesystem with mount point using the following <a href=\"http:\/\/jaipurhosting.com\/blog\/how-to-check-disk-usage-using-df-commands\/\">df command<\/a><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>df -hT<\/em><\/strong><br><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Removing Virtual Drive Volume<\/strong><br><\/p>\n\n\n\n<p>If you don\u2019t need the VHD volume anymore, run the following commands to unmount the VHD filesystem, then delete the image file:<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>sudo umount \/mnt\/VHD\/<\/em><\/strong><br> <br><strong><em>sudo rm \/media\/VHD.img <\/em><\/strong><\/pre>\n\n\n\n<p>You can also create a <a href=\"http:\/\/jaipurhosting.com\/blog\/how-to-create-a-linux-swap-file-2\/\">swap area\/space using a file&nbsp;in Linux<\/a> <\/p>\n\n\n\n<p>We hope you\u2019ve found this useful!&nbsp; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description Virtual Hard Disk&nbsp;(VHD) is a disk image file format which represents a virtual hard disk drive, capable of storing the complete contents of a physical hard drive. It\u2019s a container file that acts similar to a physical hard drive. The disk image replicates an existing hard drive and includes all data and structural features. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1402,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1401"}],"version-history":[{"count":4,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1401\/revisions"}],"predecessor-version":[{"id":1415,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1401\/revisions\/1415"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1402"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}