{"id":50,"date":"2010-01-03T19:33:53","date_gmt":"2010-01-03T11:33:53","guid":{"rendered":"http:\/\/www.lanchbury.id.au\/wp\/?p=50"},"modified":"2013-03-17T07:35:49","modified_gmt":"2013-03-16T23:35:49","slug":"adding-a-hdd-to-linux","status":"publish","type":"post","link":"https:\/\/www.lanchbury.au\/?p=50","title":{"rendered":"Adding a HDD to linux"},"content":{"rendered":"<p>Well every time I add a hard drive to my server. It&#8217;s always such a  long time between that I forget how to do it. Lucky I&#8217;ve bookmarked a  few sites on how to do it. But that&#8217;s just it a few sites, not one that  explains the whole process. Well there most likely is now but I thought I  might write this so I can just go to my own site with all the  information I need on it. So here it is.<\/p>\n<p><strong>PLEASE NOTE: <\/strong>I  know this guide works as I wrote it during the installation of a new  hard drive myself. Please understand mistakes can be made on my or your  part. At a few points during this guide one incorrect key entry can  completely erase your data and\/or operating system. I try to stress  points during the process but overall I can not be liable for the  information below on your system. Just be clear minded during the steps  and take your time there&#8217;s no hurry. It took me 2 days (over Christmas)  so take your time like I did.<\/p>\n<p><strong>1.<\/strong> Well the very first thing is shut down the machine and install the hard drive, simple enough.<br \/>\n<strong>2.<\/strong> Turn it back on and allow it to boot normally.<br \/>\n<strong>3. <\/strong>Open a terminal window or login a shell<br \/>\n<strong>4.<\/strong> su to root access<br \/>\n<strong>5. <\/strong>Next we want to see if linux has found it. Depending on your hardware it could be sd* or hd* as below<\/p>\n<p><code># ls \/dev\/sd*<br \/>\n\/dev\/sda \/dev\/sda3 \/dev\/sdb \/dev\/sdc1 \/dev\/sde1<br \/>\n\/dev\/sda1 \/dev\/sda4 \/dev\/sdb1 \/dev\/sdd \/dev\/sdf<br \/>\n\/dev\/sda2 \/dev\/sda5 \/dev\/sdc \/dev\/sde \/dev\/sdf1<\/code><\/p>\n<p><strong>6. <\/strong>From that list your looking for a hard drive  without a partition. So to explain sda is the hard drive itself, sda1 is  the first partition and sda2 is the second. So in my case my new hard  drive is \/dev\/sdd. This arrangement changes depending which sata slot  the drive is plugged into and if there are blank spots. So in my case  sde and sdf moved down to fit sdd in.<br \/>\n<strong>7. <\/strong>OK we want  to create a partition on the drive to do this I use fdisk, for those of  you come from dos this will be self explanatory.<\/p>\n<p><code> # \/sbin\/fdisk \/dev\/sdd<br \/>\nDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel<br \/>\nBuilding a new DOS disklabel with disk identifier 0x9ab04e42.<br \/>\nChanges will remain in memory only, until you decide to write them.<br \/>\nAfter that, of course, the previous content won't be recoverable.<\/code><\/p>\n<p>The number of cylinders for this disk is set to 121601.<br \/>\nThere is nothing wrong with that, but this is larger than 1024,<br \/>\nand could in certain setups cause problems with:<br \/>\n1) software that runs at boot time (e.g., old versions of LILO)<br \/>\n2) booting and partitioning software from other OSs<br \/>\n(e.g., DOS FDISK, OS\/2 FDISK)<br \/>\nWarning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)<\/p>\n<p>Command (m for help):<\/p>\n<p><strong>8. <\/strong>As it says there &#8216;m&#8217; for help. So if I miss something you want, do that.<br \/>\n<strong>9. <\/strong>One  thing I like to do is make sure there is nothing on the drive. This  also makes me list were I&#8217;m at in my own head, plus makes sure your not  on the wrong drive<\/p>\n<p><code>Command (m for help): p<\/code><\/p>\n<p>Disk \/dev\/sdd: 1000.2 GB, 1000204886016 bytes<br \/>\n255 heads, 63 sectors\/track, 121601 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<br \/>\nDisk identifier: 0x9ab04e42<\/p>\n<p>Device Boot Start End Blocks Id System<\/p>\n<p><strong>10. <\/strong>We want to make a new partition. For me I just  want one full size. You can make more if you want and repeat steps 15  down to format them.<\/p>\n<p><code>Command (m for help): n<br \/>\nCommand action<br \/>\ne extended<br \/>\np primary partition (1-4)<br \/>\np<br \/>\nPartition number (1-4): 1<br \/>\nFirst cylinder (1-121601, default 1):<br \/>\nUsing default value 1<br \/>\nLast cylinder or +size or +sizeM or +sizeK (1-121601, default 121601):<br \/>\nUsing default value 121601<\/code><\/p>\n<p><strong>11. <\/strong>I through a lot into there. N to create a new  partition. P to select it as the primary as there isn&#8217;t any on it now. 1  as the first partition. The last two steps are asking where to store  the data on the drive, the defaults are fine for a single large  partition so enter twice.<\/p>\n<p><code>Command (m for help): p<\/code><\/p>\n<p>Disk \/dev\/sdd: 1000.2 GB, 1000204886016 bytes<br \/>\n255 heads, 63 sectors\/track, 121601 cylinders<br \/>\nUnits = cylinders of 16065 * 512 = 8225280 bytes<br \/>\nDisk identifier: 0xed679c51<\/p>\n<p>Device Boot Start End Blocks Id System<br \/>\n\/dev\/sdd1 1 121601 976760001 83 Linux<\/p>\n<p><strong>12. <\/strong>One again it&#8217;s good to see what you&#8217;ve done.  Plus we will confirm the changes to the disk next. So make sure your  happy with the above. If you make a mistake as this point you can Q for  quit or Ctrl+C. Then start again from step 7<\/p>\n<p><code>Command (m for help): w<br \/>\nThe partition table has been altered!<\/code><\/p>\n<p>Calling ioctl() to re-read partition table.<br \/>\nSyncing disks.<br \/>\n#<\/p>\n<p><strong>13. <\/strong>Don&#8217;t be too worried how long this step takes.<br \/>\n<strong>14. <\/strong>Next  we want to format it linux so that we can mount it. First lets double  check the partition is showing up and that you file system the right<\/p>\n<p><code># ls \/dev\/sd*<br \/>\n\/dev\/sda \/dev\/sda3 \/dev\/sdb \/dev\/sdc1 \/dev\/sde \/dev\/sdf1<br \/>\n\/dev\/sda1 \/dev\/sda4 \/dev\/sdb1 \/dev\/sdd \/dev\/sde1<br \/>\n\/dev\/sda2 \/dev\/sda5 \/dev\/sdc \/dev\/sdd1 \/dev\/sdf<\/code><\/p>\n<p><strong>15. <\/strong>So \/dev\/sdd1 has appeared so next now we can run  the make file system command. Double check you \/dev\/sd? with your fdisk  to be sure. This takes a bit of time depending on the size of your hard  drive and the speed of it. For my terabyte drive it took around 5  minutes. But it keeps you informed.<\/p>\n<p><code># \/sbin\/mkfs.ext3 \/dev\/sdd1<br \/>\nmke2fs 1.40.4 (31-Dec-2007)<br \/>\nFilesystem label=<br \/>\nOS type: Linux<br \/>\nBlock size=4096 (log=2)<br \/>\nFragment size=4096 (log=2)<br \/>\n122109952 inodes, 244190000 blocks<br \/>\n12209500 blocks (5.00%) reserved for the super user<br \/>\nFirst data block=0<br \/>\nMaximum filesystem blocks=0<br \/>\n7453 block groups<br \/>\n32768 blocks per group, 32768 fragments per group<br \/>\n16384 inodes per group<br \/>\nSuperblock backups stored on blocks:<br \/>\n32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,<br \/>\n4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,<br \/>\n102400000, 214990848<\/code><\/p>\n<p>Writing inode tables: ####\/7453<br \/>\nWriting inode tables: done<br \/>\nCreating journal (32768 blocks): done<br \/>\nWriting superblocks and filesystem accounting information: done<\/p>\n<p>This filesystem will be automatically checked every 37 mounts or<br \/>\n180 days, whichever comes first. Use tune2fs -c or -i to override.<\/p>\n<p><strong>16. <\/strong>OK so the drive is ready for mounting. But there  are a couple of things I do to make sure installing new or removing old  hard drives don&#8217;t mess with the other drives. This process is call  labelling your hard drive. As my server is called Nebuchadnezzar I label  my drives as the characters on the ship. So in this case it will be  trinity.<\/p>\n<p><code># \/sbin\/e2label \/dev\/sdd1 trinity<\/code><\/p>\n<p><strong>17. <\/strong>Lastly we need to create a folder that we can  mount the new drive to. In my case all my hard drive are mounted in  \/media and I know the hard drive label so<\/p>\n<p><code># mkdir \/media\/trinity\/<\/code><\/p>\n<p><strong>18. <\/strong>I&#8217;ve just learnt during the writing of the a  script called devlabel that makes a symbolic link for the hard drive.  It&#8217;s come out in fedora 12 and I&#8217;m running Fedora 8 on this server. Yes  yes I need to upgrade, hopefully over this Christmas break I&#8217;ll get to  it. So hopefully I&#8217;ll change this when I find out more -your welcome to  if you want.<br \/>\n<strong>19. <\/strong>OK, OK, Let mount this drive.<\/p>\n<p><code># mount LABEL=trinity \/media\/trinity\/<\/code><\/p>\n<p><strong>20. <\/strong>Well that&#8217;s the hard bit done to see how much space you&#8217;ve got now<\/p>\n<p><code># df -h<br \/>\nFilesystem Size Used Avail Use% Mounted on<br \/>\n\/dev\/sda2 71G 55G 12G 83% \/<br \/>\n\/dev\/sda1 190M 47M 134M 26% \/boot<br \/>\ntmpfs 1.5G 396K 1.5G 1% \/dev\/shm<br \/>\n\/dev\/sde1 917G 775G 97G 89% \/media\/apoc<br \/>\n\/dev\/sdf1 917G 772G 99G 89% \/media\/mouse<br \/>\n\/dev\/sdc1 688G 645G 8.2G 99% \/media\/morpheus<br \/>\n\/dev\/sdb1 459G 369G 67G 85% \/media\/switch<br \/>\n\/dev\/sdd1 917G 200M 871G 1% \/media\/trinity<\/code><\/p>\n<p><strong>21. <\/strong>The question is how long will it last \ud83d\ude42<br \/>\n<strong>22. <\/strong>OK  the last thing to do is that mounting only works for this boot. Once  you reboot the hard will be unmounted. To mount it at boot time you need  to edit fstab. I need to stress editing this file incorrectly will stop  the machine from booting. The only way to recover from that is to boot  using your installation media and the recovery option and edit the fstab  again. The fstab also doesn&#8217;t like comment lines so much (or in my  experience &#8211; done a few recoveries myself) so try and avoid them i.e.  any lines you want to delete write down or put them into another file.<\/p>\n<p><code># vim \/etc\/fstab<br \/>\nLABEL=\/ \/ ext3 defaults 1 1<br \/>\nLABEL=boot \/boot ext3 defaults 1 2<br \/>\ntmpfs \/dev\/shm tmpfs defaults 0 0<br \/>\ndevpts \/dev\/pts devpts gid=5,mode=620 0 0<br \/>\nsysfs \/sys sysfs defaults 0 0<br \/>\nproc \/proc proc defaults 0 0<br \/>\nLABEL=SWAP-sda5 swap swap defaults 0 0<br \/>\nLABEL=apoc \/media\/apoc ext3 defaults 0 0<br \/>\nLABEL=mouse \/media\/mouse ext3 defaults 0 0<br \/>\nLABEL=morpheus \/media\/morpheus ext3 defaults 0 0<br \/>\nLABEL=switch \/media\/switch ext3 defaults 0 0<br \/>\nLABEL=trinity \/media\/trinity ext3 defaults 0 0<\/code><\/p>\n<p><strong>23.<\/strong> This blog doesn&#8217;t show the spacing every well  but the spaces are tabs. This way it&#8217;s more pleasing to the eye to  understand. To insert in vim press &#8220;i&#8221; and arrow to the end of the  bottom line and press enter. Then to save and quit press &#8220;Esc&#8221; and type  &#8220;:wq!&#8221;<br \/>\n<strong>24. <\/strong>Now would be the time to reboot your  computer and make sure it boots correctly. I&#8217;ve done this some many  times I won&#8217;t because I know my fstab is correct &#8211; many wrongs do make a  right \ud83d\ude42 rebooting means if it fails you know what you did last and can  hopefully fix it &#8211; with your installation media.<\/p>\n<p>Well that&#8217;s the  complete installation process on a linux system. In my case I use  fedora but most linux systems work with these commands.<\/p>\n<p>I hope I&#8217;ve been a help to a couple of people<\/p>\n<p>Enjoy your new hard drive space.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well every time I add a hard drive to my server. It&#8217;s always such a long time between that I forget how to do it. Lucky I&#8217;ve bookmarked a few sites on how to do it. But that&#8217;s just it a few sites, not one that explains the whole process. Well there most likely is &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/www.lanchbury.au\/?p=50\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[12],"tags":[],"class_list":["post-50","post","type-post","status-publish","format-standard","hentry","category-how-to","item-wrap"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7tC7P-O","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=50"}],"version-history":[{"count":4,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions"}],"predecessor-version":[{"id":317,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=\/wp\/v2\/posts\/50\/revisions\/317"}],"wp:attachment":[{"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lanchbury.au\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}