001、当前的硬盘个数及挂载情况
[root@PC1 ~]# find /dev/ -name "sd*" ## 一共一块硬盘sda, 两个分区 sda1 和 sda2 /dev/sda2 /dev/sda1 /dev/sda [root@PC1 ~]# lsblk ## sda1为系统启动区, sda2 中分为根分区和swap分区 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 19.5G 0 part ├─rhel-root 253:0 0 17.5G 0 lvm / └─rhel-swap 253:1 0 2G 0 lvm [SWAP] sr0 11:0 1 3.5G 0 rom /media/cdrom [root@PC1 ~]# df -Th ## 根分区中文件系统为xfs Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 18G 3.2G 15G 19% / devtmpfs devtmpfs 905M 0 905M 0% /dev tmpfs tmpfs 914M 136K 914M 1% /dev/shm tmpfs tmpfs 914M 8.9M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 xfs 497M 119M 379M 24% /boot /dev/sr0 iso9660 3.5G 3.5G 0 100% /media/cdrom
002、关闭虚拟机, 添加新硬盘,然后启动虚拟机
003、重启虚拟机后,查看硬盘个数及分区、挂载情况:
[root@PC1 Desktop]# find /dev/ -name "sd*" ## 可以看到多出了一块硬盘,sdb /dev/sda2 /dev/sda1 /dev/sda /dev/sdb [root@PC1 Desktop]# lsblk ## 新的硬盘容量为100G NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 19.5G 0 part ├─rhel-root 253:0 0 17.5G 0 lvm / └─rhel-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 100G 0 disk sr0 11:0 1 3.5G 0 rom /media/cdrom [root@PC1 Desktop]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 18G 3.2G 15G 19% / devtmpfs devtmpfs 905M 0 905M 0% /dev tmpfs tmpfs 914M 84K 914M 1% /dev/shm tmpfs tmpfs 914M 8.8M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 xfs 497M 119M 379M 24% /boot
004、对磁盘sdb进行分区
[root@PC1 Desktop]# fdisk /dev/sdb ## 利用fdisk命令对硬盘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 0xdd9be1ec. Command (m for help): n ## 输入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-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): w ## w 保存退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
005、检测分区是否成功
[root@PC1 Desktop]# find /dev/ -name "sd*" ## 多出一个新分区 sdb1 /dev/sdb1 /dev/sda2 /dev/sda1 /dev/sda /dev/sdb
006、对sdb1分区进行格式化
[root@PC1 Desktop]# mkfs.xfs /dev/sdb1 ## 将分区sdb1格式化为xfs文件系统 meta-data=/dev/sdb1 isize=256 agcount=4, agsize=6553536 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=26214144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=12799, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
007、将sdb1分区生成物理卷
[root@PC1 Desktop]# pvcreate /dev/sdb1 ## 将sdb1分区生成为物理卷 WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n] y ## 输入y Wiping xfs signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created
008、查看根分区所属的卷组
[root@PC1 Desktop]# vgdisplay ## 显示出卷组 --- Volume group --- VG Name rhel 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 19.51 GiB ## 卷组大小为20G PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 0 / 0 VG UUID uD8Hr1-2clx-UPXq-AwZK-B72W-s82V-vskol2 [root@PC1 Desktop]# df -Th ## 列出根分区所属卷组 Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 18G 3.2G 15G 19% / devtmpfs devtmpfs 905M 0 905M 0% /dev tmpfs tmpfs 914M 140K 914M 1% /dev/shm tmpfs tmpfs 914M 8.8M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 xfs 497M 119M 379M 24% /boot
009、将sdb1分区加入到rhel卷组
[root@PC1 Desktop]# vgextend rhel /dev/sdb1 ## 将分区sdb1添加到rhel卷组 Volume group "rhel" successfully extended [root@PC1 Desktop]# vgdisplay ## 列出卷组信息 --- Volume group --- VG Name rhel System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 119.50 GiB ## 卷组大小增加了100G PE Size 4.00 MiB Total PE 30593 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 25599 / 100.00 GiB VG UUID uD8Hr1-2clx-UPXq-AwZK-B72W-s82V-vskol2 [root@PC1 Desktop]#
010、扩展根分区
[root@PC1 Desktop]# df -Th ## 查看根分区大小 Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 18G 3.2G 15G 19% / devtmpfs devtmpfs 905M 0 905M 0% /dev tmpfs tmpfs 914M 140K 914M 1% /dev/shm tmpfs tmpfs 914M 8.8M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 xfs 497M 119M 379M 24% /boot [root@PC1 Desktop]# lvextend -L +100G /dev/mapper/rhel-root ## 扩展100G报错 Extending logical volume root to 117.51 GiB Insufficient free space: 25600 extents needed, but only 25599 available [root@PC1 Desktop]# lvextend -L +99G /dev/mapper/rhel-root ## 改变扩展容量的大小, 没有问题 Extending logical volume root to 116.51 GiB Logical volume root successfully resized
011、加载并查看根分区大小
[root@PC1 Desktop]# xfs_growfs /dev/mapper/rhel-root ## 加载 meta-data=/dev/mapper/rhel-root isize=256 agcount=4, agsize=1147392 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=4589568, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 4589568 to 30541824 [root@PC1 Desktop]# df -Th ## 查看此时根分区的大小 Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 117G 3.2G 114G 3% / devtmpfs devtmpfs 905M 0 905M 0% /dev tmpfs tmpfs 914M 140K 914M 1% /dev/shm tmpfs tmpfs 914M 8.8M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 xfs 497M 119M 379M 24% /boot
012、重启虚拟机观测根分区大小
[root@PC1 Desktop]# lsblk ## 查看磁盘及分区 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 19.5G 0 part ├─rhel-root 253:0 0 116.5G 0 lvm / └─rhel-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part └─rhel-root 253:0 0 116.5G 0 lvm / sr0 11:0 1 3.5G 0 rom /media/cdrom [root@PC1 Desktop]# df -Th ## 查看根分区大小, 扩容成功 Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 117G 3.2G 114G 3% / devtmpfs devtmpfs 905M 0 905M 0% /dev tmpfs tmpfs 914M 140K 914M 1% /dev/shm tmpfs tmpfs 914M 8.8M 905M 1% /run tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 iso9660 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 xfs 497M 119M 379M 24% /boot
标签:914M,##,dev,rhel,linux,磁盘,tmpfs,root From: https://www.cnblogs.com/liujiaxin2018/p/17067565.html