- How to Add a New Disk Drive to a Linux Machine
- Contents
- Mounted File-systems or Logical Volumes
- Getting Started
- Finding the New Hard Drive in RHEL 6.x
- Creating Linux Partitions
- Creating a File System on an RHEL 6.X Disk Partition
- Mounting a Filesystem
- Configuring RHEL 6 to Automatically Mount a File System
- How to Add New Disks Using LVM to an Existing Linux System
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to add new disk in Linux
- Adding raw disk to Linux machine
- Identifying newly added disk in Linux
- Add new disk in LVM
- Mounting volume from new disk on mount point
- Add an Additional Disk Drive to Your Linux Computer
- Disk Partition Notes:
How to Add a New Disk Drive to a Linux Machine
This article helps you to configure and add a new disk to the Linux box. This is one of the most common problems encountered by system administrators these days since the servers are tending to run out of disk space to store excess data. Fortunately, disk space is now one of the cheapest. We shall look at the steps necessary to configure on Red Hat Enterprise Linux 6. x to add more space by installing the disk.
Contents
- Mounted Filesystems or Logical Volumes
- Getting Started
- Finding the New Hard Drive in RHEL 6
- Creating Linux Partitions
- Creating a Filesystem on an RHEL 6 Disk Partition
- Mounting a Filesystem
- Configuring RHEL 6 to Automatically Mount a Filesystem
Mounted File-systems or Logical Volumes
One very simplest method is to create a Linux partition on the new disk. Create a Linux file system on those partitions and then mount the disk at a specific mount point so that they can be accessed.
Getting Started
This article assumes that the new physical hard drive has been installed on the system and is visible to the operating system.
Finding the New Hard Drive in RHEL 6.x
Assuming the drive as visible to the BIOS, it should automatically be detected by the operating system. Typically, the disk drives in a system are assigned to a device name beginning with hd or sd followed by a letter to indicate the device number. For example, the first device might be /dev/sda, the second /dev/sdb and so on.
The following is the output from a system with only one physical disk drive –
This shows that the disk drive is represented by /dev/sda itself divided into 2 partitions, represented by /dev/sda1 and /dev/sda2. The following would be the output for the same system if we attach second hard disk drive.
As shown above, the new hard drive has been assigned to the device file /dev/sdb. Currently, the drive has no partitions shown (because we have yet to create any).
At this point, we have a choice of creating partitions and file systems on the new drive and mounting them for access or adding the disk as a physical volume as part of a volume group.
Creating Linux Partitions
The next step is to create one or more Linux partitions on the new disk drive. This is achieved using the fdisk utility which takes as a command-line argument on the device to be partitioned.
As we can see from the above, the fdisk output of the disk currently has no partitions because it is a previously unused disk. The next step is to create a new partition on the disk, a task which is performed by entering “n” (for new partition) and “p” (for primary partition)
In this example, we only plan to create one partition which will be partition 1. Next, we need to specify where the partition will begin and end. Since, this is the first partition, we need to start at the first available sector and as we want to use the entire disk to specify the last sector at the end. Note that, if you wish to create multiple partitions, you can specify the size of each partition by sectors, bytes, kilobytes or megabytes.
If we now look at the devices again we will see that the new partition is visible as /dev/sdb1:
The next step is to create a filesystem on our new partition.
Creating a File System on an RHEL 6.X Disk Partition
We now have a new disk installed, it is visible to RHEL 6 and we have configured a Linux partition on the disk. The next step is to create a Linux file system on the partition so that the operating system can use it to store files and data. The easiest way to create a file system on a partition is to use the mkfs.ext4 utility which takes as arguments the label and the partition device
This filesystem checks automatically after 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Mounting a Filesystem
Now that we have created a new filesystem on the Linux partition of our new disk drive, we need to mount it so that it is accessible. In order to do this we need to create a mount point. A mount point is simply a directory or folder into which the filesystem will be mounted. For the purposes of this example, we will create a /backup directory to match our filesystem label (although it is not necessary that these values match)
The file system may then be manually mounted using the mount command
Running the mount command with no arguments shows us all currently mounted filesystems (including our new filesystem):
Configuring RHEL 6 to Automatically Mount a File System
In order to configure the system so that the new disk is automatically mounted at the time boot we need an entry to be added to the /etc/fstab file.
The below is the sample configuration file which shows an fstab file configured to auto mount our /backup partition
After this configuration and demo, we can add new disks to the existing Linux machine without any issues and extends the space for storing the backups with another drive with easy steps. Hope this information helps!
Источник
How to Add New Disks Using LVM to an Existing Linux System
LVM (Logical Volume Management) is a flexible and advanced option available to manage hard disks in most of the major Linux distributions. It is easy to manage the disks with LVM than the tradition tools like fdisk, parted or gparted.
Some of the terms which you need to understand while using LVM:
- Physical Volume (PV): Consists of Raw disks or RAID arrays or other storage devices.
- Volume Group (VG): Combines the physical volumes into storage groups.
- Logical Volume (LV): VG’s are divided into LV’s and are mounted as partitions.
In this article, we will take you through the steps to configure Disks using LVM in existing Linux machine by creating PV, VG’s and LV’s.
Note: If you don’t what to use LVM, you can add disk directly to an existing Linux system using these guides.
Let’s consider a scenario where there are 2 HDD of 20GB and 10GB, but we need to add only 2 partitions one of 12GB and another 13GB. We can achieve this using LVM method only.
Once the disks has been added, you can list them using the following command.
Verify Hard Disks
1. Now partitions both the disks /dev/xvdc and /dev/xvdd using fdisk command as shown.
Use n to create the partition and save the changes with w command.
Partition Hark Disks
2. After partitioning, use the following command to verify the partitions.
Verify New Partitions
3. Create Physical Volume (PV).
Create Physical Volume
4. Create Volume Group (VG).
Here, “testvg” is the VG name.
Create Volume Group
5. Now use “vgdisplay” to list all details about the VG’s in the system.
List Volume Group
6. Create Logical Volumes (LV).
Here, “lv_data1” and “lv_data2” are LV name.
Create Logical Volumes
7. Now use “lvdisplay” to list all details about the Logical volumes available in the system.
List Logical Volumes
8. Format the Logical Volums (LV’s) to ext4 format.
Format LV to Ext4 Format
9. Finally, mount the file system.
Make sure to create data1 and data2 directories before mounting the filesystem.
Mount Filesystem
That’s it! In this article, we discussed how to create a partition using LVM. If you have any comments or queries regarding this, feel free to post in the comments.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How to add new disk in Linux
Published: March 20, 2019 | Modified: June 24, 2020
Step by step procedure to add disk in Linux machine
In this article, we will walk you through steps to add a new disk in the Linux machine. Adding a raw disk to the Linux machine may vary depending upon the type of server you have but once the disk is presented to the machine, the procedure of getting it to mount points is almost the same.
Objective: Add a new 10GB disk to the server and create a 5GB mount point out of it using LVM and newly created volume group.
Adding raw disk to Linux machine
If you are using the AWS EC2 Linux server, you may follow these steps to add raw disk. If you are on VMware Linux VM you will have a different set of steps to follow to add disk. If you are running a physical rack-mount/blade server then adding disk will be a physical task.
Now once the disk is attached to the Linux machine physically/virtually, it will be identified by the kernel and then our rally starts.
Identifying newly added disk in Linux
After the attachment of the raw disk, you need to ask the kernel to scan a new disk. Mostly it’s done now automatically by the kernel in new versions.
First thing is to identify the newly added disk and its name in the kernel. There are numerous ways to achieve this. I will list a few –
- You can observer lsblk output before and after adding/scanning disk to get a new disk name.
- Check newly created disk files in /dev filesystem. Match timestamp of file and disk addition time.
- Observer fdisk -l output before and after adding/scanning disk to get a new disk name.
For our example, I am using the AWS EC2 server and I added 5GB disk to my server. here is my lsblk output –
You can see xvdf is our newly added disk. Full path for disk is /dev/xvdf .
Add new disk in LVM
We are using LVM here since its widely used and flexible volume manager on the Linux platform. Make sure you have lvm or lvm2 package installed on your system. If not, install lvm/lvm2 package.
Now, we are going to add this RAW disk in Logical Volume Manager and create 10GB of mount point out of it. List of commands you need to follow are –
If you are willing to add a disk to the existing mount point and use its space to extend mount point then vgcreate should be replaced by vgextend .
Sample outputs from my session –
Now, you have a logical volume created. You need to format it with the filesystem on your choice and mount it. We are choosing ext4 filesystem here and formatting using mkfs.ext4 .
Mounting volume from new disk on mount point
Lets mount the logical volume of 5GB which we created and formatted on /data mount point using mount command.
Verify your mount point with df command as above and you are all done! You can always add an entry in /etc/fstab to make this mount persistent over reboots.
You have attached a 10GB disk to the Linux machine and created a 5GB mount point out of it!
Источник
Add an Additional Disk Drive to Your Linux Computer
Related YoLinux Tutorials:
Prerequisite: This tutorial covers adding a new disk drive to your linux computer. First it is assumed that the hard drive was physically added to your system.
SATA drives are connected via a dedicated cable of seven conductors of which there are two pairs dedicated to data with the remaining 3 being ground. SATA drives represent the predominat and current technology.
Linux SATA naming convention: /dev/sda, /dev/sdb, .
IDE based systems, can support two drives on each ribbon cable. The cable is attached to either the Primary or Secondary IDE controller. A «jumper» is pressed onto two pins (thus connecting the two pins) on the drive to define the drive as a «Master» or a «Slave» drive. Each cable can support one master and one slave drive. Typically new desktop systems have one hard drive connected as a Master on the Primary controller and one CD-Rom on the second cable configured as a master.
Linux IDE naming convention: /dev/hda, /dev/hdb, .
SCSI drives will have jumpers positioned to assign a SCSI device ID number typically numbered 1-8. A sticker on the top of the drive will often show a diagram of jumper placement for drive assignment.
Linux SCSI naming convention: /dev/sda, /dev/sdb, .
IDE drives are referred to as hda for the first drive, hdb for the second etc. IDE uses separate ribbon cables for primary and secondary drives. The partitions on each drive are referred numerically. The first partition on the first drive is referred to as hda1, the second as hda2, the third as hda3 etc .
Linux IDE naming conventions:
Device | Description | Configuration |
---|---|---|
/dev/hda | 1st (Primary) IDE controller | Master |
/dev/hdb | 1st (Primary) IDE controller | Slave |
/dev/hdc | 2nd (Secondary) IDE controller | Master |
/dev/hdd | 2nd (Secondary) IDE controller | Slave |
Note: SCSI disks are labeled /dev/sda, /dev/sdb, /dev/sdc etc. to represent the first, second, third. SCSI hard drive devices but not the SCSI ID. SCSI hard drive partitions are represented by an additional number. i.e. First drive first partition, /dev/sda1, second partition, /dev/sda2. Other SCSI devices such as tape backup are labeled /dev/st0 for the first, /dev/st1 for the second and so forth. See YoLinux SCSI tutorial for more info.
Disk Partition Notes:
- Partitions are defined and generated with fdisk
- Each hard drive may only have a maximum of four primary partitions (MBR limit: 1-4). One can add more partitions using extended partitions. Multiple logical partitions can then be added to each extended partition (5-20).
- Extended partitions allow one to place up to 24 partitions on a single drive.
- One may only boot an OS from a primary partition. A computer system may have multiple drives with primary partitions but only one primary partition may be active on one drive only. The active primary partition is used for booting the system and is referenced by the Master Boot Record (MBR).
- Creating a primary partition:
- [root]$ fdisk /dev/sda
- n (add a new partition)
- p (new partition will be a primary partition. Options are e or p)
- 1 (define partition number. 4 primary partitions allowed)
- Creating and extended partition containing logical partitions
- [root]$ fdisk /dev/sda
- n (add a new partition)
- e (new partition will be an extended partition. Options are e or p)
- w (Write and save partition table)
- n (add a new partition)
- l (new partition will be a logical partition. Options are l or p)
- Define sector or accept default (first free sector)
- Define last sector or sector size in (K)ilobyte (M)egabytes, (G)igabytes or accept default to use up the remaining space on drive.
- w (Write and save partition table)
As root perform the following: (as highlighted in bold)
Note:
- Partition size: K = Kilobyte M = Megabyte, G= Gigabyte
Example, Last cylinder expressed in size: +500M - If replacing a failed drive you will probably be in single user mode with a read only drive and may want to match the previous UUID so it boots seamlessly:
mkfs.ext4 -L disk2 -U /dev/sdb1
where the the UUID is obtained by looking in /etc/fstab
This will allow the replacement drive to mount just as if it was the old drive it is replacing.
Example /etc/fstab entry with a UUID:
UUID=7cb6e598-f639-488e-85c3-2a09d1440008 /share ext4 defaults 1 1
[Potential Pitfall] : If you get the following mkfs ext4 formatting error: This occurs when you try and format an extended partition directly rather than a primary partition. Unlike the IDE example below with ext3 (RHEL5), this SATA ext4 configuration requires a primary partition. The extended partition contains its own partition table and is a container for other logical partitions. To format the extended partition, add logical partitions to the extended partition and format these logical partitions.
As root perform the following: (as highlighted in bold)
The above example shows the addition of a drive as one whole extended partition used to extend the storage space of the system. It was not created to hold additional operating systems as this would require a primary partition. Primary partitions can be used to extend the storage space of the system as well. It is not precluded from such a function but it will then limit you to four partitions for that hard drive.
Enter the drive into the fstab file so that it is recognized and mounted upon system boot.
File: /etc/fstab Red Hat 8.0
The digits «1 2» refer to whether the mount point should be backed up when the dump command is used and disk integrity checks using fsck. The «1» states that it should be backed up when the dump command is issued (0=no). The «2» refers to the order in which «fsck» should check the mount points. The digit «1» identifies the root («/») of the filesystem. All others should be «2». (0=no check)
Also see: fstab man page for a description of all options.
- YoLinux Tutorial: System Administration — [Filesystems and drives]
- YoLinux Tutorial: System optimization — Hard drive performance optimizations
- Hard Drive Partitions — Definitions
- Partitions — Tools, best practices, explanations
- Man pages:
- e2label — Add label to hard drive: e2label /dev/hdb EXTRA_DRIVE
Note: Labels support up to 16 characters. - fdisk — Manipulate/configure the partition table.
- sfdisk — Manipulate/configure the partition table.
- cfdisk — Curses based disk partition table manipulator.
- mkfs — Build Linux file system. (Actually a front-end to various file system builders for various file system types.)
- mkswap — format partition as a swap partition
- mke2fs — Create a Linux second extended file system.
- tune2fs — Adjust file system parameters on a second extended filesystem. Convert ext2 to ext3, add volume label (-L), .
- mount — Mount a file system
- fstab — Configuration file for mounting filesystems.
- lsblk — list block devices
- e2label — Add label to hard drive: e2label /dev/hdb EXTRA_DRIVE
Источник