Well every time I add a hard drive to my server. It’s always such a long time between that I forget how to do it. Lucky I’ve bookmarked a few sites on how to do it. But that’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.
PLEASE NOTE: 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’s no hurry. It took me 2 days (over Christmas) so take your time like I did.
1. Well the very first thing is shut down the machine and install the hard drive, simple enough.
2. Turn it back on and allow it to boot normally.
3. Open a terminal window or login a shell
4. su to root access
5. Next we want to see if linux has found it. Depending on your hardware it could be sd* or hd* as below
# ls /dev/sd*
/dev/sda /dev/sda3 /dev/sdb /dev/sdc1 /dev/sde1
/dev/sda1 /dev/sda4 /dev/sdb1 /dev/sdd /dev/sdf
/dev/sda2 /dev/sda5 /dev/sdc /dev/sde /dev/sdf1
6. 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.
7. 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.
# /sbin/fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x9ab04e42.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
The number of cylinders for this disk is set to 121601.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help):
8. As it says there ‘m’ for help. So if I miss something you want, do that.
9. One thing I like to do is make sure there is nothing on the drive. This also makes me list were I’m at in my own head, plus makes sure your not on the wrong drive
Command (m for help): p
Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x9ab04e42
Device Boot Start End Blocks Id System
10. 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.
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-121601, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601):
Using default value 121601
11. I through a lot into there. N to create a new partition. P to select it as the primary as there isn’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.
Command (m for help): p
Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xed679c51
Device Boot Start End Blocks Id System
/dev/sdd1 1 121601 976760001 83 Linux
12. One again it’s good to see what you’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
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#
13. Don’t be too worried how long this step takes.
14. 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
# ls /dev/sd*
/dev/sda /dev/sda3 /dev/sdb /dev/sdc1 /dev/sde /dev/sdf1
/dev/sda1 /dev/sda4 /dev/sdb1 /dev/sdd /dev/sde1
/dev/sda2 /dev/sda5 /dev/sdc /dev/sdd1 /dev/sdf
15. 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.
# /sbin/mkfs.ext3 /dev/sdd1
mke2fs 1.40.4 (31-Dec-2007)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122109952 inodes, 244190000 blocks
12209500 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
7453 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Writing inode tables: ####/7453
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
16. 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’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.
# /sbin/e2label /dev/sdd1 trinity
17. 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
# mkdir /media/trinity/
18. I’ve just learnt during the writing of the a script called devlabel that makes a symbolic link for the hard drive. It’s come out in fedora 12 and I’m running Fedora 8 on this server. Yes yes I need to upgrade, hopefully over this Christmas break I’ll get to it. So hopefully I’ll change this when I find out more -your welcome to if you want.
19. OK, OK, Let mount this drive.
# mount LABEL=trinity /media/trinity/
20. Well that’s the hard bit done to see how much space you’ve got now
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 71G 55G 12G 83% /
/dev/sda1 190M 47M 134M 26% /boot
tmpfs 1.5G 396K 1.5G 1% /dev/shm
/dev/sde1 917G 775G 97G 89% /media/apoc
/dev/sdf1 917G 772G 99G 89% /media/mouse
/dev/sdc1 688G 645G 8.2G 99% /media/morpheus
/dev/sdb1 459G 369G 67G 85% /media/switch
/dev/sdd1 917G 200M 871G 1% /media/trinity
21. The question is how long will it last 🙂
22. 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’t like comment lines so much (or in my experience – 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.
# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda5 swap swap defaults 0 0
LABEL=apoc /media/apoc ext3 defaults 0 0
LABEL=mouse /media/mouse ext3 defaults 0 0
LABEL=morpheus /media/morpheus ext3 defaults 0 0
LABEL=switch /media/switch ext3 defaults 0 0
LABEL=trinity /media/trinity ext3 defaults 0 0
23. This blog doesn’t show the spacing every well but the spaces are tabs. This way it’s more pleasing to the eye to understand. To insert in vim press “i” and arrow to the end of the bottom line and press enter. Then to save and quit press “Esc” and type “:wq!”
24. Now would be the time to reboot your computer and make sure it boots correctly. I’ve done this some many times I won’t because I know my fstab is correct – many wrongs do make a right 🙂 rebooting means if it fails you know what you did last and can hopefully fix it – with your installation media.
Well that’s the complete installation process on a linux system. In my case I use fedora but most linux systems work with these commands.
I hope I’ve been a help to a couple of people
Enjoy your new hard drive space.
1 pings
[…] as this website server was one of the ones affected, I had to, where normally I would look at my Adding a HDD to Linux post. No […]