Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add a new disk to Linux

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to add a new disk in Linux". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to add a new disk to Linux.

Add raw disks to the Linux machine

If you are using an AWS EC2 Linux server, you can add the original disk by following these steps. If you are using VMware Linux VM, you need to follow different steps to add disks. If you are running a physical rack device / blade server, adding disks will be a physical task.

Once the disk is physically / virtually connected to the Linux machine, it will be recognized by the kernel and ready to begin.

Identify disks added by Linux

After the original disk is connected, you need to have the kernel scan the new disk. In the new version, it is mainly done automatically by the kernel.

The only thing to do is to identify the newly added disk and its name in the kernel. There are many ways to achieve this, a few of which are listed below:

You can observe the lsblk output before and after adding / scanning the disk to get the new disk name.

Check the newly created disk files in the / dev file system. Match the timestamp of the file and disk add time.

Observe the output before and after fdisk-l adds / scans the disk to get the new disk name.

In this example, I used an AWS EC2 server and added 5GB disks to the server. My lsblk output is as follows:

[root@kerneltalks ~] # lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTxvda 202 root@kerneltalks 0 0 10G 0 disk xvda1 202 root@kerneltalks 1 0 1M 0 part └─ xvda2 202 8 0 10G 0 part / xvdf 202 8 0 10G 0 disk

You can see that xvdf is a newly added disk. The full path is / dev/xvdf.

Add a new disk in LVM

We use LVM here because it is a very flexible volume manager widely used on the Linux platform. Verify that the lvm or lvm2 package is installed on the system. If it is not installed, install the lvm/lvm2 package.

Now we will add this raw disk to the logical volume manager and create a mount point for 10GB. The commands used are as follows:

Pvcreate

Vgcreate

Lvcreate

If you want to add a disk to an existing mount point and use its space to expand the mount point, vgcreate should be replaced with vgextend.

The sample output of the session is as follows:

[root@kerneltalks ~] # pvcreate / dev/xvdf Physical volume "/ dev/xvdf" successfully created. [root@kerneltalks ~] # vgcreate vgdata / dev/xvdf Volume group "vgdata" successfully created [root@kerneltalks ~] # lvcreate-L 5G-n lvdata vgdata Logical volume "lvdata" created.

The creation of the logical volume is now complete. You need to format it with the selected file system and mount it. Select the ext4 file system here and format it using mkfs.ext4.

[root@kerneltalks] # mkfs.ext4 / dev/vgdata/lvdatamke2fs 1.42.9 (28-Dec-2013) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1310720 blocks65536 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768,98304,163840,229376,294912,819200 884736 Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done mounts the volume from the new disk at the mount point

Use the mount command to install the created and formatted 5GB logical volume on the / data mount point.

[root@kerneltalks ~] # mount / dev/vgdata/lvdata / data [root@kerneltalks ~] # df-Ph / dataFilesystem Size Used Avail Use% Mounted on/dev/mapper/vgdata-lvdata 4.8G 20m 4.6G 1% / data

Use the df command to verify the mount point. As mentioned above, you have finished it! You can add an entry to / etc/fstab to keep the mount on reboot.

You have connected the 10GB disk to the Linux computer and created the 5GB mount point!

At this point, I believe you have a deeper understanding of "how to add a new disk in Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report