工作随机: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使用fdisk进行磁盘的相关操作

《Linux使用fdisk进行磁盘的相关操作》fdisk命令是Linux中用于管理磁盘分区的强大文本实用程序,这篇文章主要为大家详细介绍了如何使用fdisk进行磁盘的相关操作,需要的可以了解下... 目录简介基本语法示例用法列出所有分区查看指定磁盘的区分管理指定的磁盘进入交互式模式创建一个新的分区删除一个存

Linux使用dd命令来复制和转换数据的操作方法

《Linux使用dd命令来复制和转换数据的操作方法》Linux中的dd命令是一个功能强大的数据复制和转换实用程序,它以较低级别运行,通常用于创建可启动的USB驱动器、克隆磁盘和生成随机数据等任务,本文... 目录简介功能和能力语法常用选项示例用法基础用法创建可启动www.chinasem.cn的 USB 驱动

高效管理你的Linux系统: Debian操作系统常用命令指南

《高效管理你的Linux系统:Debian操作系统常用命令指南》在Debian操作系统中,了解和掌握常用命令对于提高工作效率和系统管理至关重要,本文将详细介绍Debian的常用命令,帮助读者更好地使... Debian是一个流行的linux发行版,它以其稳定性、强大的软件包管理和丰富的社区资源而闻名。在使用

Python中的随机森林算法与实战

《Python中的随机森林算法与实战》本文详细介绍了随机森林算法,包括其原理、实现步骤、分类和回归案例,并讨论了其优点和缺点,通过面向对象编程实现了一个简单的随机森林模型,并应用于鸢尾花分类和波士顿房... 目录1、随机森林算法概述2、随机森林的原理3、实现步骤4、分类案例:使用随机森林预测鸢尾花品种4.1

Linux Mint Xia 22.1重磅发布: 重要更新一览

《LinuxMintXia22.1重磅发布:重要更新一览》Beta版LinuxMint“Xia”22.1发布,新版本基于Ubuntu24.04,内核版本为Linux6.8,这... linux Mint 22.1「Xia」正式发布啦!这次更新带来了诸多优化和改进,进一步巩固了 Mint 在 Linux 桌面

LinuxMint怎么安装? Linux Mint22下载安装图文教程

《LinuxMint怎么安装?LinuxMint22下载安装图文教程》LinuxMint22发布以后,有很多新功能,很多朋友想要下载并安装,该怎么操作呢?下面我们就来看看详细安装指南... linux Mint 是一款基于 Ubuntu 的流行发行版,凭借其现代、精致、易于使用的特性,深受小伙伴们所喜爱。对

什么是 Linux Mint? 适合初学者体验的桌面操作系统

《什么是LinuxMint?适合初学者体验的桌面操作系统》今天带你全面了解LinuxMint,包括它的历史、功能、版本以及独特亮点,话不多说,马上开始吧... linux Mint 是一款基于 Ubuntu 和 Debian 的知名发行版,它的用户体验非常友好,深受广大 Linux 爱好者和日常用户的青睐,

Linux(Centos7)安装Mysql/Redis/MinIO方式

《Linux(Centos7)安装Mysql/Redis/MinIO方式》文章总结:介绍了如何安装MySQL和Redis,以及如何配置它们为开机自启,还详细讲解了如何安装MinIO,包括配置Syste... 目录安装mysql安装Redis安装MinIO总结安装Mysql安装Redis搜索Red

SSID究竟是什么? WiFi网络名称及工作方式解析

《SSID究竟是什么?WiFi网络名称及工作方式解析》SID可以看作是无线网络的名称,类似于有线网络中的网络名称或者路由器的名称,在无线网络中,设备通过SSID来识别和连接到特定的无线网络... 当提到 Wi-Fi 网络时,就避不开「SSID」这个术语。简单来说,SSID 就是 Wi-Fi 网络的名称。比如

VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virtual disk”问题

《VMWare报错“指定的文件不是虚拟磁盘“或“Thefilespecifiedisnotavirtualdisk”问题》文章描述了如何修复VMware虚拟机中出现的“指定的文件不是虚拟... 目录VMWare报错“指定的文件不是虚拟磁盘“或“The file specified is not a virt