How to add second hdd (additional hard drive) in Ubuntu 14.04 (Linux) Step-by-step


This guide is for people who want to add Second Hard Drive and need help configuring it to work with their Linux Server. I’ll be logged in as root.
Step 1 – Update repositories.
root@mail:/# apt-get update
root@mail:/# apt-get upgrade
Step 2 – Show all hdd with the following command fdisk -l and you will see something similar to this:
root@mail:/# fdisk -l
Disk /dev/sda: 160.0 GB, 160041885696 bytes 255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000d94a0
Device Boot Start End Blocks Id System /dev/sda1 * 2048 296534015 148265984 83 Linux /dev/sda2 296536062 312580095 8022017 5 Extended /dev/sda5 296536064 312580095 8022016 82 Linux swap / Solaris
Disk /dev/sdb: 160.0 GB, 160000000000 bytes 58 heads, 29 sectors/track, 185790 cylinders, total 312500000 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xf5f5f5f5
Device Boot Start End Blocks Id System /dev/sdb1 2048 312499999 156248976 83 Linux
Disk /dev/sdc: 4009 MB, 4009754624 bytes 124 heads, 62 sectors/track, 1018 cylinders, total 7831552 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000001
Device Boot Start End Blocks Id System
Step 3. – I will insert USB flash drive and Linus will recognise it as sdc drive. For the example I will use this drive. If there isn’t a valid partition on your hdd, you must create it with the following commands: fdisk /dev/sdc 1 – fdisk /dev/sdc -select hdd 2 – m – print this menu 3 – p – print the partition table – If there is a valid partition on your hdd you can delete it with d 4 – n – add a new partition – 5 – p – I choose to create primary partition 6 – 1 – choose number of partition 7 – enter – Press ENTER twice to select default sectors 8 – w – write table to disk and exit
root@mail:/# fdisk /dev/sdc
Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition’s system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdc: 4009 MB, 4009754624 bytes 124 heads, 62 sectors/track, 1018 cylinders, total 7831552 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000001
Device Boot Start End Blocks Id System
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-7831551, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-7831551, default 7831551): Using default value 7831551
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
Now you have one primary partiton. Step 4 – Now you must create file system. For example I will create ext4 file system. Run the following command mkfs.ext4 /dev/sdc1
root@mail:/# mkfs.ext4 /dev/sdc1 mke2fs 1.42.9 (4-Feb-2014) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 244800 inodes, 978688 blocks 48934 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1002438656 30 block groups 32768 blocks per group, 32768 fragments per group 8160 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done
Step 5 – Now I will prepare ubuntu for permanently add hdd. We must create folder, and see block id of hdd and add in fstab. For automatically adding a hard drive after restart run the following commands:
root@mail:/# mkdir /srv/samba/secondhdd
root@mail:/# blkid /dev/sdc1 /dev/sdc1: UUID=”7a8fc443-e4c3-47c2-9d59-4f0ebd690e09? TYPE=”ext4?
root@mail:/# nano /etc/fstab
add the following line of the end
UUID=dd2bc94e-aedc-4ba7-9587-f74f7cf0a444 /srv/samba/secondhdd ext4 defaults 0 0
Run follow commands for re-mount hdd
root@mail:/# mount -o
Step 6 – Run df -h
root@mail:/# df -h
Filesystem        Size        Used        Avail        Use%  Mounted  on /dev/sda1       140G        8.1G       124G           7%        / none                 4.0K        0        4.0K              0%            /sys/fs/cgroup udev                 3.8G        8.0K        3.8G              1%            /dev tmpfs                 767M        836K        766M              1%            /run none                 5.0M;       0        5.0M              0%            /run/lock none                 100M;       0        100M              0%            /run/shm /dev/sdc1      3.7G;       7.5M        3.5G              1%            /srv/samba/secondhdd
Now you have added second hdd. After restart hdd will be added automatically.
Posts Contents: Download More Blogspot contents(Posts) for you site

Comments