Linux在RedHat7上原有四个主分区,分别为sda1,sda2,sda3,sda4,其中sda1为主分区,200M,后面三个主分区共40G,后三个主分区为lvm,目前磁盘空间紧张,由于linux只能划分四个主分区,目前四个主分区已经全部占用了,如果直接删除会导致数据丢失,还好前期分区时做的lvm,为了拓展/dev/rhel/root根分区的空间,/dev/sda3空间最小,使用pvmove命令,将/dev/sda3里的数据全部移到/dev/sda2,然后将/dev/sda3 移除
pvmove /dev/sda3 /dev/sda2
pvremove /dev/sda3
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 63916031 31752192 8e Linux LVM
/dev/sda4 64530432 68724735 2097152 8e Linux LVM
移动完成后,系统空出300M空间,在vmware中扩展硬盘空间到100G,使用partprobe /dev/sda,使用fdisk -l查看硬盘空间,已经显示为107.4G
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c5098
接着使用fdisk /dev/sda添加扩展分区,使用n,选择扩展分区,初始块直接回车,结束块时,不能输入209715200这个结束扇区,只能输入以前系统默认提供的300M空间,重启后问题依旧,无法识别后加的60G空间,怀疑问题是因为这个分区是在中间,无法与后续行成连续分区
使用parted工具进行分区
[root@server ~]# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a
particular partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted)
使用命令print list,看到结束分区为35.6G,使用命令mkpart extended ,输入起始分区36G,输入结束分区107G,使用partprobe /dev/sda更新分区表
使用命令cat /proc/partitions查看是否新增扩展分区/dev/sda3
使用fdisk /dev/sda进行分区,新增30G空间进来/dev/sda5
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 63916031 31752192 8e Linux LVM
/dev/sda3 70311936 209715199 69701632 f W95 Ext’d (LBA)
/dev/sda4 64530432 68724735 2097152 8e Linux LVM
/dev/sda5 70313984 133228543 31457280 83 Linux
接下来使用pvcreate /dev/sda5新增pv
使用vgextend rhel /dev/sda5扩展vg
vgextend rhel /dev/sda5
使用lvextend扩展根分区大小,从/dev/sda5中划分空间
lvextend -L +10G /dev/rhel/root /dev/sda5
使用系统自带的xfs_info查看扇区信息,可以看到每个块为4KB,将10G换算成块为2621440,加上原有的就是5181440
xfs_growfs -D 5242880 /dev/mapper/rhel-root
再使用命令df -h查看挂载情况
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 20G 631M 20G 4% /
devtmpfs 912M 0 912M 0% /dev
tmpfs 921M 164K 921M 1% /dev/shm
tmpfs 921M 9.0M 912M 1% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/rhel-usr 5.0G 4.2G 834M 84% /usr
/dev/mapper/rhel-home 4.9G 115M 4.8G 3% /home
/dev/mapper/rhel-var 9.8G 515M 9.3G 6% /var
/dev/sda1 197M 89M 109M 45% /boot
根目录已经扩展到20G,后续如果新增可以从扩展分区中新增分区,再按此操作方法增回
更多RedHat相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-01/126958.htm