当前位置:网站首页 > 科技动态 > 正文

Linux——磁盘管理——LVM

代码

pvcreate———物理卷                       vgcreate——卷组             lvcreate——逻辑卷                mkfs.ext4   、mkfs.xfs——格式化     lvextend——增容              8e = Linux LVM

扩容后还需要执行的命令: 文件系统是ext4 需要   resize2fs /dev/xcloudvg/xcloudlv

                                            文件系统是xfs   需要   xfs_growfs /dev/xcloudvg/xcloudl

partprobe /dev/sdb 此命令在磁盘分区作用是刷新磁盘分区表

指定PE大小的参数   vgcreate xcloudvg /dev/sdb[1-2] -s 16M    PE 的大小,单位可以是 MB、GB、TB 等,如果不写,则默认 PE 大小是 4MB

实验一

使用 xserver1 虚拟机,使用 VMWare 软件自行添加一块大小为 20G 的硬盘,使用 fdisk 命令对该硬盘进行分区,要求分出三个大小为 5G 的分区。使用这三个分区,创建名 xcloudvg 的逻辑卷,大小为 12G ,最后用 ext4 文件系统对逻辑卷进行格式化挂载带 /mnt 目录下。

添加磁盘 20G

[root@xserver1 ~]# lsblk NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT sda               8:0    0   40G  0 disk ├─sda1            8:1    0  500M  0 part /boot └─sda2            8:2    0 39.5G  0 part   ├─centos-root 253:0    0 35.6G  0 lvm  /   └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP] sdb               8:16   0   20G  0 disk  sr0              11:0    1 1024M  0 rom

 分区

[root@xserver1 ~]# 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 0x7905fea8. 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-, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-, default ): +5G Partition 1 of type Linux and of size 5 GiB is set Command (m for help): n Partition type:    p   primary (1 primary, 0 extended, 3 free)    e   extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (-, default ): Using default value  Last sector, +sectors or +size{K,M,G} (-, default ): +5G Partition 2 of type Linux and of size 5 GiB is set Command (m for help): n Partition type:    p   primary (2 primary, 0 extended, 2 free)    e   extended Select (default p): Using default response p Partition number (3,4, default 3): First sector (-, default ): Using default value  Last sector, +sectors or +size{K,M,G} (-, default ): +5G Partition 3 of type Linux and of size 5 GiB is set Command (m for help): p    #查看 Disk /dev/sdb: 21.5 GB,  bytes,  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: 0x7905fea8    Device Boot      Start         End      Blocks   Id  System /dev/sdb1            2048            83  Linux /dev/sdb2                    83  Linux /dev/sdb3                    83  Linux Command (m for help): t Partition number (1-3, default 3): 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): t Partition number (1-3, default 3): 2 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): t Partition number (1-3, default 3): 3 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,  bytes,  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: 0x7905fea8    Device Boot      Start         End      Blocks   Id  System /dev/sdb1            2048            8e  Linux LVM /dev/sdb2                    8e  Linux LVM /dev/sdb3                    8e  Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@xserver1 ~]# lsblk NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT sda               8:0    0   40G  0 disk ├─sda1            8:1    0  500M  0 part /boot └─sda2            8:2    0 39.5G  0 part   ├─centos-root 253:0    0 35.6G  0 lvm  /   └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP] sdb               8:16   0   20G  0 disk ├─sdb1            8:17   0    5G  0 part ├─sdb2            8:18   0    5G  0 part └─sdb3            8:19   0    5G  0 part sr0              11:0    1 1024M  0 rom

创建物理卷

[root@xserver1 ~]# pvcreate /dev/sdb[1-3]   Physical volume "/dev/sdb1" successfully created   Physical volume "/dev/sdb2" successfully created   Physical volume "/dev/sdb3" successfully created 

创建卷组

[root@xserver1 ~]# vgcreate xcloudvg /dev/sdb[1-3]   Volume group "xcloudvg" successfully created

创建逻辑卷指定其大小

[root@xserver1 ~]# lvcreate -L +12G -n xcloudlv xcloudvg Logical volume "xcloudlv" created.

