linux system data disk merged into the system disk

 Check it out, the current command:

df -h
[[email protected] ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs 990M 0 990M 0% / dev
tmpfs                   1001M     0 1001M   0% /dev/shm
tmpfs                   1001M   57M  944M   6% /run
Tmpfs 1001M 0 1001M 0% /sys/fs/cgroup/dev/mapper/centos-root 27G 5.8G 22G 22% / // After expansion, look at this item for comparison
/dev/sda1               1014M  154M  861M  16% /boot
tmpfs                    201M     0  201M   0% /run/user/0[[email protected] ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda 8: 0 0 30G 0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   27G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
Sdb 8:16 0 10G 0 disk // The newly added hard disk is named sdb, it already exists, but the partition is not available to the system.
sr0 11: 0 1 1024M 0 room

 

 Create a partition for the new hard disk (here a partition is created by default)

fdisk /dev/sdb
[[email protected] ~]# -linux . memory only,  you decide to  primary,  extended,  -, default -, default +sectors or +size{K,M,G} (-, default  of type Linux and of size   Empty             NEC DOS           Minix /  FAT12             Hidden NTFS Win   Linux swap / So c1  DRDOS/sec (FAT-   XENIX root        Plan             Linux           c4  DRDOS/sec (FAT-   XENIX usr       3c  PartitionMagic    OS/ hidden C:  c6  DRDOS/sec (FAT-   FAT16 <32M        Venix        Extended          PPC PReP Boot     NTFS volume set da  Non-  FAT16             SFS               NTFS volume set db  CP/M / CTOS /  HPFS/NTFS/exFAT 4d  QNX4.x            AIX             4e  QNX4.x 2nd part          AIX bootable    4f  QNX4.x 3rd part / Boot Manag   OnTrack DM        Amoeba BBT      e3  DOS R/  OnTrack DM6 Aux 9f  BSD/  CP/  OPUS              EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-  Hidden FAT12      Hidden FAT16 <   Hidden FAT16      GNU HURD or Sys af  HFS / HFS+  Hidden HPFS/NTF   AST SmartSleep    PC/ to /dev/sdb:  GB,  bytes, = sectors of  *  = /physical):  bytes / /O size (minimum/optimal):  bytes / /dev/sdb1                     help): !-

 

View the partition again, but the partition is good, not mounted, not added to the system root, can not be used

lsblk

[[email protected] ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda 8: 0 0 30G 0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   29G  0 part 
  ├─centos-root 253:0    0   27G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk 
└─sdb1            8:17   0   10G  0 part 
sr0 11: 0 1 1024M 0 room

 

Convert the new partition to a physical volume

pvcreate /dev/sdb1

[[email protected] ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

 

View the existing volume group name, here is centos

vgdisplay

[[email protected] ~]# vgdisplay 
  --- Volume group ---
  VG Name centos // This is the default VG Name under the Centos system, and the RHEL system is shown as rhel
  System ID             
  Format lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV 0
  Cur LV 2
  Open LV               2
  Max PV                0
  Cur PV 1
  Act PV                1
  VG Size <29.00 GiB //Be aware of changes in this value
  PE Size               4.00 MiB
  Total PE 7423
  Alloc PE / Size 7422 / 28.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               RNpAgN-PLQm-M4vp-E37i-fhhp-mr2z-faLm3A

 

Put the physical volume of the conversion number into vg (volume group)

vgextend centos /dev/sdb1

[[email protected] ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended

[[email protected] ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV 0
  Cur LV 2
  Open LV               2
  Max PV                0
  Cur PV 2
  Act PV                2
  VG Size 38.99 GiB //Contrast, it is about 10G
  PE Size               4.00 MiB
  Total PE 9982
  Alloc PE / Size 7422 / 28.99 GiB
  Free  PE / Size       2560 / 10.00 GiB
  VG UUID               RNpAgN-PLQm-M4vp-E37i-fhhp-mr2z-faLm3A

 

View the logical volume, the default system is divided into 2, select the corresponding logical volume path

lvdisplay

[[email protected] ~]# lvdisplay 
  --- Logical volume ---
  LV Path /dev/centos/swap //The system defaults to 2G for swap, no need to manage
  LV Name                swap
  VG Name                centos
  LV UUID w8yxWk-Qrth-x16P-jVg3-1haX-lZUH-0r1SkV
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-03-21 02:10:16 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path /dev/centos/root // extend the logical volume later, remember the path
  LV Name                root
  VG Name                centos
  LV UUID ECEWl4-0AEW-W1Tn-acE2-GLpe-NxeD-v16tGb
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-03-21 02:10:16 +0800
  LV Status              available
  # open                 1
  LV Size                26.99 GiB
  Current LE             6910
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto  - currently set to     8192
  Block device           253:0

 

Extend space for logical volumes

lvextend /dev/centos/root /dev/sdb1


[[email protected] ~]# lvextend /dev/centos/root /dev/sdb1
  Size of logical volume centos/root changed from 26.99 GiB (6910 extents) to <36.99 GiB (9469 extents).
  Logical volume centos/root successfully resized.
10. Write to the file system for the expansion to take effect.

Current command:

xfs_growfs /dev/mapper/centos-root
Copy code

[[email protected] ~]# xfs_growfs /dev/mapper/centos-root 
meta-data = / dev / mapper / centos-root help = 512 agcount = 4, agsize = 1768960 blks = sectsz = 512 attr = 2, projid32bit = 1
         =                       crc=1        finobt=0 spinodes=0data     =                       bsize=4096   blocks=7075840, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1log      =internal               bsize=4096   blocks=3455, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0data blocks changed from 7075840 to 9696256

If it is an ext system, you can use the resize2fs command to replace the xfs_growfs command.

 

Check the expansion effect

[[email protected] ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs 990M 0 990M 0% / dev
tmpfs                   1001M     0 1001M   0% /dev/shm
tmpfs                   1001M   57M  944M   6% /run
tmpfs                   1001M     0 1001M   0% /sys/fs/cgroup/dev/mapper/centos-root   37G  5.8G   32G  16% /
/dev/sda1               1014M  154M  861M  16% /boot
tmpfs                    201M     0  201M   0% /run/user/0

Compared with the original display, the expansion was successful.

 

  • 353 Users Found This Useful
Was this answer helpful?

Related Articles

How to choose the cloud server?

★ Choose the right cloud server configuration based on your actual business needs: Understand...

How do I connect to my cloud server? (including linux and windows)

First of all to distinguish between linux and windows, including ubuntu, centos, debian are...

Linux cloud server data disk expansion tutorial guide

This tutorial belongs to the data disk expansion [non-system disk] default directory /dev/sdb...

About the automatic synchronization of cloud server time, and the problem that time cannot be modified.

Recently, there have been user feedback, cloud server time cannot be modified. The solution is...

How to mount a data disk on a Linux system?

After remote SSH login to CentOS or Debian and Ubuntu series Linux servers, do the following:...