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.
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
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
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.