Advance

Tutorial add a new disk to Linux server

Tutorial add a new disk to Linux server
0
(0)

As system administration, you need to know how to configure raw hard disks to the existing servers. In this article, you are going to learn tutorial add a new disk to Linux server. In the following, you see how to add a new disk to the existing servers as part of upgrading server capacity or sometimes disk replacement in case of disk failure. So join us to see the way you can add the new raw hard disk to an existing Linux server such as RHEL/CentOS or Debian/Ubuntu.

 

Prerequisites

The tutorial may be more useful if you know:

  • Please consider that you will learn only to create a new partition and not any partition extension or other switches.
  • Use fdisk utility to do this configuration.
  • To be mounted as a /data partition, add a hard disk of 20GB capacity.
Recommended Article: How to test a Secure Password

Tutorial add a new disk to Linux server

To view and manage hard disks and partitions on Linux systems, run the following command.

fdisk -l  

The partitions and configurations will list as below.

[root@Eldernode installer]# -l  Disk /dev/xvda: 107.4 GB, 107374182400 bytes, 209715200 sectors  Units = sectors of 1 * 512 bytes  Sector size (logical/physical): 512 bytes 512 bytes  I/O size (minimum/optimal): 512 bytes / 512 bytes  Disk lable type: dos  Disk identifier: 0x000969af       Device Boot     Start      End     Blocks   Id  System  /dev/xvda1    *       2048   1026047    512000   83  Linux  /dev/xvda2         1026048  209715199  104344576 8e  Linux LVM  Disk /dev/mapper/rhel-root: 104.7 GB 104681439232 bytes, 204455936 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 / dev/mapper/rhel-swap: 2164 MB, 2164260864 bytes, 4227072 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    

The fdisk -l will give the following output, after attaching the hard disk of 20GB capacity.

fdisk -l    [root@Eldernode installer]# fdisk -l  Disk /dev/xvda: 107.4 GB, 107374182400 bytes, 209715200 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   I/O size lable type: dos  Disk identifier: 0x000969af        Device Boot    Start     End    Blocks  Id  System  /dev/xvda1    *       2048    1026047  512000  83 Linux  /dev/xvda2         1026048 209715199 104344576 8e Linix LVM  Disk /dev/mapper/rhel-root: 104.7 GB, 104681439232 bytes, 204455936 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 /dev/mapper/rhel-swap: 2164 MB, 2164260864 bytes, 4227072 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 /dev/xvdc: 21.5 GB, 21474836480 bytes, 41943040 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  

You can view the newly added disk as /dev/xvdc. And if you have added physical disk, it will show as /dev/sda based on the disk type. we used a virtual disk in this tutorial.

for example /dev/xvdc, to partition a particular hard disk.

fdisk /dev/xvdc    

Buy Linux Web Hosting

In the following, you can use fdisk commands.

  • n – Create partition
  • p – print partition table
  • d – delete a partition
  • q – exit without saving the changes
  • w – write the changes and exit.

While using n option, the created partition would be as below.

[root@Eldernode installer]#  fdisk  /dev/xvdc  Welcome to fdisk (unil-linux 2.23.2).    Changes will remain in memory only, until you decide to write them.  Be careful before using the write command.    device does not contain a recognized partition table  Building a new Dos disklable with disk identifier 0xea4ddcaf    Command (m for help): n

 

Also, you are recommended to create primary/extended partitions. You can have up to 4 primary partitions by default.

Command (m for help): n  Partition type:      P    primary (0 primary, 0 extended, 4 free)      e    extended  Select   (default p): p

 

Now you are recommended to go for the default value 1. Give the partition number as desired.

Partition number (1-4, default 1) : 1

In case of using a new disk, you should always select the default value. To create a second partition on the same disk, you need to add 1 to the last sector of the previous partition.

First sector (2048-41943039, default 2048) : 2048

It is time to give the value of the last sector or the partition size. Always try to give the size of the partition and prefix + to avoid value out of range error.

Last sector, +sectors or +size{k,m,g} (2048-41943039, default 41943039) : +18G

Then save the changes and exit.

Partition 1 of type Linux and of size 18 Gib is set  Command (m for help) : w    Calling ioctl() to re-read partition table.  Syncing disk.  [root@Eldernode installer]#

 

Disk /dev/xvdc: 21.5 GB, 21474836480 bytes, 41943040 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 lable type: dos  Disk identifier : 0xea4ddcaf          Device boot     Start      End      Blocks    Id   System  /dev/xvdcl             2048  37750783 18874368      83   Linux  [root@Eldernode installer]#

 

Format the disk now with mkfs command.

mkfs.ext4 /dev/xvdc1
[root@Eldernode installer]# mkfs.ext4 /dev/xvdc1  mke2fs 1.42.9 (28-Dec-2013)  Filesystem lable=  OS type: Linux  Block size=4096 (log=2)  Fragment size=4096 (log=2)  Stride=0 blocks, Stripe width=0 blocks  1179648 inodes, 4718592 blocks  235929 blocks (5.00%) reserved for thr super user  First data block=0  Maximum filesystem blocks=2153775104  144 block groups  32768 blocks per group, 32768 fragment per group  8192 inodes per group  Superblock backups stored on blocks:        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000    Allocating group tables: done  Writting inode tables: done  Creating Journal (32768 blocks): done   Writting superblocks and filesystem accounting information: done    

Mount the partition after formatting is completed.

mount /dev/xvdc1 /data  

Now you should make an entry in /etc/fstab file for the permanent mount at boot time.

/dev/xvdc1	/data	ext4	defaults     0   0

 

Pay attention while working with the partitions especially when you are editing the configured disks.

 

Dear user, we wish this tutorial add a new disk to Linux server would be helpful for you, to ask any question or review the conversation of our users about this article, please visit Ask page. Also to improve your knowledge, there are so many useful tutorials ready for Eldernode training.

 

 

Also, see

Tutorial connect to ssh on Linux

How to work with Fping in Linux

Tutorial send messages to all users on Linux Server

 

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day