修改磁盘空间
关闭CentOS服务器,在VisualBox管理工具中进入菜单: 管理 -> 虚拟介质管理
分配空间
启动服务器,进入控制台
- 执行命令: fdisk -l
```shell [root@hyperledger141 ~]# fdisk -l
磁盘 /dev/sda:34.4 GB, 34359738368 字节,67108864 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x0000e6ff
设备 Boot Start End Blocks Id System /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 16777215 7339008 8e Linux LVM
磁盘 /dev/mapper/centos-root:6652 MB, 6652166144 字节,12992512 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:859 MB, 859832320 字节,1679360 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节
其中第一行显示当前磁盘的总空间及扇区个数(67108864),第12行End列显示当前使用的扇区个数(16777215),因此存在剩余空间
2. 执行命令: **fdisk /dev/sda**
```shell
[root@hyperledger141 ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
分区号 (3,4,默认 3):
起始 扇区 (16777216-67108863,默认为 16777216):
将使用默认值 16777216
Last 扇区, +扇区 or +size{K,M,G} (16777216-67108863,默认为 67108863):
将使用默认值 67108863
分区 3 已设置为 Linux 类型,大小设为 24 GiB
命令(输入 m 获取帮助):
需要输入参数时,都是用回车作为默认值即可
- 保存分区配置:完成后输入命令w进行保存 ```shell 命令(输入 m 获取帮助):w The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙. 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) 正在同步磁盘。
4. 再次查看**fdisk -l**,可以看到最后的扇区与最大值已经相同了
```shell
[root@hyperledger141 ~]# fdisk -l
磁盘 /dev/sda:34.4 GB, 34359738368 字节,67108864 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0000e6ff
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 16777215 7339008 8e Linux LVM
/dev/sda3 16777216 67108863 25165824 83 Linux
磁盘 /dev/mapper/centos-root:6652 MB, 6652166144 字节,12992512 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:859 MB, 859832320 字节,1679360 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
新增加的设备为/dev/sda3
- 重启服务器,使配置生效,使用df -hl查看磁盘空间
此时磁盘并未生效[root@hyperledger141 ~]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 908M 0 908M 0% /dev
tmpfs 919M 4.0K 919M 1% /dev/shm
tmpfs 919M 8.6M 911M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/mapper/centos-root 6.2G 6.2G 20K 100% /
/dev/sda1 1014M 188M 827M 19% /boot
tmpfs 184M 0 184M 0% /run/user/0
磁盘分区并格式化
格式化分区:mkfs.xfs /dev/sda3
[root@hyperledger141 ~]# mkfs.xfs /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1572864 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=6291456, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=3072, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
此处/dev/sda3为前面新增加的磁盘设备名称
创建物理卷:pvcreate /dev/sda3
[root@hyperledger141 ~]# pvcreate /dev/sda3
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
查看卷组:pvdisplay
[root@hyperledger141 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <7.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 1791
Free PE 0
Allocated PE 1791
PV UUID kSBHTp-cBQ6-ackG-oYJa-vgzw-l7a9-BV03fI
"/dev/sda3" is a new physical volume of "24.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 24.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 5i9gtW-Gba0-X35r-xlM3-AONx-IANK-FOO3mM
第4行,原有的磁盘卷组名为centos
将新创建的卷加入卷组:vgextend centos /dev/sda3,如果报错请参考《遇到的问题》
[root@hyperledger141 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
扩展逻辑卷:lvextend -L 30G /dev/centos/root
[root@hyperledger141 ~]# lvextend -L 30G /dev/centos/root
Size of logical volume centos/root changed from <6.20 GiB (1586 extents) to 30.00 GiB (7680 extents).
Logical volume centos/root successfully resized.
扩展文件系统:xfs_growfs /dev/centos/root
[root@hyperledger141 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=406016 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1624064, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
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 1624064 to 7864320
再次执行df -hl
[root@hyperledger141 ~]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 908M 0 908M 0% /dev
tmpfs 919M 4.0K 919M 1% /dev/shm
tmpfs 919M 8.7M 911M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/mapper/centos-root 30G 6.1G 24G 21% /
/dev/sda1 1014M 188M 827M 19% /boot
tmpfs 184M 0 184M 0% /run/user/0
第7行显示了新的文件大小
至此完成了磁盘的扩容
遇到的问题
错误:Couldn’t create temporary archive name.
- 问题:在执行vgextend centos /dev/sda3命令时,提示 Couldn’t create temporary archive name.
- 解决:由于磁盘空间满了才进行扩容的,扩容前磁盘空间如下:
第7行,整个磁盘只剩下20KB了,空间不足以执行命令,所以需要先删除部分不要的文件[root@hyperledger141 ~]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 908M 0 908M 0% /dev
tmpfs 919M 4.0K 919M 1% /dev/shm
tmpfs 919M 8.7M 911M 1% /run
tmpfs 919M 0 919M 0% /sys/fs/cgroup
/dev/mapper/centos-root 6.2G 6.2G 20K 100% /
/dev/sda1 1014M 188M 827M 19% /boot
tmpfs 184M 0 184M 0% /run/user/0