工作随机:linux 挂载LVM管理模式的磁盘

2024-05-14 09:28

本文主要是介绍工作随机:linux 挂载LVM管理模式的磁盘,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 前言
  • 一、创建一个分区
  • 二、创建PV
  • 三、创建VG
  • 四、创建LV
  • 五、格式化并挂载目录


前言

在数据库管理中,常有比较头疼的问题,就是一段时间发展后我的磁盘空间不够了,想要扩容原有的目录很是头疼,那么LVM管理的优势就体现出来了:逻辑卷的大小可以动态调整,而且不会丢失现在的数据,从而达到一个不动旧数据的情况下进行扩容。


一、创建一个分区

使用fdisk分区工具创建LVM分区,区别在与分区类型选择为8e

[root@XXJSB-OEM-01 /]# fdisk -lDisk /dev/sda: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x000adc79Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  1048575999   523238400   8e  Linux LVMDisk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rhel-root: 527.3 GB, 527337259008 bytes, 1029955584 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/rhel-swap: 8455 MB, 8455716864 bytes, 16515072 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[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 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 0xc7d7fbc4.Command (m for help): m
Command actiona   toggle a bootable flagb   edit bsd disklabelc   toggle the dos compatibility flagd   delete a partitiong   create a new empty GPT partition tableG   create an IRIX (SGI) partition tablel   list known partition typesm   print this menun   add a new partitiono   create a new empty DOS partition tablep   print the partition tableq   quit without saving changess   create a new empty Sun disklabelt   change a partition's system idu   change display/entry unitsv   verify the partition tablew   write table to disk and exitx   extra functionality (experts only)Command (m for help): 
Command (m for help): n
Partition type:p   primary (0 primary, 0 extended, 4 free)e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-2147483647, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2147483647, default 2147483647): 
Using default value 2147483647
Partition 1 of type Linux and of size 1024 GiB is setCommand (m for help): 
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 
#选择8e:一定要指定分区的格式为8e,这是LVM的分区格式
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'Command (m for help): 
Command (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# lsblk
NAME          MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda             8:0    0   500G  0 disk 
├─sda1          8:1    0     1G  0 part /boot
└─sda2          8:2    0   499G  0 part ├─rhel-root 253:0    0 491.1G  0 lvm  /└─rhel-swap 253:1    0   7.9G  0 lvm  [SWAP]
sdb             8:16   0     1T  0 disk 
└─sdb1          8:17   0  1024G  0 part 
sr0            11:0    1  1024M  0 rom  
[root@XXJSB-OEM-01 /]# 

二、创建PV

[root@XXJSB-OEM-01 /]# pvcreate /dev/sdb1Physical volume "/dev/sdb1" successfully created.
[root@XXJSB-OEM-01 /]#

三、创建VG

[root@XXJSB-OEM-01 /]# vgdisplay--- Volume group ---VG Name               rhelSystem ID             Format                lvm2Metadata Areas        2Metadata Sequence No  7VG Access             read/writeVG Status             resizableMAX LV                0Cur LV                2Open LV               2Max PV                0Cur PV                2Act PV                2VG Size               <1.49 TiBPE Size               4.00 MiBTotal PE              389886Alloc PE / Size       127743 / <499.00 GiBFree  PE / Size       262143 / <1024.00 GiBVG UUID               7L2R89-R1ep-1It5-pg4h-Xx4i-DHGR-fuMunL[root@XXJSB-OEM-01 /]# 
#新增已经存在的VG
[root@XXJSB-OEM-01 /]# vgextend rhel /dev/sdb1Volume group "rhel" successfully extended
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# vgsVG   #PV #LV #SN Attr   VSize  VFree    rhel   2   2   0 wz--n- <1.49t <1024.00g

四、创建LV

#新建256G
[root@XXJSB-OEM-01 /]# lvcreate -L 256G -n u01 rhelRounding up size to full physical extent 256.00 GiBLogical volume "u01" created.
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# vgsVG   #PV #LV #SN Attr   VSize  VFree   rhel   2   3   0 wz--n- <1.49t <768.00g#扩容668G
[root@XXJSB-OEM-01 /]# lvextend -L +668G /dev/rhel/u01Size of logical volume rhel/u01 changed from 256.00 GiB (65536 extents) to 924.00 GiB (236544 extents).Logical volume rhel/u01 successfully resized.
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# vgsVG   #PV #LV #SN Attr   VSize  VFree   rhel   2   3   0 wz--n- <1.49t <100.00g
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# lvdisplay--- Logical volume ---LV Path                /dev/rhel/swapLV Name                swapVG Name                rhelLV UUID                hR1pPu-I1hw-cjql-tPdk-tWDF-58ok-XVk4RVLV Write Access        read/writeLV Creation host, time localhost, 2021-05-21 13:14:00 +0800LV Status              available# open                 2LV Size                <7.88 GiBCurrent LE             2016Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:1--- Logical volume ---LV Path                /dev/rhel/rootLV Name                rootVG Name                rhelLV UUID                PR5wZY-1aUU-jVKr-4Dpe-gi0U-B0Cp-nnzMGhLV Write Access        read/writeLV Creation host, time localhost, 2021-05-21 13:14:02 +0800LV Status              available# open                 1LV Size                491.12 GiBCurrent LE             125727Segments               2Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:0--- Logical volume ---LV Path                /dev/rhel/u01LV Name                u01VG Name                rhelLV UUID                O9vP6V-28jH-WbpF-sMLn-1SQn-EuqE-iUSY13LV Write Access        read/writeLV Creation host, time XXJSB-OEM-01, 2024-05-10 17:44:05 +0800LV Status              available# open                 0LV Size                924.00 GiBCurrent LE             236544Segments               1Allocation             inheritRead ahead sectors     auto- currently set to     8192Block device           253:2[root@XXJSB-OEM-01 /]#

五、格式化并挂载目录

[root@XXJSB-OEM-01 /]# mkfs -t xfs /dev/rhel/u01
meta-data=/dev/rhel/u01          isize=512    agcount=4, agsize=60555264 blks=                       sectsz=512   attr=2, projid32bit=1=                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=242221056, imaxpct=25=                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=118272, version=2=                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@XXJSB-OEM-01 /]#
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# mount /dev/rhel/u01 /u01
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs                32G     0   32G   0% /dev
tmpfs                   32G   12K   32G   1% /dev/shm
tmpfs                   32G   21M   32G   1% /run
tmpfs                   32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/rhel-root  492G  6.0G  486G   2% /
/dev/sda1             1014M  183M  832M  19% /boot
tmpfs                  6.3G   12K  6.3G   1% /run/user/42
tmpfs                  6.3G     0  6.3G   0% /run/user/0
tmpfs                  6.3G     0  6.3G   0% /run/user/1000
/dev/mapper/rhel-u01   924G   33M  924G   1% /u01
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# cat /etc/fstab#
# /etc/fstab
# Created by anaconda on Fri May 21 13:14:02 2021
#
# 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/rhel-root   /                       xfs     defaults        0 0
UUID=7b18c326-0c8d-43b7-ba7b-ca3a73e77a0d /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# vi /etc/fstab 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# cat /etc/fstab #
# /etc/fstab
# Created by anaconda on Fri May 21 13:14:02 2021
#
# 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/rhel-root   /                       xfs     defaults        0 0
UUID=7b18c326-0c8d-43b7-ba7b-ca3a73e77a0d /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
/dev/rhel/u01           /u01                    xfs     defaults        0 0

