码迷,mamicode.com
首页 > 其他好文 > 详细

lvm的创建和挂载

时间:2020-07-17 01:19:21      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:fragments   users   技术   serve   nod   mke2fs   fdisk   img   write   

创建一个至少有两个PV组成的大小为20G的名为testvg的VG;要求PE大小 为16MB, 而后在卷组中创建大小为5G的逻辑卷testlv;挂载至/users目录

实验准备:
增加一块20G的硬盘,其中划分一个10G的分区;增加一块10G的硬盘
10G的分区和10G的硬盘组成pv
技术图片

[root@Centos7 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan 
[root@Centos7 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan 
[root@Centos7 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0  476M  0 part /boot
└─sda2            8:2    0 49.5G  0 part 
  ├─centos-root 253:0    0 47.5G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk 
sdc               8:32   0   10G  0 disk 
sr0              11:0    1  8.1G  0 rom  /mnt

在sdb里创建一个10G大小的分区,标记为lvm

[root@Centos7 ~]# 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 0xcb41bb54.

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-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition ‘Linux‘ to ‘Linux LVM‘

Command (m for help): p

Disk /dev/sdb: 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 label type: dos
Disk identifier: 0xcb41bb54

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@Centos7 ~]# partprobe /dev/sdb
[root@Centos7 ~]#

创建pv

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

创建vg,并且指定PE为16M,vg名为testvg

[root@Centos7 ~]# vgcreate -s 16M testvg /dev/sdb1 /dev/sdc
  Volume group "testvg" successfully created
[root@Centos7 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  centos   1   2   0 wz--n-  49.53g      0 
  testvg   2   0   0 wz--n- <19.97g <19.97g

[root@Centos7 ~]# vgdisplay testvg
  --- Volume group ---
  VG Name               testvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <19.97 GiB
  PE Size               16.00 MiB
  Total PE              1278
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1278 / <19.97 GiB
  VG UUID               fFSJn9-GdFC-3612-gSel-SzNh-1kIi-uSPkAG

创建大小为5G的逻辑卷testlv

[root@Centos7 ~]# lvcreate -L 5G -n testlv testvg 
  Logical volume "testlv" created.
[root@Centos7 ~]# lvs
  LV     VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   centos -wi-ao---- 47.53g                                                    
  swap   centos -wi-ao----  2.00g                                                    
  testlv testvg -wi-a-----  5.00g 

[root@Centos7 ~]# lvdisplay testlv testvg
  Volume group "testlv" not found
  Cannot process volume group testlv
  --- Logical volume ---
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                L3cNiC-Xc0s-IdiK-34sA-nMht-vxjD-bUa19h
  LV Write Access        read/write
  LV Creation host, time Centos7.localdomain, 2020-07-17 00:12:15 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

创建挂载目录/users,开机自动挂载

#格式testlv,直接使用mkfs命令格式化文件系统,是ext2的,如果要格式化成xfs,则使用mkfs.xfs命令,谨记!
[root@Centos7 ~]# mkfs /dev/mapper/
/dev/mapper/centos-root    /dev/mapper/testvg-testlv
/dev/mapper/centos-swap    
[root@Centos7 ~]# mkfs /dev/mapper/testvg-testlv 
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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

[root@Centos7 ~]# mkdir /users
[root@Centos7 ~]# mount /dev/mapper/testvg-testlv /users
[root@Centos7 ~]# df -Th /users
Filesystem                Type  Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv ext2  5.0G   10M  4.7G   1% /users

[root@Centos7 ~]# blkid |grep /dev/mapper/testvg-testlv 
/dev/mapper/testvg-testlv: UUID="32f7e494-a794-4ed8-a64c-89f98301f2c1" TYPE="ext2"

[root@Centos7 ~]# umount /users
[root@Centos7 ~]# mount -a
[root@Centos7 ~]# df -Th /users
Filesystem                Type  Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv ext2  5.0G   10M  4.7G   1% /users

lvm的创建和挂载

标签:fragments   users   技术   serve   nod   mke2fs   fdisk   img   write   

原文地址:https://blog.51cto.com/14812296/2511155

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!