Linux逻辑卷的创建与扩容

Logical volume 的创建


  • 磁盘初始化

[root@xxxx-centos7-template ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000a580e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648   104857599    52222976   8e  Linux LVM

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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/centos-root: 44.9 GB, 44883247104 bytes, 87662592 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/centos-swap: 8589 MB, 8589934592 bytes, 16777216 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@xxxx-centos7-template ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   42G  1.6G   41G   4% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.5M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                197M  103M   95M  53% /boot
tmpfs                    799M     0  799M   0% /run/user/0
[root@xxxx-centos7-template ~]# mkdir /data
[root@xxxx-centos7-template ~]# 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 0x3bb4b474.

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

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x3bb4b474

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@xxxx-centos7-template ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.

  • 物理卷,卷组 创建
[root@xxxxcentos7-template ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

[root@xxxx-centos7-template ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               49.80 GiB
  PE Size               4.00 MiB
  Total PE              12749
  Alloc PE / Size       12749 / 49.80 GiB
  Free  PE / Size       0 / 0
  VG UUID               uYlfgy-kh0D-YE6a-A3Eq-n4RN-t3QF-C7HBLS

[root@xxxx-centos7-template ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@xxxx-centos7-template ~]# pvscan
  PV /dev/sda2   VG centos          lvm2 [49.80 GiB / 0    free]
  PV /dev/sdb1   VG centos          lvm2 [<100.00 GiB / <100.00 GiB free]
  Total: 2 [<149.80 GiB] / in use: 2 [<149.80 GiB] / in no VG: 0 [0   ]

> *  逻辑卷创建
[root@xxxx-centos7-template ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                vFM0SF-6giK-lWPg-iCTY-usKM-ywpA-bp5zxd
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2018-04-20 13:44:01 +0800
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                mtRvdH-eFlc-3EiS-xQbW-lqfm-y6K5-bAiZrv
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2018-04-20 13:44:01 +0800
  LV Status              available
  # open                 1
  LV Size                41.80 GiB
  Current LE             10701
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@xxxx-centos7-template ~]# lvcreate -L 100G -n data centos
  Volume group "centos" has insufficient free space (25599 extents): 25600 required.
[root@skong-centos7-template ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                vFM0SF-6giK-lWPg-iCTY-usKM-ywpA-bp5zxd
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2018-04-20 13:44:01 +0800
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                mtRvdH-eFlc-3EiS-xQbW-lqfm-y6K5-bAiZrv
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2018-04-20 13:44:01 +0800
  LV Status              available
  # open                 1
  LV Size                41.80 GiB
  Current LE             10701
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@xxxx-centos7-template ~]# lvcreate -L 99G -n data centos
  Logical volume "data" created.
[root@xxxx-centos7-template ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                vFM0SF-6giK-lWPg-iCTY-usKM-ywpA-bp5zxd
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2018-04-20 13:44:01 +0800
  LV Status              available
  # open                 2
  LV Size                8.00 GiB
  Current LE             2048
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                mtRvdH-eFlc-3EiS-xQbW-lqfm-y6K5-bAiZrv
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2018-04-20 13:44:01 +0800
  LV Status              available
  # open                 1
  LV Size                41.80 GiB
  Current LE             10701
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/data
  LV Name                data
  VG Name                centos
  LV UUID                Jj7pYx-vlUm-2z9U-UcK0-Wx3m-182t-UeQH25
  LV Write Access        read/write
  LV Creation host, time xxxx-centos7-template, 2019-03-13 20:50:49 +0800
  LV Status              available
  # open                 0
  LV Size                99.00 GiB
  Current LE             25344
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2

  • 挂载lvm

[root@xxxx-centos7-template ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   42G  1.6G   41G   4% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.5M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                197M  103M   95M  53% /boot
tmpfs                    799M     0  799M   0% /run/user/0

[root@xxxx-centos7-template ~]# mkfs.ext4 -j /dev/centos/data
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
6488064 inodes, 25952256 blocks
1297612 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
792 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, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

[root@xxxx-centos7-template ~]# vim /etc/fstab
[root@xxxx-centos7-template ~]# cat /etc/fstab
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=30d431c7-640e-4431-8850-4a686d553114 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/centos/data         /data                  ext4    defaults        0 0
[root@xxxx-centos7-template ~]# 

[root@xxxx-centos7-template ~]# mount -a
[root@xxxx-centos7-template ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   42G  1.6G   41G   4% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.5M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                197M  103M   95M  53% /boot
tmpfs                    799M     0  799M   0% /run/user/0
/dev/mapper/centos-data   98G   61M   93G   1% /data

Logical volume 扩容

  • 如果单纯的给已存在了逻辑卷扩容

 lvdisplay
 lvextend  /dev/centos/data /dev/sda3
 xfs_growfs /dev/centos/data

原文地址:https://blog.51cto.com/13386520/2362292

时间: 2024-10-06 09:58:08

Linux逻辑卷的创建与扩容的相关文章

Linux系统LVM逻辑卷的创建与扩容(命令详解,图文并茂)

LVM简介: LVM(Logical Volume Manager)中文名:逻辑卷管理器,本质上是一个虚拟设备驱动,是在内核中块设备和物理设备之间添加的一个新的抽象层次,它可以将几块磁盘(物理卷,PhysicalVolume)组合起来形成一个存储池或者卷组(VolumeGroup).LVM可以每次从卷组中划分出不同大小的逻辑卷(LogicalVolume)创建新的逻辑设备.底层的原始的磁盘不再由内核直接控制,而由LVM层来控制.对于上层应用来说卷组替代了磁盘块成为数据存储的基本单元.LVM管理着

Linux 逻辑卷LVM创建扩展删除实例

我这里用sdb这个20G的硬盘创建四个5G分区,并使用这四个分区创建test_lvm卷组,最后从卷组中创建两个8G的逻辑卷test_web和test_data. 详细步骤:需要操作和注意的内容均已用深色标注 1,首先对sdb创建分区 [[email protected] ~]# fdisk -l    #查看磁盘分区 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Unit

Linux逻辑卷的创建以及扩展和缩减

一:磁盘分区 二: PV 三: VG,以及从VG中删除PV和添加PV 四: LV 五:扩展LV.缩减LV 1.1创建磁盘分区,修改分区类型为LVM 2.1安装lvm2 yum install lvm2 2.2创建PV(Physical Volume) 2.2.1相关概念图 2.2.2把sdb5.sdb6创建为PV [[email protected] /]# pvcreate /dev/sdb{5,6} 2.3查看当前系统的所有PV [[email protected] /]# pvscan 2

Linux 逻辑卷扩容

Linux 逻辑卷扩容 关键词:pv(物理卷).vg(卷组) .lv(逻辑卷) 今天在用linux过程中,根分区容量不够了,突然想起来好久没更新博客,就来说说逻辑卷扩容的问题吧. 1.扩容前的检查 记住/dev/mapper/rhel-root 我们等会给它扩容,记好root的分区类型为xfs [[email protected] ~]# df -hT 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/rhel-root xfs 10G 6.7G 3.4G 67% / d

GNU/Linux下LVM配置管理以及快照卷、物理卷、卷组、逻辑卷的创建和删除

LVM是Linux环境中对磁盘分区进行管理的一种机制,是建立在硬盘和分区之上.文件系统之下的一个逻辑层,可提高磁盘分区管理的灵活性.最大的优点是在不损伤数据的前提下调整存储空间的大小. 本篇主要讲述LVM的创建.LVM的扩展与缩减和快照卷的使用三部分 第一部分:LVM的创建 LVM创建的大致步骤为 1.将多个分区转化为多个物理卷PV(Physical Vomule)    一个分区可以创建一个物理卷,可以在多块磁盘上创建物理卷.也可以做raid10磁盘阵列以后在做物理卷, 以    便有更快的读

Linux磁盘管理:LVM逻辑卷的创建及使用

一.创建LVM逻辑卷 事先添加了三块虚拟物理磁盘/dev/sdb 1G, /dev/sdc 2G, /dev/sdd 3G 使用fdisk –l命令查看: [[email protected] ~]# fdisk -l Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes /

Linux 逻辑卷逻辑卷的创建,扩展,缩减

Linux 逻辑卷逻辑卷的创建,扩展,缩减   在生活中会遇到磁盘空间不足的情况,为了不影响Linux系统的正常使用,我们需要在线扩展和缩减逻辑卷大小.首先需要先了解一下LVM(Logical Volume Manager),它是Linux环境下对磁盘分区进行管理的一种机制,LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性. LVM的工作原理其实很简单,它就是通过将底层的物理硬盘抽象的封装起来,然后以逻辑卷的方式呈现给上层应用.在传统的磁盘管理机制中,我们的上层应用是直接访问

Linux逻辑卷管理器(LVM)

LVM基础 通过使用Linux的逻辑卷管理器(Logical Volume Manager, LVM),用户可以在系统运行时动态调整文件系统的大小,把数据从一块硬盘重定位到另一块硬盘,也可以提高I/O操作的性能,以及提供冗余保护,它的快照功能允许用户对逻辑卷进行实时的备份. 对一般用户来讲,使用最多的是动态调整文件系统大小的功能.这样,你在分区时就不必为如何设置分区的大小而烦恼,只要在硬盘中预留出部分空闲空间,然后根据系统的使用情况,动态调整分区大小. 在LVM中,主要有三个概念: 物理卷(Ph

Linux逻辑卷管理(LVM)

Linux逻辑卷管理(LVM) LVM基本概念 PV (物理卷): 可以由硬盘或分区创建.(使用硬盘分区创建时PV时,若原分区已有文件系统,需将分区的id更改为8e,使用fdisk 命令中t选项修改) VG(卷组): 由若干个PV组成,创建时候,需指定最小单元PE(物理扩展盘区)大小,并同时将指定的PV加入VG内作为成员. PE(Physical Extent): PE是PV中固定大小的物理存储单元,LVM技术就是通过在VG中交换PE来实现LV的空间容量扩容或缩减的 LV(逻辑卷): 在VG中划