本帖最后由 guhui 于 2024-5-6 09:03 编辑
常用的LVM部署命令 [td]功能/命令 | 物理卷管理 | 卷组管理 | 逻辑卷管理 | 扫描 | pvscan | vgscan | lvscan | 建立 | pvcreate | vgcreate | lvcreate | 显示 | pvdisplay | vgdisplay | lvdisplay | 删除 | pvremove | vgremove | lvremove | 扩展 | | vgextend | lvextend | 缩小 | | vgreduce | lvreduce |
LVM扩容以及缩小- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 60G 0 disk
- ├─sda1 8:1 0 1G 0 part /boot
- └─sda2 8:2 0 59G 0 part
- ├─centos-root 253:0 0 37G 0 lvm /
- ├─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
- └─centos-home 253:2 0 18.1G 0 lvm /home
- sr0 11:0 1 9.5G 0 rom /run/media/gh/CentOS 7 x86_64
- [root@localhost ~]# pvs #查看
- PV VG Fmt Attr PSize PFree
- /dev/sda2 centos lvm2 a-- <59.00g 4.00m
- [root@localhost ~]# vgs
- VG #PV #LV #SN Attr VSize VFree
- centos 1 3 0 wz--n- <59.00g 4.00m
- [root@localhost ~]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- home centos -wi-ao---- 18.08g
- root centos -wi-ao---- <37.04g
- swap centos -wi-ao---- <3.88g
- [root@localhost ~]#
- xfs不支持缩减
- [root@server1 ~]# lvextend -L +300M /dev/test1/lv
- Size of logical volume test1/lv changed from 120.00 MiB (30 extents) to 420.00 MiB (105 extents).
- Logical volume test1/lv successfully resized.
- [root@server1 ~]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- root rhel -wi-ao---- <17.00g
- swap rhel -wi-ao---- 2.00g
- lv test1 -wi-a----- 420.00m
- [root@server1 ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 20G 0 disk
- └─test1-lv 253:2 0 420M 0 lvm #扩大
- sdb 8:16 0 20G 0 disk
- sdc 8:32 0 20G 0 disk
- sr0 11:0 1 7.9G 0 rom /root/sr0
- nvme0n1 259:0 0 20G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 19G 0 part
- ├─rhel-root 253:0 0 17G 0 lvm /
- └─rhel-swap 253:1 0 2G 0 lvm [SWAP]
- [root@server1 ~]# mount /dev/test1/lv /root/lvv/ 挂载之后刷新
- [root@server1 ~]# xfs_growfs /dev/test1/lv 刷新
- meta-data=/dev/mapper/test1-lv isize=512 agcount=4, agsize=7680 blks
- = sectsz=512 attr=2, projid32bit=1
- = crc=1 finobt=1, sparse=1, rmapbt=0
- = reflink=1
- data = bsize=4096 blocks=30720, imaxpct=25
- = sunit=0 swidth=0 blks
- naming =version 2 bsize=4096 ascii-ci=0, ftype=1
- log =internal log bsize=4096 blocks=1368, version=2
- = sectsz=512 sunit=0 blks, lazy-count=1
- realtime =none extsz=4096 blocks=0, rtextents=0
- data blocks changed from 30720 to 107520
- [root@server1 ~]# df -Th
- Filesystem Type Size Used Avail Use% Mounted on
- devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
- tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
- tmpfs tmpfs 1.9G 9.6M 1.9G 1% /run
- tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
- /dev/mapper/rhel-root xfs 17G 4.9G 13G 29% /
- /dev/nvme0n1p1 xfs 1014M 230M 785M 23% /boot
- tmpfs tmpfs 376M 1.2M 375M 1% /run/user/42
- tmpfs tmpfs 376M 4.0K 376M 1% /run/user/1000
- /dev/sr0 iso9660 7.9G 7.9G 0 100% /root/sr0
- /dev/mapper/test1-lv xfs 415M 9.8M 405M 3% /root/lvv #设备
- #ext格式
- [root@server1 ~]# lvcreate -n ext -L 300M test1
- Logical volume "ext" created.
- [root@server1 ~]# mkfs.ext4 /dev/test1/ext
- mke2fs 1.45.4 (23-Sep-2019)
- Creating filesystem with 307200 1k blocks and 76912 inodes
- Filesystem UUID: 822265e6-d394-4741-8a7e-f8553e61529c
- Superblock backups stored on blocks:
- 8193, 24577, 40961, 57345, 73729, 204801, 221185
- Allocating group tables: done
- Writing inode tables: done
- Creating journal (8192 blocks): done
- Writing superblocks and filesystem accounting information: done
- [root@server1 ~]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- root rhel -wi-ao---- <17.00g
- swap rhel -wi-ao---- 2.00g
- ext test1 -wi-a----- 300.00m
- lv test1 -wi-ao---- 420.00m
- #增加或是删减时,设备必须是在未挂载情况下进行
- 增加
- 1.磁盘检查
- [root@server1 ~]# e2fsck -f /dev/test1/ext
- e2fsck 1.45.4 (23-Sep-2019)
- Pass 1: Checking inodes, blocks, and sizes
- Pass 2: Checking directory structure
- Pass 3: Checking directory connectivity
- Pass 4: Checking reference counts
- Pass 5: Checking group summary information
- /dev/test1/ext: 11/76912 files (0.0% non-contiguous), 19977/307200 blocks
- 2.调整大小
- [root@server1 ~]# lvextend -L 500M /dev/test1/ext
- Size of logical volume test1/ext changed from 300.00 MiB (75 extents) to 500.00 MiB (125 extents).
- Logical volume test1/ext successfully resized.
- [root@server1 ~]# lvs
- LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
- root rhel -wi-ao---- <17.00g
- swap rhel -wi-ao---- 2.00g
- ext test1 -wi-a----- 500.00m
- lv test1 -wi-ao---- 420.00m
- 3.检查磁盘
- [root@server1 ~]# e2fsck -f /dev/test1/ext
- e2fsck 1.45.4 (23-Sep-2019)
- Pass 1: Checking inodes, blocks, and sizes
- Pass 2: Checking directory structure
- Pass 3: Checking directory connectivity
- Pass 4: Checking reference counts
- Pass 5: Checking group summary information
- /dev/test1/ext: 11/76912 files (0.0% non-contiguous), 19977/307200 blocks
- [root@server1 ~]# resize2fs /dev/test1/ext 重置磁盘
- resize2fs 1.45.4 (23-Sep-2019)
- Resizing the filesystem on /dev/test1/ext to 512000 (1k) blocks.
- The filesystem on /dev/test1/ext is now 512000 (1k) blocks long.
- 4.挂载查看
- [root@server1 ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 20G 0 disk
- ├─test1-lv 253:2 0 420M 0 lvm /root/lvv
- └─test1-ext 253:3 0 500M 0 lvm /root/ext #容量更改
- sdb 8:16 0 20G 0 disk
- sdc 8:32 0 20G 0 disk
- sr0 11:0 1 7.9G 0 rom /root/sr0
- nvme0n1 259:0 0 20G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 19G 0 part
- ├─rhel-root 253:0 0 17G 0 lvm /
- └─rhel-swap 253:1 0 2G 0 lvm [SWAP]
- [root@server1 ~]# df -Th
- Filesystem Type Size Used Avail Use% Mounted on
- devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
- tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
- tmpfs tmpfs 1.9G 9.6M 1.9G 1% /run
- tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
- /dev/mapper/rhel-root xfs 17G 4.9G 13G 29% /
- /dev/nvme0n1p1 xfs 1014M 230M 785M 23% /boot
- tmpfs tmpfs 376M 1.2M 375M 1% /run/user/42
- tmpfs tmpfs 376M 4.0K 376M 1% /run/user/1000
- /dev/sr0 iso9660 7.9G 7.9G 0 100% /root/sr0
- /dev/mapper/test1-lv xfs 415M 9.8M 405M 3% /root/lvv
- /dev/mapper/test1-ext ext4 477M 2.3M 446M 1% /root/ext #容量更改
- 删减
- 1.卸载磁盘并检查磁盘
- [root@server1 ~]# umount /dev/test/ext
- umount: /dev/test/ext: no mount point specified.
- [root@server1 ~]# umount /dev/test1/ext
- [root@server1 ~]# e2fsck -f /dev/test1/ext
- e2fsck 1.45.4 (23-Sep-2019)
- Pass 1: Checking inodes, blocks, and sizes
- Pass 2: Checking directory structure
- Pass 3: Checking directory connectivity
- Pass 4: Checking reference counts
- Pass 5: Checking group summary information
- /dev/test1/ext: 11/127512 files (0.0% non-contiguous), 26612/512000 blocks
- 3.删减容量
- [root@server1 ~]# resize2fs /dev/test1/ext 400M 重置磁盘容量
- resize2fs 1.45.4 (23-Sep-2019)
- Resizing the filesystem on /dev/test1/ext to 409600 (1k) blocks.
- The filesystem on /dev/test1/ext is now 409600 (1k) blocks long.
- [root@server1 ~]# lvreduce -L 400M /dev/test1/ext 逻辑卷删减
- WARNING: Reducing active logical volume to 400.00 MiB.
- THIS MAY DESTROY YOUR DATA (filesystem etc.)
- Do you really want to reduce test1/ext? [y/n]: y
- Size of logical volume test1/ext changed from 500.00 MiB (125 extents) to 400.00 MiB (100 extents).
- Logical volume test1/ext successfully resized.
- 4.检查磁盘
- [root@server1 ~]# lvreduce -L 400M /dev/test1/ext
- WARNING: Reducing active logical volume to 400.00 MiB.
- THIS MAY DESTROY YOUR DATA (filesystem etc.)
- Do you really want to reduce test1/ext? [y/n]: y
- Size of logical volume test1/ext changed from 500.00 MiB (125 extents) to 400.00 MiB (100 extents).
- Logical volume test1/ext successfully resized.
- [root@server1 ~]# e2fsck -f /dev/test1/ext
- e2fsck 1.45.4 (23-Sep-2019)
- Pass 1: Checking inodes, blocks, and sizes
- Pass 2: Checking directory structure
- Pass 3: Checking directory connectivity
- Pass 4: Checking reference counts
- Pass 5: Checking group summary information
- /dev/test1/ext: 11/101200 files (0.0% non-contiguous), 23297/409600 blocks
- 5.挂载查看
- [root@server1 ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 20G 0 disk
- ├─test1-lv 253:2 0 420M 0 lvm /root/lvv
- └─test1-ext 253:3 0 400M 0 lvm
- sdb 8:16 0 20G 0 disk
- sdc 8:32 0 20G 0 disk
- sr0 11:0 1 7.9G 0 rom /root/sr0
- nvme0n1 259:0 0 20G 0 disk
- ├─nvme0n1p1 259:1 0 1G 0 part /boot
- └─nvme0n1p2 259:2 0 19G 0 part
- ├─rhel-root 253:0 0 17G 0 lvm /
- └─rhel-swap 253:1 0 2G 0 lvm [SWAP]
- [root@server1 ~]# mount /dev/test1/ext /root/ext/
- [root@server1 ~]# df -TH
- Filesystem Type Size Used Avail Use% Mounted on
- devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
- tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
- tmpfs tmpfs 2.0G 11M 2.0G 1% /run
- tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
- /dev/mapper/rhel-root xfs 19G 5.3G 13G 29% /
- /dev/nvme0n1p1 xfs 1.1G 241M 824M 23% /boot
- tmpfs tmpfs 394M 1.2M 393M 1% /run/user/42
- tmpfs tmpfs 394M 4.1k 394M 1% /run/user/1000
- /dev/sr0 iso9660 8.5G 8.5G 0 100% /root/sr0
- /dev/mapper/test1-lv xfs 435M 11M 425M 3% /root/lvv
- /dev/mapper/test1-ext ext4 398M 2.4M 371M 1% /root/ext
复制代码
非LVM扩容- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 20G 0 disk
- ├─sda1 8:1 0 300M 0 part /boot
- ├─sda2 8:2 0 2G 0 part [SWAP]
- └─sda3 8:3 0 17.7G 0 part /
- sr0 11:0 1 61.2M 0 rom
- sr1 11:1 1 9.5G 0 rom
复制代码对设备原有磁盘大小进行扩容
- [gh@localhost ~]$ lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 31G 0 disk
- ├─sda1 8:1 0 300M 0 part /boot
- ├─sda2 8:2 0 2G 0 part [SWAP]
- └─sda3 8:3 0 17.7G 0 part /
- sr0 11:0 1 1024M 0 rom
- [gh@localhost ~]$ df -TH
- Filesystem Type Size Used Avail Use% Mounted on
- devtmpfs devtmpfs 938M 0 938M 0% /dev
- tmpfs tmpfs 954M 0 954M 0% /dev/shm
- tmpfs tmpfs 954M 11M 944M 2% /run
- tmpfs tmpfs 954M 0 954M 0% /sys/fs/cgroup
- /dev/sda3 xfs 20G 5.5G 14G 29% /
- /dev/sda1 xfs 312M 171M 141M 55% /boot
- tmpfs tmpfs 191M 13k 191M 1% /run/user/42
- tmpfs tmpfs 191M 0 191M 0% /run/user/1000
- [gh@localhost ~]$
- 通过fdisk做根目录扩容
- [root@localhost ~]# fdisk /dev/sda
- 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.
- Command (m for help): m
- Command action
- a toggle a bootable flag #切换可启动标志
- b edit bsd disklabel #编辑BSD磁盘标签
- c toggle the dos compatibility flag #切换DOS兼容性标志
- d delete a partition #删除除一个分区
- g create a new empty GPT partition table #创建一个新的空GPT分区表
- G create an IRIX (SGI) partition table #创建一个IRIX(SGI)分区表
- l list known partition types #列出已知的分区类型
- m print this menu #打印此菜单
- n add a new partition #添加一个新的分区
- o create a new empty DOS partition table #创建一个新的空DOS分区表
- p print the partition table #打印分区表
- q quit without saving changes #不保存更改退出
- s create a new empty Sun disklabel #创建一个新的空Sun磁盘标签
- t change a partition's system id # 更改分区的系统ID
- u change display/entry units #更改显示/条目单位
- v verify the partition table #验证分区表
- w write table to disk and exit #将表写入磁盘并退出
- x extra functionality (experts only) #额外功能(仅限专家)
-
- Command (m for help):p
- Disk /dev/sda: 33.3 GB, 33285996544 bytes, 65011712 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: 0x000ca3d7
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 616447 307200 83 Linux
- /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
- /dev/sda3 4810752 41943039 18566144 83 Linux #根目录,指定开始节点4810752
- Command (m for help):d
- Partition number (1-3, default 3): 3
- Partition 3 is deleted
- Command (m for help): p
- Disk /dev/sda: 33.3 GB, 33285996544 bytes, 65011712 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: 0x000ca3d7
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 616447 307200 83 Linux
- /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
- Command (m for help): n
- Partition type:
- p primary (2 primary, 0 extended, 2 free)
- e extended
- Select (default p): p
- Partition number (3,4, default 3): 3
- First sector (4810752-65011711, default 4810752): 4810752
- Last sector, +sectors or +size{K,M,G} (4810752-65011711, default 65011711): +20G
- Partition 3 of type Linux and of size 20 GiB is set
- Command (m for help): p
- Disk /dev/sda: 33.3 GB, 33285996544 bytes, 65011712 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: 0x000ca3d7
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 616447 307200 83 Linux
- /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
- /dev/sda3 4810752 46753791 20971520 83 Linux #可以看到分区结束位置
- Command (m for help): w #保存退出
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
- The kernel still uses the old table. The new table will be used at
- the next reboot or after you run partprobe(8) or kpartx(8)
- Syncing disks.
- #此时还需要进行磁盘刷新
- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 31G 0 disk
- ├─sda1 8:1 0 300M 0 part /boot
- ├─sda2 8:2 0 2G 0 part [SWAP]
- └─sda3 8:3 0 17.7G 0 part /
- sr0 11:0 1 1024M 0 rom
- [root@localhost ~]# df -TH
- Filesystem Type Size Used Avail Use% Mounted on
- devtmpfs devtmpfs 938M 0 938M 0% /dev
- tmpfs tmpfs 954M 0 954M 0% /dev/shm
- tmpfs tmpfs 954M 11M 944M 2% /run
- tmpfs tmpfs 954M 0 954M 0% /sys/fs/cgroup
- /dev/sda3 xfs 20G 5.5G 14G 29% /
- /dev/sda1 xfs 312M 171M 141M 55% /boot
- tmpfs tmpfs 191M 13k 191M 1% /run/user/42
- tmpfs tmpfs 191M 0 191M 0% /run/user/1000
- [root@localhost ~]# partprobe /dev/sda
- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 31G 0 disk
- ├─sda1 8:1 0 300M 0 part /boot
- ├─sda2 8:2 0 2G 0 part [SWAP]
- └─sda3 8:3 0 20G 0 part /
- sr0 11:0 1 1024M 0 rom
- [root@localhost ~]# df -TH
- Filesystem Type Size Used Avail Use% Mounted on
- devtmpfs devtmpfs 938M 0 938M 0% /dev
- tmpfs tmpfs 954M 0 954M 0% /dev/shm
- tmpfs tmpfs 954M 11M 944M 2% /run
- tmpfs tmpfs 954M 0 954M 0% /sys/fs/cgroup
- /dev/sda3 xfs 20G 5.5G 14G 29% /
- /dev/sda1 xfs 312M 171M 141M 55% /boot
- tmpfs tmpfs 191M 13k 191M 1% /run/user/42
- tmpfs tmpfs 191M 0 191M 0% /run/user/1000
复制代码
|