裸设备直接创建PV

之前系统中都是将磁盘分区格式化后在创建PV,今天发现裸设备直接可以创建PV

1.查看磁盘情况

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/sdc:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

2.直接用裸设备创建PV

[root@localhost ~]# pvcreate /dev/sdb  /dev/sdc
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc" successfully created.
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <39.51g     0 
  /dev/sdb          lvm2 ---   10.00g 10.00g
  /dev/sdc          lvm2 ---   10.00g 10.00g

3.创建VG

[root@localhost ~]# pvcreate /dev/sdb  /dev/sdc
  Physical volume "/dev/sdb" successfully created.
  Physical volume "/dev/sdc" successfully created.
[root@localhost ~]# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  centos lvm2 a--  <39.51g     0 
  /dev/sdb          lvm2 ---   10.00g 10.00g
  /dev/sdc          lvm2 ---   10.00g 10.00g
[root@localhost ~]# vgcreate mysqlvg /dev/sdb
  Volume group "mysqlvg" successfully created
[root@localhost ~]# vgcreate mysqlbak /dev/sdc
  Volume group "mysqlbak" successfully created

4.创建LV

[root@localhost ~]# lvcreate -n mysql -L 5G mysqlvg
  Logical volume "mysql" created.
[root@localhost ~]# lvcreate -n datalv -L 5G mysqlvg
  Volume group "mysqlvg" has insufficient free space (1279 extents): 1280 required.
[root@localhost ~]# lvcreate -n datalv -L 4G mysqlvg
  Logical volume "datalv" created.
[root@localhost ~]# lvcreate -n baklv -L 9G mysqlbak
  Logical volume "baklv" created.

 5、格式化磁盘

[root@localhost ~]# mkfs.xfs /dev/mysqlbak/baklv
meta-data=/dev/mysqlbak/baklv    isize=512    agcount=4, agsize=589824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2359296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkfs.xfs /dev/mysqlvg/mysql
meta-data=/dev/mysqlvg/mysql     isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkfs.xfs /dev/mysqlvg/datalv
meta-data=/dev/mysqlvg/datalv    isize=512    agcount=4, agsize=262144 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1048576, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

6、新建目录

[root@localhost ~]# mkdir -p /mysql/app
[root@localhost ~]# mkdir -p /mysql/data
[root@localhost ~]# mkdir -p /mysql/backup

7、将LV分区挂载到新建的目录

[root@localhost ~]# mount /dev/mapper/mysqlvg-mysql  /mysql/app
[root@localhost ~]# mount /dev/mapper/mysqlvg-datalv  /mysql/data
[root@localhost ~]# mount /dev/mapper/mysqlbak-baklv  /mysql/backup

8、写入fstab文件

/dev/mapper/mysqlvg-mysql  /mysql/app  xfs  defaults 0 0
/dev/mapper/mysqlvg-datalv /mysql/data  xfs defaults 0 0
/dev/mapper/mysqlbak-baklv /mysql/backup  xfs defaults 0 0

9、现有lv扩容

新挂载的两块磁盘,继续用裸设备直接创建PV

[root@localhost ~]# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created.
[root@localhost ~]# pvcreate /dev/sde
  Physical volume "/dev/sde" successfully created.

创建好以后,扩容vg

[root@localhost ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree   
  centos     1   2   0 wz--n- <39.51g       0 
  mysqlbak   1   1   0 wz--n- <10.00g 1020.00m
  mysqlvg    1   2   0 wz--n- <10.00g 1020.00m
[root@localhost ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree   
  /dev/sda2  centos   lvm2 a--  <39.51g       0 
  /dev/sdb   mysqlvg  lvm2 a--  <10.00g 1020.00m
  /dev/sdc   mysqlbak lvm2 a--  <10.00g 1020.00m
  /dev/sdd            lvm2 ---   10.00g   10.00g
  /dev/sde            lvm2 ---   10.00g   10.00g
[root@localhost ~]# vgextend mysqlvg /dev/sdd
  Volume group "mysqlvg" successfully extended
[root@localhost ~]# vgextend mysqlvg /dev/sde
  Volume group "mysqlvg" successfully extended

vg扩容好以后,扩容lv

root@localhost ~]# lvextend -L +9G  /dev/mysqlvg/datalv
  Size of logical volume mysqlvg/datalv changed from 4.00 GiB (1024 extents) to 13.00 GiB (3328 extents).
  Logical volume mysqlvg/datalv successfully resized.
[root@localhost ~]# lvextend -L +4G /dev/mysqlvg/mysql
  Size of logical volume mysqlvg/mysql changed from 5.00 GiB (1280 extents) to 9.00 GiB (2304 extents).
  Logical volume mysqlvg/mysql successfully resized.

扩容文件系统,用resize2fs报错

[root@localhost ~]# resize2fs /dev/mysqlvg/datalv
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block 当尝试打开 /dev/mysqlvg/datalv 时
找不到有效的文件系统超级块.
[root@localhost ~]# xfs_growfs /dev/mysqlvg/datalv
meta-data=/dev/mapper/mysqlvg-datalv isize=512    agcount=4, agsize=262144 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1048576, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1048576 to 3407872

另外一块磁盘

[root@localhost ~]# xfs_growfs  /dev/mysqlvg/mysql
meta-data=/dev/mapper/mysqlvg-mysql isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 1310720 to 2359296

用df  -h命令查看

[root@localhost ~]# df -h
文件系统                    容量  已用  可用 已用% 挂载点
devtmpfs                    894M     0  894M    0% /dev
tmpfs                       910M     0  910M    0% /dev/shm
tmpfs                       910M   11M  900M    2% /run
tmpfs                       910M     0  910M    0% /sys/fs/cgroup
/dev/mapper/centos-root      36G  4.0G   32G   12% /
/dev/mapper/mysqlbak-baklv  9.0G   33M  9.0G    1% /mysql/backup
/dev/mapper/mysqlvg-mysql   9.0G   33M  9.0G    1% /mysql/app
/dev/mapper/mysqlvg-datalv   13G   33M   13G    1% /mysql/data
/dev/sda1                   497M  177M  321M   36% /boot
tmpfs                       182M  4.0K  182M    1% /run/user/42
tmpfs                       182M   20K  182M    1% /run/user/0

 

posted @ 2022-09-14 21:52  中仕  阅读(39)  评论(0编辑  收藏  举报