How to Add, Format and Mount new disks in Linux Server?

By mallik034vismobang14 Mar 202014 min read

>>> Adding
a disk in Linux Server.
>>> Formatting
a disk in Linux Server.
>>> Mounting
the disk in Linux Server.

When
you insert new storage into linux server or attach raw storage
into linux box. You can see those hard disks under /dev location as
show below

Here sda is
system disk and sdb is newly added disk.

[root@oel5-testdb
dev]# ls -ltr sd*
brw-r—–
1 root disk 8,  0 Jun  7 19:37 sda
brw-r—–
1 root disk 8,  2 Jun  7 19:37 sda2
brw-r—–
1 root disk 8, 16 Jun  7 19:37 sdb
brw-r—–
1 root disk 8,  1 Jun  7 19:37 sda1

How to
find the newly added disk. Below command shows which disk is newly added to
server

[root@oel5-testdb
dev]# fdisk -l
Disk
/dev/sda: 21.4 GB, 21474836480 bytes
255
heads, 63 sectors/track, 2610 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes

   Device
Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux  ——————-
This indicates sda is old disk
/dev/sda2              14        2610    20860402+  8e  Linux
LVM

Disk
/dev/sdb: 21.4 GB, 21474836480 bytes
255
heads, 63 sectors/track, 2610 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes

Disk
/dev/sdb doesn’t contain a valid partition
table   —————– This indicates sdb is new
disk

Disk
/dev/dm-0: 19.2 GB, 19226689536 bytes
255
heads, 63 sectors/track, 2337 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes

Disk
/dev/dm-0 doesn’t contain a valid partition table
Disk
/dev/dm-1: 2113 MB, 2113929216 bytes
255
heads, 63 sectors/track, 257 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes
Disk
/dev/dm-1 doesn’t contain a valid partition table

[root@oel5-testdb
dev]# fdisk -l /dev/sdb
Disk
/dev/sdb: 21.4 GB, 21474836480 bytes
255
heads, 63 sectors/track, 2610 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes

Disk
/dev/sdb doesn’t contain a valid partition table

[root@oel5-testdb
dev]# fdisk -l /dev/sda
Disk
/dev/sda: 21.4 GB, 21474836480 bytes
255
heads, 63 sectors/track, 2610 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        2610    20860402+  8e  Linux
LVM


Format
the newly added disk which was identified from Step2 using below command.

[root@oel5-testdb
dev]# 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 2610.
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): p   
——————————————-
Print the current partitions if any

Disk
/dev/sdb: 21.4 GB, 21474836480 bytes
255
heads, 63 sectors/track, 2610 cylinders
Units =
cylinders of 16065 * 512 = 8225280 bytes

   Device
Boot      Start         End      Blocks   Id  System

Command
(m for help): n
——————————————— Create new
partitions
Command
action
   e   extended
   p   primary
partition (1-4)
p   —————————————————————————
Primary partition
Partition
number (1-4): 1
First
cylinder (1-2610, default 1):
Using
default value 1
Last
cylinder or +size or +sizeM or +sizeK (1-2610, default 2610):
Using
default value 2610

Command
(m for help): w
——————————————- Save new partition
The
partition table has been altered!

Calling ioctl()
to re-read partition table.
Syncing
disks.
[root@oel5-testdb
dev]#

Verify
newly formatted disk.

[root@oel5-testdb
dev]# ls -ld sd*
brw-r—–
1 root disk 8,  0 Jun  7 19:37 sda
brw-r—–
1 root disk 8,  1 Jun  7 19:37 sda1
brw-r—–
1 root disk 8,  2 Jun  7 19:37 sda2
brw-r—– 1 root disk 8, 16 Jun  7 19:46 sdb
brw-r—– 1 root disk 8, 17 Jun  7 19:46 sdb1 —————– Newly created partition


Check
the current system filesystem format

[root@oel5-testdb
dev]# cat /etc/fstab
/dev/VolGroup00/LogVol00
/                       ext3    defaults        1
1
LABEL=/boot             /boot                   ext3    defaults        1
2
————– ext3 filesyetem format
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
/dev/VolGroup00/LogVol01
swap                    swap    defaults        0
0

Format
the newly create partition with filesystem type identified in Step5

[root@oel5-testdb
dev]# mkfs -t ext3 /dev/sdb
mke2fs
1.39 (29-May-2006)
/dev/sdb is
entire device, not just one partition!
Proceed
anyway? (y,n) y
Filesystem label=
OS
type: Linux
Block
size=4096 (log=2)
Fragment
size=4096 (log=2)
2621440 inodes,
5242880 blocks
262144
blocks (5.00%) reserved for the super user
First
data block=0
Maximum filesystem blocks=4294967296
160
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

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

This filesystem will
be automatically checked every 23 mounts or
180
days, whichever comes first.  Use tune2fs -c or -i to override.
[root@oel5-testdb
dev]#


Create
new directory /orabin and mount the newly formatted filesystem under
/orabin directory

[root@oel5-testdb
dev]# mkdir /orabin
[root@oel5-testdb
dev]# chmod 777 /orabin/
[root@oel5-testdb
dev]# mount /dev/sdb
sdb   sdb1  

[root@oel5-testdb
dev]# mount /dev/sdb /orabin/

[root@oel5-testdb
dev]# df -h
Filesystem            Size  Used
Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       18G   13G  4.0G  77%
/
/dev/sda1              99M   40M   55M  43%
/boot
tmpfs                 497M     0  497M   0%
/dev/shm
/dev/sdb               20G  173M   19G   1%
/orabin   ————————– New mount point mounted
[root@oel5-testdb
dev]#

Add
the filesystem and mount options in /etc/fstab to reflect mount
as permanent.

[root@oel5-testdb
~]# cat /etc/fstab
/dev/VolGroup00/LogVol00
/                       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
/dev/VolGroup00/LogVol01
swap                    swap    defaults        0
0
[root@oel5-testdb
~]#

[root@oel5-testdb
~]# vi /etc/fstab

[root@oel5-testdb
~]# cat /etc/fstab
/dev/VolGroup00/LogVol00
/                       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
/dev/VolGroup00/LogVol01
swap                    swap    defaults        0
0
/dev/sdb                /orabin                 ext3    defaults        1
1 —————— added this entry 
[root@oel5-testdb
~]#

[root@oel5-testdb
~]# mount -a

[root@oel5-testdb
~]# df -h
Filesystem            Size  Used
Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       18G   13G  4.0G  77%
/
/dev/sda1              99M   40M   55M  43%
/boot
tmpfs                 497M     0  497M   0%
/dev/shm
Shared_Drive          238G  173G   66G  73%
/media/sf_Shared_Drive
Shared_Drive          238G  173G   66G  73%
/Shared_Drive/
/dev/sdb               20G  173M   19G   1%
/orabin


Regards,
Mallik

M
Mallikarjun Ramadurg

Oracle ACE Pro • Oracle SME & Founder of Vismo Technologies. Sharing practical Oracle DBA, RAC and Exadata knowledge.

Get the weekly Vismo digestNew Oracle articles and Q&A in your inbox. No spam.

One email a week. Unsubscribe any time.