温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

centos7 磁盘重新分区怎么创建LVM并格式化

发布时间:2021-11-04 17:06:55 来源:亿速云 阅读:196 作者:柒染 栏目:建站服务器

这篇文章给大家介绍centos7 磁盘重新分区怎么创建LVM并格式化,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

1、磁盘分区,两个分两个区 一个160G,一个40G

[root@mysql innodb_log]# fdisk /dev/vdb
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.


Command (m for help): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x8510d8fb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209717247   104857600   83  Linux

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

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

Command (m for help): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x8510d8fb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209717247   104857600   83  Linux
/dev/vdb2       209717248   545261567   167772160   83  Linux
/dev/vdb3       545261568   629145599    41942016   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

2、设置格式为LVM

[root@mysql innodb_log]# fdisk -l

Disk /dev/vda: 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: 0x000be2dd

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624    20971519     9960448   8e  Linux LVM
/dev/vda3        20971520    83886079    31457280    5  Extended
/dev/vda5        20973568    83886079    31456256   8e  Linux LVM

Disk /dev/mapper/vg01-lv01: 42.4 GB, 42404413440 bytes, 82821120 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/vdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x8510d8fb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209717247   104857600   83  Linux
/dev/vdb2       209717248   545261567   167772160   83  Linux
/dev/vdb3       545261568   629145599    41942016   83  Linux


[root@mysql innodb_log]# fdisk /dev/vdb
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.


Command (m for help): t
Partition number (1-3, default 3): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@mysql innodb_log]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.


[root@mysql innodb_log]# fdisk -l

Disk /dev/vda: 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: 0x000be2dd

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624    20971519     9960448   8e  Linux LVM
/dev/vda3        20971520    83886079    31457280    5  Extended
/dev/vda5        20973568    83886079    31456256   8e  Linux LVM

Disk /dev/mapper/vg01-lv01: 42.4 GB, 42404413440 bytes, 82821120 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/vdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x8510d8fb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209717247   104857600   83  Linux
/dev/vdb2       209717248   545261567   167772160   8e  Linux LVM
/dev/vdb3       545261568   629145599    41942016   8e  Linux LVM

3、创建LVM

pv两个: /dev/vdb2  /dev/vdb3

vg一个对应:  /dev/vdb2 /dev/vdb3

lv 一个:160G 

[root@mysql innodb_log]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/vda2  vg01 lvm2 a--   <9.50g    0
  /dev/vda5  vg01 lvm2 a--  <30.00g    0
[root@mysql innodb_log]# pvcreate /dev/vdb2
WARNING: ext4 signature detected on /dev/vdb2 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/vdb2.
  Physical volume "/dev/vdb2" successfully created.
[root@mysql innodb_log]# pvcreate /dev/vdb3
  Physical volume "/dev/vdb3" successfully created.
[root@mysql innodb_log]# pvs
  PV         VG   Fmt  Attr PSize   PFree 
  /dev/vda2  vg01 lvm2 a--   <9.50g      0
  /dev/vda5  vg01 lvm2 a--  <30.00g      0
  /dev/vdb2       lvm2 ---  160.00g 160.00g
  /dev/vdb3       lvm2 ---  <40.00g <40.00g
[root@mysql innodb_log]# fdisk -l

Disk /dev/vda: 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: 0x000be2dd

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048     1050623      524288   83  Linux
/dev/vda2         1050624    20971519     9960448   8e  Linux LVM
/dev/vda3        20971520    83886079    31457280    5  Extended
/dev/vda5        20973568    83886079    31456256   8e  Linux LVM

Disk /dev/mapper/vg01-lv01: 42.4 GB, 42404413440 bytes, 82821120 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/vdb: 322.1 GB, 322122547200 bytes, 629145600 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: 0x8510d8fb

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209717247   104857600   83  Linux
/dev/vdb2       209717248   545261567   167772160   8e  Linux LVM
/dev/vdb3       545261568   629145599    41942016   8e  Linux LVM


[root@mysql innodb_log]# pvs
  PV         VG   Fmt  Attr PSize   PFree 
  /dev/vda2  vg01 lvm2 a--   <9.50g      0
  /dev/vda5  vg01 lvm2 a--  <30.00g      0
  /dev/vdb2       lvm2 ---  160.00g 160.00g
  /dev/vdb3       lvm2 ---  <40.00g <40.00g
