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工具進行分區
[[email protected] ~]# 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檢視挂載情況
[[email protected] ~]# 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,後續如果新增可以從擴充分區中新增分區,再按此操作方法增回