配置好了fstab后要进行测试哦!(防止)

[root@XXJSB-OEM-01 /]# umount /u01
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs                32G     0   32G   0% /dev
tmpfs                   32G   12K   32G   1% /dev/shm
tmpfs                   32G   21M   32G   1% /run
tmpfs                   32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/rhel-root  492G  6.0G  486G   2% /
/dev/sda1             1014M  183M  832M  19% /boot
tmpfs                  6.3G   12K  6.3G   1% /run/user/42
tmpfs                  6.3G     0  6.3G   0% /run/user/0
tmpfs                  6.3G     0  6.3G   0% /run/user/1000
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# mount -a
[root@XXJSB-OEM-01 /]# 
[root@XXJSB-OEM-01 /]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs                32G     0   32G   0% /dev
tmpfs                   32G   12K   32G   1% /dev/shm
tmpfs                   32G   21M   32G   1% /run
tmpfs                   32G     0   32G   0% /sys/fs/cgroup
/dev/mapper/rhel-root  492G  6.0G  486G   2% /
/dev/sda1             1014M  183M  832M  19% /boot
tmpfs                  6.3G   12K  6.3G   1% /run/user/42
tmpfs                  6.3G     0  6.3G   0% /run/user/0
tmpfs                  6.3G     0  6.3G   0% /run/user/1000
/dev/mapper/rhel-u01   924G   33M  924G   1% /u01
[root@XXJSB-OEM-01 /]# 

