文章插圖

文章插圖
centos7.8配置lvm并掛載1 lvm是什么
LVM(Logic Volume Manager)即邏輯卷管理器 , 是linux系統用戶對硬盤分區管理的一種機制 。創建初衷是為了解決硬盤設備在創建完分區后不易修改分區的問題 , LVM技術是在硬盤分區和文件系統之間加了一個邏輯層 , 他提供了一個抽象的卷組 , 可以把多個硬盤進行卷組合并 , 這樣一來 , 用戶就不用擔心物理硬盤設備的底層架構布局 , 可以輕松實現對硬盤分區的動態調整 。簡而言之就是動態添加、縮減空間 , 而不會影響原有數據 。
2 lvm原理及常用命令
PV(Physical Volume):物理卷
VG(Volume Group):卷組
LV(Logical Volume):邏輯卷
PE(Physical Extent):基本單元
【磁盤掛載命令cat 掛載磁盤的命令】物理卷處于LVM中的最底層 , 可以將其理解為物理硬盤、硬盤分區或者磁盤陣列 , 物理卷可以理解為一個磁盤分區 , 創建物理卷時指定磁盤分區 。卷組是建立在物理卷之上的 , 一個卷組可以包含多個物理卷 , 卷組創建之后也可以繼續向其中添加物理卷 。邏輯卷是用卷組中空閑的資源建立的 , 而且邏輯卷在建立后可以動態地擴建或者縮小空間 ?;驹砣鐖D:(圖片源自網絡)
功能PV管理命令VG管理命令LV管理命令scan 掃描pvscanvgscanlvscancreate 創建pvcreatevgcreatelvcreatedisplay 顯示pvdisplayvgdisplaylvdisplayremove 移除pvremovevgremovelvremoveextend 擴展vgextendlvextend(lvresize)reduce 減少vgreducelvreduce(lvresize)resize改變容量lvresizeattribute 改變屬性 pvchangevgchangelvchange3 實操步驟本次實操是在云平臺上的磁盤上進行lvm的創建及空間分配 , 磁盤為/dev/vdb
1 格式化分區
依次輸入:fdisk /dev/vdb
n:新建分區
p:主分區
默認回車
默認回車
t:調整分區類型
8e:調整為lvm類型分區
w:保存
[[email protected] ~]# fdisk /dev/vdbWelcome 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 tableBuilding a new DOS disklabel with disk identifier 0xd3ff2d0b.Command (m for help): nPartition type:pprimary (0 primary, 0 extended, 4 free)eextendedSelect (default p): pPartition number (1-4, default 1):First sector (2048-419430399, default 2048):Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399):Using default value 419430399Partition 1 of type Linux and of size 200 GiB is setCommand (m for help): tSelected partition 1Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.2 創建pv[[email protected] ~]# pvcreate /dev/vdb1Physical volume "/dev/vdb1" successfully created.#查看pv信息[[email protected] ~]# pvsPVVGFmtAttr PSizePFree/dev/vda2centos lvm2 a--<19.00g0/dev/vdb1lvm2 ---<200.00g <200.00g3 創建vg[[email protected] ~]# vgcreate vg_test /dev/vdb1#第一個參數為vg名稱 , 第二個參數為加入vg的pvVolume group "vg_test" successfully created#查看vg信息[[email protected] ~]# vgsVG#PV #LV #SN AttrVSizeVFreecentos120 wz--n-<19.00g0vg_test100 wz--n- <200.00g <200.00g4 創建lv , 并加入100%vg的剩余空間[[email protected] ~]# lvcreate -n lv_test -l 100%FREE vg_test#創建名為lv_test的邏輯卷 , 并分配名為vg_test的卷組內所有分區空間的全部空閑空間Logical volume "lv_test" created.4 格式化[[email protected] ~]# mkfs -t ext4 /dev/mapper/vg_test-lv_testmke2fs 1.42.9 (28-Dec-2013)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks13107200 inodes, 52427776 blocks2621388 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=21999124481600 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done#再次查看磁盤信息 , 就能看到這一個邏輯卷了[[email protected] ~]# fdisk -l#省略了部分輸出Disk /dev/mapper/vg_test-lv_test: 214.7 GB, 214744170496 bytes, 419422208 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes5 掛載磁盤掛載磁盤不用磁盤名的方式 , 使用UUID掛載 , 更加可靠 。
[[email protected] ~]# blkid#查看創建的lv的UUID/dev/mapper/vg_test-lv_test: UUID="cdab99dd-fbf4-45f0-86ff-f55728d186cb" TYPE="ext4"[[email protected] ~]# vim /etc/fstab## /etc/fstab# Created by anaconda on Wed Aug 19 12:09:37 2020## 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/centos-root /xfsdefaults0 0UUID=4a6e8295-a8c1-479c-9890-cbab68fdfd68 /bootxfsdefaults0 0/dev/mapper/centos-swap swapswapdefaults0 0UUID=567b727c-af56-4d76-ae44-fb51b3c3944d /home/software ext4 defaults 0 0####/home/software 為要掛載的目錄#掛載立即生效 , 不用重啟[[email protected] ~]# mount -a地方-h6 查看掛載情況[[email protected] ~]# df -hFilesystemSizeUsed Avail Use% Mounted on/dev/mapper/vg_test-lv_test197G61M187G1% /home/software
- Linux連接服務器 linux 命令連接
- linux文件復制命令的實現 linux文件復制命令cat
- 修改端口號命令 端口號可以隨便改嗎
- linux常用命令重啟服務 linux中重啟服務器命令
- sql刪除數據表命令 sql語句中刪除表的命令是什么
- 華為路由器恢復出廠設置的命令 華為路由器怎樣恢復出廠設置方法
- linux創建文件命令 liux創建文件夾
- flashfxp怎么下載 flashfxp怎么使用命令行
- h3c交換機配置常用命令 h3c交換機命令行配置教程
- linux常用命令zip linux zip用法
