1.1 Linux类型虚拟机磁盘扩容
步骤1 查看磁盘状态
在虚拟机操作系统内的命令行终端上再次执行“fdisk -l”,发现虚拟磁盘总共有416101个柱面,但只使用了其中的208051个柱面,未被使用的柱面就是扩容之后的磁盘,下面需要为未被使用的柱面创建分区。
代码语言:javascript复制[root@yjgltpc-cgzs-2 ~]# fdisk -l
Disk /dev/vda: 214.7 GB, 214748364800 bytes
16 heads, 63 sectors/track, 416101 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00091944
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 208051 104344576 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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/centos-swap: 4093 MB, 4093640704 bytes
255 heads, 63 sectors/track, 497 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/centos-home: 49.1 GB, 49064968192 bytes
255 heads, 63 sectors/track, 5965 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
[root@yjgltpc-cgzs-2 ~]#
步骤2 创建新的分区。
代码语言:javascript复制[root@yjgltpc-cgzs-2 ~]# fdisk /dev/vda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n # 键入“n”创建新的分区
Command action
e extended
p primary partition (1-4)
e # 键入“e”创建扩展分区
Partition number (1-4): 3
First cylinder (1-416101, default 1): 208051 # 键入起始柱面从“208051”开始
Last cylinder, cylinders or size{K,M,G} (208051-416101, default 416101): # 直接回车
Using default value 416101
Command (m for help): p # 键入“p”查看分区创建情况
Disk /dev/vda: 214.7 GB, 214748364800 bytes
16 heads, 63 sectors/track, 416101 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00091944
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 208051 104344576 8e Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3 208051 416101 104857304 5 Extended
Command (m for help): n # 键入“n”创建逻辑分区
Command action
l logical (5 or over)
p primary partition (1-4)
l # 键入“l”选择逻辑分区
First cylinder (208051-416101, default 208051): # 直接回车
Using default value 208051
Last cylinder, cylinders or size{K,M,G} (208051-416101, default 416101):
Using default value 416101
Command (m for help): p # 键入“p”显示所有分区情况
Disk /dev/vda: 214.7 GB, 214748364800 bytes
16 heads, 63 sectors/track, 416101 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00091944
Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 208051 104344576 8e Linux LVM
Partition 2 does not end on cylinder boundary.
/dev/vda3 208051 416101 104857304 5 Extended
/dev/vda5 208051 416101 104857272 83 Linux
Command (m for help): w # 键入“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@yjgltpc-cgzs-2 ~]#
步骤3 重新启动虚拟机操作系统之后,对逻辑分区进行格式化。
代码语言:javascript复制[root@yjgltpc-cgzs-2 ~]# mkfs.ext4 /dev/vda5 # 格式化为ext4文件系统
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214318 blocks
1310715 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@yjgltpc-cgzs-2 ~]#
步骤4 创建物理卷(PV)
代码语言:javascript复制[root@yjgltpc-cgzs-2 ~]# pvcreate /dev/vda5
Physical volume "/dev/vda5" successfully created
[root@yjgltpc-cgzs-2 ~]#
步骤5 查看当前卷组情况。
代码语言:javascript复制[root@yjgltpc-cgzs-2 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 99.51 GiB
PE Size 4.00 MiB
Total PE 25474
Alloc PE / Size 25474 / 99.51 GiB
Free PE / Size 0 / 0 # 表示没有可用的扩展空间
VG UUID YYbZEp-ddOk-gdIC-h0dU-seBF-Enlx-SeYIpP
[root@yjgltpc-cgzs-2 ~]#
步骤6 扩展卷组
代码语言:javascript复制
## 再次查看卷组,发现可扩展空间为100GB。
[root@yjgltpc-cgzs-2 ~]# vgextend /dev/centos /dev/vda5
Volume group "VolGroup" successfully extended
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 199.50 GiB
PE Size 4.00 MiB
Total PE 51073
Alloc PE / Size 25474 / 99.51 GiB
Free PE / Size 25599 / 100.00 GiB
VG UUID YYbZEp-ddOk-gdIC-h0dU-seBF-Enlx-SeYIpP
[root@yjgltpc-cgzs-2 ~]#
步骤7 扩展根分区逻辑卷的容量。
代码语言:javascript复制[root@yjgltpc-cgzs-2 ~]# lvextend -l 100%FREE /dev/centos/root # 扩展所有可用空间到根分区
Extending logical volume lv_root to 150.00 GiB
Logical volume lv_root successfully resized
[root@yjgltpc-cgzs-2 ~]#
步骤8 文件系统的真正扩容
代码语言:javascript复制#上面只是卷扩容了,下面是文件系统的真正扩容,输入以下命令:
#CentOS7下面由于使用的是XFS命令:
#xfs_growfs针对文件系统xfs
#检查数据块大小和数量
xfs_growfs info /dev/centos/root
#将XFS文件扩展到1986208
xfs_growfs /dev/centos/root -D 1986208
#自动扩展XFS文件系统到最大的可用大小
xfs_growfs /dev/centos/root
#/dev/mapper/centos-root是df -h查看到根目录的挂载点,需要扩容的挂载点
xfs_growfs /dev/centos/root
#CentOS6使用命令:
#使用resize2fs对挂载目录在线扩容#resize2fs针对文件系统ext2 ext3 ext4
resize2fs /dev/centos/root
步骤9 查看分区情况
代码语言:javascript复制#发现根分区磁盘容量从原来的“50GB”扩容到“~150GB”。
[root@yjgltpc-cgzs-2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 148G 2.9G 138G 3% /
tmpfs 2.0G 224K 2.0G 1% /dev/shm
/dev/vda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 45G 180M 43G 1% /home
[root@yjgltpc-cgzs-2 ~]#
步骤10 磁盘可用性验证
代码语言:javascript复制# 从远端共享服务器拷贝一个2GB左右的文件到新建磁盘,验证磁盘的可写性。
[root@yjgltpc-cgzs-2 ~]# scp root@192.168.0.6:/vms/isos/file.iso /
root@192.168.0.6's password:
file.iso 100% 1997MB 48.7MB/s 00:41
[root@yjgltpc-cgzs-2 ~]#
问题
问题1:
代码语言:javascript复制[root@yjgltpc-cgzs-2 log]# mkfs.ext4 /dev/vda5
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/vda5 --- No such file or directory
The device apparently does not exist; did you specify it correctly?
解决方法:执行下partprobe 命令
partprobe
partprobe包含在parted的rpm软件包中。partprobe可以修改kernel中分区表,使kernel重新读取分区表。 因此,使用该命令就可以创建分区并且在不重新启动机器的情况下系统能够识别这些分区。
问题2: Couldn’t create temporary archive name.
原来是根分区满了,无法创建归档名称,至少需要1M的剩余空间才能操作。 所以必须先删除一些临时文件. 首先使用如下命令,查找根分区中大于1G的文件。
我的博客即将同步至腾讯云 社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=y982vd2u7c9k