{"id":88,"date":"2015-09-07T16:41:16","date_gmt":"2015-09-07T15:41:16","guid":{"rendered":"http:\/\/www.haxed.me.uk\/?p=88"},"modified":"2015-09-07T16:42:26","modified_gmt":"2015-09-07T15:42:26","slug":"mounting-a-disk-in-linux-operating-systems","status":"publish","type":"post","link":"https:\/\/haxed.me.uk\/index.php\/2015\/09\/07\/mounting-a-disk-in-linux-operating-systems\/","title":{"rendered":"Mounting A disk in Linux Operating Systems"},"content":{"rendered":"<p>So, apparently, some people aren&#8217;t sure how to properly add a new disk to a Linux server. Well, it&#8217;s pretty simple if you are using something like Cloud Block Storage and have ondemand. But even if you don&#8217;t, after adding the disk into your Linux machine, here is the process of going about adding a standard disk, fdisking (partitioning), formating (mkfs), and the mounting process itself, including that in fstab.<\/p>\n<p>Step 1. List the disk&#8217;s on the box<\/p>\n<pre> \r\n$ fdisk -l\r\n\r\nDevice     Boot Start      End  Sectors Size Id Type\r\n\/dev\/xvda1 *     2048 41940991 41938944  20G 83 Linux\r\n\r\nDisk \/dev\/xvdb: 75 GiB, 80530636800 bytes, 157286400 sectors\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\n<\/pre>\n<p>As we can see the new 75GiB drive I added hasn&#8217;t any file system on it yet. <\/p>\n<p>Step 2. Let&#8217;s start partitioning the disk <\/p>\n<pre>\r\n$ fdisk \/dev\/xvdb\r\n\r\nDevice     Boot Start      End  Sectors Size Id Type\r\n\/dev\/xvda1 *     2048 41940991 41938944  20G 83 Linux\r\n\r\nDisk \/dev\/xvdb: 75 GiB, 80530636800 bytes, 157286400 sectors\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\n<\/pre>\n<p>Step 3. Let&#8217;s create a new partition using &#8216;n&#8217; key, and then let&#8217;s state we want a primary partition using &#8216;p&#8217;.<br \/>\nStep 4: Let&#8217;s set the first and last sectors of the disk (you can type enter and the machine will normally chose something sane for you). It&#8217;s also possible to add multiple partitions of a single device, but for this tutorial we won&#8217;t be covering that.<\/p>\n<pre>\r\n\r\nCommand (m for help): n\r\nPartition type\r\n   p   primary (0 primary, 0 extended, 4 free)\r\n   e   extended (container for logical partitions)\r\n\r\nSelect (default p): p\r\n\r\nPartition number (1-4, default 1): 1\r\nFirst sector (2048-157286399, default 2048): \r\nLast sector, +sectors or +size{K,M,G,T,P} (2048-157286399, default 157286399): \r\n\r\nCreated a new partition 1 of type 'Linux' and of size 75 GiB.\r\n<\/pre>\n<p>Step 4. Write the disk using the &#8216;w&#8217; key, and then after it&#8217;s finished confirm with fdisk that new partition is present.<\/p>\n<pre>\r\n\r\nCommand (m for help): w\r\nThe partition table has been altered.\r\nCalling ioctl() to re-read partition table.\r\nSyncing disks.\r\n\r\nroot@tesladump:\/home# fdisk -l\r\n\r\nDisk \/dev\/xvda: 20 GiB, 21474836480 bytes, 41943040 sectors\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisklabel type: dos\r\nDisk identifier: 0x0c708d98\r\n\r\nDevice     Boot Start      End  Sectors Size Id Type\r\n\/dev\/xvda1 *     2048 41940991 41938944  20G 83 Linux\r\n\r\nDisk \/dev\/xvdb: 75 GiB, 80530636800 bytes, 157286400 sectors\r\nUnits: sectors of 1 * 512 = 512 bytes\r\nSector size (logical\/physical): 512 bytes \/ 512 bytes\r\nI\/O size (minimum\/optimal): 512 bytes \/ 512 bytes\r\nDisklabel type: dos\r\nDisk identifier: 0x07c2e0a6\r\n\r\nDevice     Boot Start       End   Sectors Size Id Type\r\n\/dev\/xvdb1       2048 157286399 157284352  75G 83 Linux\r\n\r\n<\/pre>\n<p>Now the disk has been partitioned.<\/p>\n<p>Step 5. So lets create an (EXT3) file system on the device.<\/p>\n<pre>\r\n\r\n$ mkfs -t ext3 \/dev\/xvdb1\r\n\r\nmke2fs 1.42.12 (29-Aug-2014)\r\nCreating filesystem with 19660544 4k blocks and 4915200 inodes\r\nFilesystem UUID: c717ddbd-d5c9-4bb1-a8af-b521d38cbb14\r\nSuperblock backups stored on blocks: \r\n\t32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, \r\n\t4096000, 7962624, 11239424\r\n\r\nAllocating group tables: done                            \r\nWriting inode tables: done                            \r\nCreating journal (32768 blocks): done\r\nWriting superblocks and filesystem accounting information: done   \r\n\r\n<\/pre>\n<p>So that is the file system done. Now all we need to do is mount it. We can do that thru the \/etc\/fstab file, and also using the mount -a command.<\/p>\n<p>Step 6. Simply we edit our \/etc\/fstab to accommodate the new disk<\/p>\n<pre> \r\n\r\n# \/etc\/fstab: static file system information.\r\n#\r\n# Use 'blkid' to print the universally unique identifier for a\r\n# device; this may be used with UUID= as a more robust way to name devices\r\n# that works even if disks are added and removed. See fstab(5).\r\n#\r\n# <file system> <mount point>   <type>  <options>       <dump>  <pass>\r\n\/dev\/xvda1      \/               ext3    errors=remount-ro,noatime,barrier=0 0       1\r\n\r\n\r\n<strong>\/dev\/xvdb1      \/home\/thetesladump ext3 defaults,noatime,nofail 0    0<\/strong>\r\n\r\n<\/pre>\n<p>Here we choose to mount the partition1  \/dev\/xvdb (\/dev\/xvdb1) on the symlink directory \/home\/thetesladump . A little FTP I temporarily wanted to host.<\/p>\n<p>So we setup the new 75Gig cloud block device to be mounted at the ftp user thetesladump&#8217;s root home user directory. All ready to go. wooo.<\/p>\n<p>Step 7. Complete hte process by running a mount -a<\/p>\n<pre> \r\n\r\nmount -a\r\n\r\n<\/pre>\n<p>Step 8. Confirm your disks are mounted where you wanted<\/p>\n<pre>\r\n\r\nroot@tesladump:\/home\/theteslasociety# df -h\r\nFilesystem      Size  Used Avail Use% Mounted on\r\n\/dev\/xvda1       20G  1.1G   18G   6% \/\r\nudev             10M     0   10M   0% \/dev\r\ntmpfs           199M   21M  179M  11% \/run\r\ntmpfs           498M     0  498M   0% \/dev\/shm\r\ntmpfs           5.0M     0  5.0M   0% \/run\/lock\r\ntmpfs           498M     0  498M   0% \/sys\/fs\/cgroup\r\n\/dev\/xvdb1       74G  178M   70G   1% \/home\/thetesladump\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So, apparently, some people aren&#8217;t sure how to properly add a new disk to a Linux server. Well, it&#8217;s pretty simple if you are using something like Cloud Block Storage and have ondemand. But even if you don&#8217;t, after adding &hellip; <a href=\"https:\/\/haxed.me.uk\/index.php\/2015\/09\/07\/mounting-a-disk-in-linux-operating-systems\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9,7],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-filesystem","category-linux","category-management-tools"],"_links":{"self":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/comments?post=88"}],"version-history":[{"count":0,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"wp:attachment":[{"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/haxed.me.uk\/index.php\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}