2021-05-12 14:32:11
RHEL7使用fdisk分割區時無法使用全部分割區的解決辦法
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,後續如果新增可以從擴充套件分割區中新增分割區,再按此操作方法增回
相關文章