add second hard disk on linux server

From WebHostingNeeds.com
Jump to: navigation, search

On a new server, second hard disk was not mounted, fdisk -l shows the hard disk.


fdisk

[email protected] [/home]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       60670   487227352+  83  Linux
/dev/sda3           60671       60801     1052257+  82  Linux swap / Solaris

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
[email protected] [/home]


Create Partition

For bigger HDD, use parted, it is better than fdisk, same commands like fdisk.

[email protected] [/home]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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 60801.
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): 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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-60801, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-60801, default 60801):
Using default value 60801

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60801   488384001   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[email protected] [/home]#
[email protected] [/home]# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14       60670   487227352+  83  Linux
/dev/sda3           60671       60801     1052257+  82  Linux swap / Solaris

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       60801   488384001   83  Linux
[email protected] [/home]#

Create File System

Format the disk with ext4 file system.

mkfs.ext4 /dev/sdb1
[[email protected] ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
18276352 inodes, 73103774 blocks
3655188 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2231 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[[email protected] ~]#

Mount New Partition

[email protected] [/home]# mkdir /backup
[email protected] [/home]# mount /dev/sdb1 /backup

Lets test

[email protected] [/home]# cd /backup
[email protected] [/backup]# echo "1" > 1.txt
[email protected] [/backup]# ls -la
total 32
drwxr-xr-x  3 root root  4096 Mar 29 17:02 ./
drwxr-xr-x 26 root root  4096 Mar 29 16:36 ../
-rw-r--r--  1 root root     2 Mar 29 17:02 1.txt
drwx------  2 root root 16384 Mar 29 16:59 lost+found/
[email protected] [/backup]# cd ..
[email protected] [/]# umount /backup
[email protected] [/]# ls -l /backup
total 12
drwxr-xr-x  2 root root 4096 Mar 29 16:36 ./
drwxr-xr-x 26 root root 4096 Mar 29 16:36 ../
[email protected] [/]#

After unmount, the file we created missing, because it is actually created in the mounted hdd, not in folder /backup/


Add Entry in fstab

vi /etc/fstab

Add following line

/dev/disk/by-uuid/UUID-OF-DISK-HERE               /backup                 ext4    defaults        1 2

Example

[[email protected] ~]# cat /etc/fstab | grep backup
/dev/disk/by-uuid/23eec71b-4954-4608-ada5-4f011f688325               /backup                 ext4    defaults        1 2
[[email protected] ~]# 


OR

/dev/sdb1               /backup                 ext4    defaults        1 2

Now run "mount -a" to mount all partitions.

[email protected] [/]# mount -a
[email protected] [/]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             451G  5.2G  422G   2% /
/dev/sda1              99M   18M   77M  19% /boot
tmpfs                 4.0G     0  4.0G   0% /dev/shm
/usr/tmpDSK           485M   13M  447M   3% /tmp
/dev/sdb1             459G  199M  435G   1% /backup
[email protected] [/]#

Now you can see /backup available.



fdisk

parted

blkid

hard disk

server setup