这篇关于工作随机:linux 挂载LVM管理模式的磁盘的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/988384

相关文章

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将

Linux系统配置NAT网络模式的详细步骤(附图文)

《Linux系统配置NAT网络模式的详细步骤(附图文)》本文详细指导如何在VMware环境下配置NAT网络模式,包括设置主机和虚拟机的IP地址、网关,以及针对Linux和Windows系统的具体步骤,... 目录一、配置NAT网络模式二、设置虚拟机交换机网关2.1 打开虚拟机2.2 管理员授权2.3 设置子

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

Linux samba共享慢的原因及解决方案

《Linuxsamba共享慢的原因及解决方案》:本文主要介绍Linuxsamba共享慢的原因及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux samba共享慢原因及解决问题表现原因解决办法总结Linandroidux samba共享慢原因及解决

Python中随机休眠技术原理与应用详解

《Python中随机休眠技术原理与应用详解》在编程中,让程序暂停执行特定时间是常见需求,当需要引入不确定性时,随机休眠就成为关键技巧,下面我们就来看看Python中随机休眠技术的具体实现与应用吧... 目录引言一、实现原理与基础方法1.1 核心函数解析1.2 基础实现模板1.3 整数版实现二、典型应用场景2

新特性抢先看! Ubuntu 25.04 Beta 发布:Linux 6.14 内核

《新特性抢先看!Ubuntu25.04Beta发布:Linux6.14内核》Canonical公司近日发布了Ubuntu25.04Beta版,这一版本被赋予了一个活泼的代号——“Plu... Canonical 昨日(3 月 27 日)放出了 Beta 版 Ubuntu 25.04 系统镜像,代号“Pluc

Linux安装MySQL的教程

《Linux安装MySQL的教程》:本文主要介绍Linux安装MySQL的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux安装mysql1.Mysql官网2.我的存放路径3.解压mysql文件到当前目录4.重命名一下5.创建mysql用户组和用户并修

Linux上设置Ollama服务配置(常用环境变量)

《Linux上设置Ollama服务配置(常用环境变量)》本文主要介绍了Linux上设置Ollama服务配置(常用环境变量),Ollama提供了多种环境变量供配置,如调试模式、模型目录等,下面就来介绍一... 目录在 linux 上设置环境变量配置 OllamPOgxSRJfa手动安装安装特定版本查看日志在

Linux系统之主机网络配置方式

《Linux系统之主机网络配置方式》:本文主要介绍Linux系统之主机网络配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、查看主机的网络参数1、查看主机名2、查看IP地址3、查看网关4、查看DNS二、配置网卡1、修改网卡配置文件2、nmcli工具【通用