场景1:
linux6.4虚拟机,配置1块5G磁盘,做过LVM,现要将磁盘扩大至21G,并将扩充后的空间加入现存的LVM组。
步骤:
1、在VMware上对磁盘进行扩容(略)
2、查看硬件是否扩容成功
命令: fdisk -l (root用户)
------------------------------------------------------------------------------------------------
[ding@master ~]$ sudo fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c82f5
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1045 7875584 8e Linux LVM
Disk /dev/mapper/vg_master-lv_root: 7205 MB, 7205814272 bytes
255 heads, 63 sectors/track, 876 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/vg_master-lv_swap: 855 MB, 855638016 bytes
255 heads, 63 sectors/track, 104 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
------------------------------------------------------------------------------------------------
发现已经变成21.5G了
3、将多出的空间进行分区。
命令:fdisk /dev/sda
键入p 查看分区数量,得到:
由此判断我们增加的分区号应该为3(dev/sda1,dev/sda2……接下来应该是dev/sda3了吧)
键入n,增加一个分区,得到:
键入 p,主分区,并键入3(编号):
默认起始扇区和结束扇区即可(键入两次Enter)
键入t,修改分区类型为8e:
键入w,写分区表,然后重启系统:
4、对新建分区进行格式化
mkfs.ext4 /dev/sda3
.ext4是自己的文件系统类型,如果不知道的话,可以查询:
parted /dev/sda
(parted) print list
5、卷扩容,添加进LVM组:
lvm> pvcreate /dev/sda3 初始化刚才的分区
lvm> vgextend vg_master /dev/sda3 将初始化过的分区加入到虚拟卷组vg_master
lvm>lvextend -L +12G /dev/vg_master/lv_root 扩展已有卷的容量
(也可使用这条命令将所有剩余空间扩展到已有的LV)
lvm>lvextend -l +100%FREE /dev/vg_master/lv_root
lvm>pvdisplay 查看卷容量
6、文件系统扩容
resize2fs /dev/vg_master/lv_root //ext文件系统
xfs_growfs /dev/vg_master/lv_root //xfs文件系统
查看文件系统类型的Linux命令
不需挂载就能查看的命令:
1. file
[root@localhost dev]# file -s /dev/sda1
/dev/sda1: Linux rev 1.0 ext4 filesystem data (extents) (huge files)
2.parted
[root@localhost dev]# parted /dev/sda
GNU Parted 1.8.8
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 206MB 206MB primary ext3 boot
2 206MB 21.5GB 21.3GB primary lvm
3.fdisk
[root@localhost dev]# fdisk -l /dev/sda
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x0007c1e8
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 2610 20764012+ 8e Linux LVM
需要挂载才能查看的命令:
1.mount
[root@localhost dev]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
/proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
2.df
[root@localhost dev]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
ext3 18320140 3426724 13962808 20% /
/dev/sda1 ext3 194442 13480 170923 8% /boot
tmpfs tmpfs 516908 0 516908 0% /dev/shm
3.stat
[root@localhost /]# stat -f bin
File: "bin"
ID: 3ef5d5f4a8cc1340 Namelen: 255 Type: ext2/ext3
Block size: 4096 Fundamental block size: 4096
Blocks: Total: 4580035 Free: 3723354 Available: 3490702
Inodes: Total: 1163264 Free: 1044678
场景2:
虚拟机中有2块磁盘。
磁盘1:20G,默认安装操作系统,操作系统创建默认的LVM。
磁盘2:50G,安装完操作系统之后添加的,并手动创建了LVM。现需要将第2块磁盘从50G扩大至80G。
步骤:
1、将第2块磁盘在虚拟机设置中调整至80G
2、在linux系统中输入pvresize -v /dev/sdb 扩展PV容量,扩展完后可以用pvdisplay命令查看扩展是否生效。
3、先用lvs命令查看下当前PV下的LV容量是多少,以便于判断操作后是否生效。
4、使用如下命令扩展LV
# lvextend -l +100%free /dev/testvg/testlv
5、再次使用lvs命令查看结果。
6、最后再用命令对文件系统更新容量。
resize2fs /dev/testvg/testlv