使用lvm创建文件系统

一、实验环境

系统

centos7.4

磁盘
/dev/vdb /dev/vdc

二、步骤

2.1 使用fdisk查看空闲磁盘/dev/vdb和/dev/vdc。

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# 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: 0x0008d73a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 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/vdc: 21.5 GB, 21474836480 bytes, 41943040 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.2 安装lvm工具

yum install lvm2 -y

2.3 创建物理卷

  [root@iZm5ehujytgo8uvw6cf2hqZ ~]# pvcreate /dev/vdb /dev/vdc
  Physical volume "/dev/vdb" successfully created.
  Physical volume "/dev/vdc" successfully created.

2.4 查看物理卷

下面显示了有两个物理卷,分别属于test这个卷组。ps:在创建完卷组后运行的pvdispaly,所有这两个物理卷会有卷组名。

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/vdb
  VG Name               test
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               0
  Allocated PE          5119
  PV UUID               AXWX7I-weYa-bTVb-mD9g-3m2S-GenW-0mk2If

  --- Physical volume ---
  PV Name               /dev/vdc
  VG Name               test
  PV Size               20.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              5119
  Free PE               2558
  Allocated PE          2561
  PV UUID               iz42TA-E17K-TiHM-LYpY-tlR2-QcmA-VQ2J9b

2.5 将两个物理卷,创建名为test的卷组

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# vgcreate test /dev/vdb /dev/vdc
Volume group "test" successfully created

2.6 查看卷组

下面是卷组的信息

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# vgdisplay 
  --- Volume group ---
  VG Name               test
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               39.99 GiB
  PE Size               4.00 MiB
  Total PE              10238
  Alloc PE / Size       7680 / 30.00 GiB
  Free  PE / Size       2558 / 9.99 GiB
  VG UUID               bS9YqZ-qlHW-tZ2g-j2eu-wuIB-VroE-OP18OK

2.7 创建一个容量为30G的逻辑卷

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# lvcreate -L +30G -n lvtest test
Logical volume "lvtest" created.

2.8 查看逻辑卷

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/test/lvtest
  LV Name                lvtest
  VG Name                test
  LV UUID                PugZCF-N2RF-Q7Pu-M7eF-0IWY-hnE1-P06v0G
  LV Write Access        read/write
  LV Creation host, time iZm5ehujytgo8uvw6cf2hqZ, 2018-04-01 08:48:19 +0800
  LV Status              available
  # open                 0
  LV Size                30.00 GiB
  Current LE             7680
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:0

2.9 使用fdisk查看,会发现多了一个设备/dev/mapper/test-lvtest,这个其实就是逻辑卷的映射

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# 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: 0x0008d73a

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83884031    41940992   83  Linux

Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 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/vdc: 21.5 GB, 21474836480 bytes, 41943040 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/mapper/test-lvtest: 32.2 GB, 32212254720 bytes, 62914560 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.10 格式化逻辑卷

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

2.11 挂载并使用

[root@iZm5ehujytgo8uvw6cf2hqZ ~]# mkdir /opt/test
[root@iZm5ehujytgo8uvw6cf2hqZ ~]# mount /dev/mapper/test-lvtest /opt/test
[root@iZm5ehujytgo8uvw6cf2hqZ ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/vda1               ext4       43G  1.6G   39G   4% /
devtmpfs                devtmpfs  955M     0  955M   0% /dev
tmpfs                   tmpfs     965M     0  965M   0% /dev/shm
tmpfs                   tmpfs     965M  361k  964M   1% /run
tmpfs                   tmpfs     965M     0  965M   0% /sys/fs/cgroup
tmpfs                   tmpfs     193M     0  193M   0% /run/user/0
/dev/mapper/test-lvtest xfs        33G   34M   33G   1% /opt/test
[root@iZm5ehujytgo8uvw6cf2hqZ ~]# echo "12">/opt/test/test.txt
[root@iZm5ehujytgo8uvw6cf2hqZ ~]# cat /opt/test/test.txt 
12

2.12 在/etc/fstab写入配置,实现开机自启动

#
# /etc/fstab
# Created by anaconda on Sun Oct 15 15:19:00 2017
#
# 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
#
UUID=eb448abb-3012-4d8d-bcde-94434d586a31 /                       ext4    defaults        1 1
/dev/mapper/test-lvtest /opt/test                       xfs    defaults        0 0
Previous Post

centos下LVM相关命令

Next Post

mongodb简介

Related Posts