linux磁盘管理---LVM

一、创建lvm
大致步骤:
1.fdisk /dev/vdb,创建一个分区如/dev/vdb1
2.创建pv,pvcreate /deb/vdb1
3.创建vg,vgcreate name /dev/vdb1
4.创建lv,lvcreate -L 20G -n lvname vgname

root@ubuntu:~# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
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.
Created a new DOS disklabel with disk identifier 0x4f478fce.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type 'Linux' and of size 20 GiB.

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@ubuntu:~# 
root@ubuntu:~# fdisk -l
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0xca984eb8

Device     Boot    Start      End  Sectors  Size Id Type
/dev/sda1  *        2048 39942143 39940096   19G 83 Linux
/dev/sda2       39944190 41940991  1996802  975M  5 Extended
/dev/sda5       39944192 41940991  1996800  975M 82 Linux swap / Solaris


Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: dos
Disk identifier: 0x4f478fce

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 41943039 41940992  20G 8e Linux LVM


Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 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@ubuntu:~#
root@ubuntu:~# pvcreate /dev/sdb1
  /run/lvm/lvmetad.socket: connect failed: No such file or directory
  WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
  Physical volume "/dev/sdb1" successfully created
root@ubuntu:~# vgcreate sdb1vg1 /dev/sdb1     #sdb1vg1是自己命名的vg名
  Volume group "sdb1vg1" successfully created
root@ubuntu:~# lvcreate -L 19G -n lvsdb1 sdb1vg1    #lvsdb1是自己命名的lv名
  Logical volume "lvsdb1" created.
root@ubuntu:~# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/sdb1vg1/lvsdb1
  LV Name                lvsdb1
  VG Name                sdb1vg1
  LV UUID                M6TXKf-Jsql-SG0C-mVCK-zTPE-OWV3-EkwSGY
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2018-09-16 23:31:31 -0700
  LV Status              available
  # open                 0
  LV Size                19.00 GiB
  Current LE             4864
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
root@ubuntu:~# mkfs.ext3 /dev/sdb1vg1/lvsdb1 
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 4980736 4k blocks and 1245184 inodes
Filesystem UUID: 27702051-2e69-429a-aa21-aea3ab1a6605
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000

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

root@ubuntu:~# mount /dev/sdb1vg1/lvsdb1 /wj/lvmtest1
root@ubuntu:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev                        469M     0  469M   0% /dev
tmpfs                        98M  4.5M   93M   5% /run
/dev/sda1                    19G  1.6G   17G   9% /
tmpfs                       488M     0  488M   0% /dev/shm
tmpfs                       5.0M     0  5.0M   0% /run/lock
tmpfs                       488M     0  488M   0% /sys/fs/cgroup
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/sdb1vg1-lvsdb1   19G   45M   18G   1% /wj/lvmtest1
root@ubuntu:~#

上述报错用下面命令解决

root@ubuntu:~# systemctl enable lvm2-lvmetad.service 
Synchronizing state of lvm2-lvmetad.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install enable lvm2-lvmetad
root@ubuntu:~# systemctl enable lvm2-lvmetad.socket
root@ubuntu:~# systemctl start lvm2-lvmetad.service 
root@ubuntu:~# systemctl start lvm2-lvmetad.socket

二、lvm扩容

大致步骤
1.fdisk /dev/vdb,创建一个分区如/dev/vdb1
2.创建pv,pvcreate /deb/vdb1
3.vgextend vgname pvname(/dev/vdb1,用lvdisplay查看)
4.lvextend -L +10G lvpath(lvdisplay查看)
5.resize2fs lvpath

先fdisk一块sdc2盘
然后具体操作如下

root@ubuntu:~# pvcreate /dev/sdc2
  Physical volume "/dev/sdc2" successfully created
root@ubuntu:~# vgdisplay 
  --- Volume group ---
  VG Name               sdb1vg1
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               20.00 GiB
  PE Size               4.00 MiB
  Total PE              5119
  Alloc PE / Size       4864 / 19.00 GiB
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               CE3SUU-zD0y-3Rrm-hehH-OXhK-PDVE-XPHClv
root@ubuntu:~# vgextend sdb1vg1 /dev/sdc2
  Volume group "sdb1vg1" successfully extended
root@ubuntu:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev                        469M     0  469M   0% /dev
tmpfs                        98M  4.5M   93M   5% /run
/dev/sda1                    19G  1.6G   17G   9% /
tmpfs                       488M     0  488M   0% /dev/shm
tmpfs                       5.0M     0  5.0M   0% /run/lock
tmpfs                       488M     0  488M   0% /sys/fs/cgroup
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/sdb1vg1-lvsdb1   19G   45M   18G   1% /wj/lvmtest1
root@ubuntu:~# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/sdb1vg1/lvsdb1
  LV Name                lvsdb1
  VG Name                sdb1vg1
  LV UUID                M6TXKf-Jsql-SG0C-mVCK-zTPE-OWV3-EkwSGY
  LV Write Access        read/write
  LV Creation host, time ubuntu, 2018-09-16 23:31:31 -0700
  LV Status              available
  # open                 1
  LV Size                19.00 GiB
  Current LE             4864
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
root@ubuntu:~# lvextend -L +5G /dev/sdb1vg1/lvsdb1 
  Size of logical volume sdb1vg1/lvsdb1 changed from 19.00 GiB (4864 extents) to 24.00 GiB (6144 extents).
  Logical volume lvsdb1 successfully resized.
root@ubuntu:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev                        469M     0  469M   0% /dev
tmpfs                        98M  4.5M   93M   5% /run
/dev/sda1                    19G  1.6G   17G   9% /
tmpfs                       488M     0  488M   0% /dev/shm
tmpfs                       5.0M     0  5.0M   0% /run/lock
tmpfs                       488M     0  488M   0% /sys/fs/cgroup
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/sdb1vg1-lvsdb1   19G   45M   18G   1% /wj/lvmtest1
root@ubuntu:~# resize2fs /dev/sdb1vg1/lvsdb1 
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sdb1vg1/lvsdb1 is mounted on /wj/lvmtest1; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 2
The filesystem on /dev/sdb1vg1/lvsdb1 is now 6291456 (4k) blocks long.

root@ubuntu:~# df -h
Filesystem                  Size  Used Avail Use% Mounted on
udev                        469M     0  469M   0% /dev
tmpfs                        98M  4.5M   93M   5% /run
/dev/sda1                    19G  1.6G   17G   9% /
tmpfs                       488M     0  488M   0% /dev/shm
tmpfs                       5.0M     0  5.0M   0% /run/lock
tmpfs                       488M     0  488M   0% /sys/fs/cgroup
tmpfs                        98M     0   98M   0% /run/user/0
/dev/mapper/sdb1vg1-lvsdb1   24G   45M   23G   1% /wj/lvmtest1
root@ubuntu:~#
Re-reading the partition table failed.: Device or resource busy

解决:

partprobe
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1,在下列地址,找一个与申请注册网约车人证审核。(我是找张江路那里去办理的。带好户口本,身份证) 2,办理成功后,...
    无敌辉阅读 36,767评论 3 2
  • 思绪 翻飞 意识 模糊 眼神 空洞 似乎失去了什么, 如一阵秋风,掠去枯叶 一切都看似没有发生,如初 不,不,不 ...
    陌小篱阅读 193评论 0 0
  • 因为你知道自己有很多的不完美 才会试着去接受对方的不完美
    左半边翅膀91阅读 115评论 0 0
  • 珍珍Pearl阅读 293评论 0 0