ext4格式化

[root@xserver1 ~]# mkfs.ext4 /dev/xcloudvg/xcloudlv 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  inodes,  blocks  blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks= 96 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, , , , , , ,  Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done

 挂载

[root@xserver1 ~]# mount /dev/xcloudvg/xcloudlv /mnt [root@xserver1 ~]# df -hT /mnt/ Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/xcloudvg-xcloudlv ext4 12G 41M 12G 1% /mnt

实验二

使用 xserver1虚拟机,使用 VMWare 软件自行添加一块大小为 20G 的硬盘,使用  fdisk 命令对该硬盘进行分区,要求分出两个大小为 5G 的分区。使两个分区,创建名 xcloudvg 的卷组并指定PE大小为 16MB 。执行 vgdisplay 查看

[root@xserver1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 39.5G 0 part ├─centos-root 253:0 0 35.6G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk sr0 11:0 1 1024M 0 rom [root@xserver1 ~]# 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 0x1f028c80. 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-, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-, default ): +5G Partition 1 of type Linux and of size 5 GiB is set Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (-, default ): Using default value  Last sector, +sectors or +size{K,M,G} (-, default ): +5G Partition 2 of type Linux and of size 5 GiB is set Command (m for help): p Disk /dev/sdb: 21.5 GB,  bytes,  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: 0x1f028c80 Device Boot Start End Blocks Id System /dev/sdb1 2048   83 Linux /dev/sdb2    83 Linux Command (m for help): t Partition number (1,2, default 2): 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): t Partition number (1,2, default 2): 2 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,  bytes,  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: 0x1f028c80 Device Boot Start End Blocks Id System /dev/sdb1 2048   8e Linux LVM /dev/sdb2    8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@xserver1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 39.5G 0 part ├─centos-root 253:0 0 35.6G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 5G 0 part └─sdb2 8:18 0 5G 0 part sr0 11:0 1 1024M 0 rom [root@xserver1 ~]# pvcreate /dev/sdb[1-2] Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created [root@xserver1 ~]# vgcreate xcloudvg /dev/sdb sdb sdb1 sdb2

  指定卷组PE大小

[root@xserver1 ~]# vgcreate xcloudvg /dev/sdb[1-2] -s 16M Volume group "xcloudvg" successfully created [root@xserver1 ~]# vgdisplay xcloudvg --- Volume group --- VG Name xcloudvg 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 9.97 GiB PE Size 16.00 MiB Total PE 638 Alloc PE / Size 0 / 0 Free PE / Size 638 / 9.97 GiB VG UUID mBRHu1-Urws-wpPc-XEbd-MPeM-Mcpz-GgQ04t

实验三

使用提供的“all-in-one”虚拟机,该虚拟机存在一块大小为20G的磁盘/dev/vdb,使用fdisk命令对该硬盘进形分区,要求分出三个大小为5G的分区。使用这三个分区,创建名xcloudvg的卷组。然后创建名xcloudlv的逻辑卷,大小为12G,最后用xfs文件系统对逻辑卷进行格式化并挂载到/mnt目录下。将上述所有操作命令和返回结果以文本形式提交到答题框。

[root@controller ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 200M 0 part /boot ├─sda2 8:2 0 39G 0 part │ ├─centos-root 253:0 0 35G 0 lvm / │ └─centos-swap 253:1 0 4G 0 lvm [SWAP] ├─sda3 8:3 0 5G 0 part ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 5G 0 part sdb 8:16 0 20G 0 disk sr0 11:0 1 1024M 0 rom loop0 7:0 0 5G 0 loop /swift/node
Command (m for help): p Disk /dev/sdb: 21.5 GB,  bytes,  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: 0xed Device Boot Start End Blocks Id System /dev/sdb1 2048   8e Linux LVM /dev/sdb2    8e Linux LVM /dev/sdb3    8e Linux LVM [root@controller ~]# pvcreate /dev/sdb[1-3] Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created Physical volume "/dev/sdb3" successfully created [root@controller ~]# vgcreate xcloudvg /dev/sdb[1-3] Volume group "xcloudvg" successfully created 

指定逻辑卷VG大小

[root@controller ~]# lvcreate -L +12G -n xcloudlv xcloudvg Logical volume "xcloudlv" created.

xfs格式化

[root@controller ~]# mkfs.xfs /dev/xcloudvg/xcloudlv meta-data=/dev/xcloudvg/xcloudlv isize=256 agcount=4, agsize= blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0

 格式化

[root@controller ~]# mount /dev/xcloudvg/xcloudlv /mnt/ [root@controller ~]# df -hT /mnt/ Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/xcloudvg-xcloudlv xfs 12G 33M 12G 1% /mnt

实验四

使用 xserver1 虚拟机,使用 VMWare 软件自行添加一块大小为 20G 的硬盘,使用 fdisk 命令对该硬盘进形分区,要求分出两个大小为 5G 的分区。使用两个分区,创建名 xcloudvg 的卷组,然后再创建一个 5G 的分区,将 xcloudvg 扩容至 15G ,最后执行 vgdisplay 命令查看卷组信息。将上述所有操作命令和返回结果以文本形式提交到答题框。

[root@xserver1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 39.5G 0 part ├─centos-root 253:0 0 35.6G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk sr0 11:0 1 1024M 0 rom [root@xserver1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 39.5G 0 part ├─centos-root 253:0 0 35.6G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 5G 0 part └─sdb2 8:18 0 5G 0 part sr0 11:0 1 1024M 0 rom [root@xserver1 ~]# pvcreate /dev/sdb[1-2] Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created [root@xserver1 ~]# vgcreate xcloudvg /dev/sdb[1-2] Volume group "xcloudvg" successfully created [root@xserver1 ~]# vgdisplay xcloudvg --- Volume group --- VG Name xcloudvg 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 9.99 GiB PE Size 4.00 MiB Total PE 2558 Alloc PE / Size 0 / 0 Free PE / Size 2558 / 9.99 GiB VG UUID 3LSzbs-UUcX-Nbab-uArm-IqfL-SDYM-by3KfE [root@xserver1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 39.5G 0 part ├─centos-root 253:0 0 35.6G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 5G 0 part ├─sdb2 8:18 0 5G 0 part └─sdb3 8:19 0 5G 0 part sr0 11:0 1 1024M 0 rom

增加卷组容量

[root@xserver1 ~]# vgextend xcloudvg /dev/sdb3 Physical volume "/dev/sdb3" successfully created Volume group "xcloudvg" successfully extended [root@xserver1 ~]# vgdisplay xcloudvg --- Volume group --- VG Name xcloudvg System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 14.99 GiB PE Size 4.00 MiB Total PE 3837 Alloc PE / Size 0 / 0 Free PE / Size 3837 / 14.99 GiB VG UUID 3LSzbs-UUcX-Nbab-uArm-IqfL-SDYM-by3KfE

其他可用命令

减少卷组容量

[root@xserver1 ~]# vgreduce xcloudvg /dev/sdb3 Removed "/dev/sdb3" from volume group "xcloudvg"

删除卷组

[root@xserver1 ~]# vgremove xcloudvg Volume group "xcloudvg" successfully removed

删除物理卷

[root@xserver1 ~]# pvremove /dev/sdb3 Labels on physical volume "/dev/sdb3" successfully wiped

版权声明


相关文章:

  • 使用JsonCpp实现JSON解析的方法2024-10-20 00:04:33
  • 国内IP节点更换攻略,一键解决烦恼2024-10-20 00:04:33
  • Java实现定时任务2024-10-20 00:04:33
  • mysql定时任务每天固定时间执行2024-10-20 00:04:33
  • 查看linux定时任务2024-10-20 00:04:33
  • 思科路由器密码设置规则2024-10-20 00:04:33
  • qt中radiobutton的用法2024-10-20 00:04:33
  • Python使用pipreqs分析项目依赖2024-10-20 00:04:33
  • popstate的自动触发问题2024-10-20 00:04:33
  • lvcreate code snippet2024-10-20 00:04:33