[root@mysql innodb_log]# vgcreate vgdata01 /dev/vdb2 /dev/vdb3
  Volume group "vgdata01" successfully created


[root@mysql innodb_log]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree 
  vg01       2   1   0 wz--n-  39.49g      0
  vgdata01   2   0   0 wz--n- 199.99g 199.99g


[root@mysql innodb_log]# lvs
  LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-ao---- 39.49g                                                   
[root@mysql innodb_log]# lvcreate -L 160G -n lv02 vgdata01
  Logical volume "lv02" created.
[root@mysql innodb_log]# lvs
  LV   VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01     -wi-ao----  39.49g                                                   
  lv02 vgdata01 -wi-a----- 160.00g          

                                          
[root@mysql innodb_log]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vgdata01/lv02
  LV Name                lv02
  VG Name                vgdata01
  LV UUID                d2tSRE-tDF6-zPDV-0ACU-Qz9I-BUJJ-jPRoT1
  LV Write Access        read/write
  LV Creation host, time mysql.novalocal, 2020-02-26 13:11:12 +0800
  LV Status              available
  # open                 0
  LV Size                160.00 GiB
  Current LE             40960
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
  --- Logical volume ---
  LV Path                /dev/vg01/lv01
  LV Name                lv01
  VG Name                vg01
  LV UUID                pErBl0-TR5d-xPSz-CYfY-hT3V-7FWp-QRPbAf
  LV Write Access        read/write
  LV Creation host, time localhost, 2019-09-16 19:31:11 +0800
  LV Status              available
  # open                 1
  LV Size                39.49 GiB
  Current LE             10110
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   

4、格式化


[root@mysql innodb_log]# mkfs.ext4 /dev/vgdata01/lv02
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
10485760 inodes, 41943040 blocks
2097152 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2189426688
1280 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done    

5、写入启动文件

[root@mysql innodb_log]# df -h

Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01   39G  4.8G   33G  13% /
devtmpfs               7.8G     0  7.8G   0% /dev
tmpfs                  7.8G     0  7.8G   0% /dev/shm
tmpfs                  7.8G  8.7M  7.8G   1% /run
tmpfs                  7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1              509M  140M  370M  28% /boot
tmpfs                  1.6G     0  1.6G   0% /run/user/0
/dev/vdb1               99G  5.3G   89G   6% /data
overlay                 39G  4.8G   33G  13% /var/lib/docker/overlay2/a8b63ab12a60dbd0e16dbbd62dd4aa1d073b6092e35f95f6b59b7f0b57dd4aee/merged
[root@mysql innodb_log]# mkdir /data1
mkdir: cannot create directory ‘/data1’: File exists
[root@mysql innodb_log]# vi /etc/fstab
UUID=fa26d131-a86c-432e-9f59-091033663fdb  /vdb1  ext4 defaults 0 0

#
# /etc/fstab
# Created by anaconda on Mon Sep 16 19:31:12 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg01-lv01   /                       ext4    defaults        1 1
UUID=9916da56-b2a1-4df1-9775-24e4103eea3a /boot                   xfs     defaults        0 0
UUID=fa26d131-a86c-432e-9f59-091033663fdb  /vdb1  ext4 defaults 0 0
/dev/vgdata01/lv02  /data1  ext4 defaults 0 0
~
~
~
~
"/etc/fstab" 12L, 503C written

6、挂载


[root@mysql innodb_log]# mount /dev/vgdata01/lv02 /data1
[root@mysql innodb_log]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01       39G  4.8G   33G  13% /
devtmpfs                   7.8G     0  7.8G   0% /dev
tmpfs                      7.8G     0  7.8G   0% /dev/shm
tmpfs                      7.8G  8.7M  7.8G   1% /run
tmpfs                      7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1                  509M  140M  370M  28% /boot
tmpfs                      1.6G     0  1.6G   0% /run/user/0
/dev/vdb1                   99G  5.3G   89G   6% /data
overlay                     39G  4.8G   33G  13% /var/lib/docker/overlay2/a8b63ab12a60dbd0e16dbbd62dd4aa1d073b6092e35f95f6b59b7f0b57dd4aee/merged
/dev/mapper/vgdata01-lv02  158G   61M  150G   1% /data1
[root@mysql innodb_log]#

关于centos7 磁盘重新分区怎么创建LVM并格式化就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI