How to Add a New Disk new partition in centos7

yuanqc發表於2018-10-17

How to Add a New Disk new partition?


  1. you can check the new disk using 'fdisk -l'


[root@cent7-64-1 ~]# fdisk -l

Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 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 label type: dos
Disk identifier: 0x000bbd47

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    16777215     7339008   8e  Linux LVM

Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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


 2. Create partition on the disk using 'fdisk /dev/sdb'

[root@cent7-64-1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-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 disklabel with disk identifier 0x699cde48.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079
Partition 1 of type Linux and of size 40 GiB is set

Command (m for help): p

Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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 label type: dos
Disk identifier: 0x699cde48

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    83886079    41942016   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


3. Create pv and add it in the existing volumegroup


[root@cent7-64-1 ~]# partprobe
[root@cent7-64-1 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@cent7-64-1 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos_cent7-64-1
  PV Size               <7.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              1791
  Free PE               0
  Allocated PE          1791
  PV UUID               NaETsH-EFN1-UmrX-nWEH-1Plr-SvfI-hdIzZ8

  "/dev/sdb1" is a new physical volume of "<40.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name
  PV Size               <40.00 GiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               eSerd5-aZV1-vM4L-eAVT-rcWz-bwk7-NPDcQ4

 
  [root@cent7-64-1 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_cent7-64-1
  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               <7.00 GiB
  PE Size               4.00 MiB
  Total PE              1791
  Alloc PE / Size       1791 / <7.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               eLROtx-hpVW-m64X-BEHk-fQOC-2x1c-M1bYh4

[root@cent7-64-1 ~]# vgextend centos_cent7-64-1 /dev/sdb1
  Volume group "centos_cent7-64-1" successfully extended

[root@cent7-64-1 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_cent7-64-1
  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               46.99 GiB
  PE Size               4.00 MiB
  Total PE              12030
  Alloc PE / Size       1791 / <7.00 GiB
  Free  PE / Size       10239 / <40.00 GiB
  VG UUID               eLROtx-hpVW-m64X-BEHk-fQOC-2x1c-M1bYh4


4. Create new LV and make xfs format on that


[root@cent7-64-1 ~]# lvcreate -L +39G centos_cent7-64-1
  Logical volume "lvol0" created.


[root@cent7-64-1 ~]# mkfs.xfs /dev/mapper/centos_cent7--64--1-lvol0
meta-data=/dev/mapper/centos_cent7--64--1-lvol0 isize=512    agcount=4, agsize=2555904 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=10223616, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=4992, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0



5.And added below line in the fstab
/dev/mapper/centos_cent7--64--1-lvol0  40874496   32944  40841552   1% /apps

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10973950/viewspace-2216688/,如需轉載,請註明出處,否則將追究法律責任。

相關文章