Linux調整root根目錄磁盤大小
[root@zabbix ~]# df -h ------------查看磁盤
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 26M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 36G 4.9G 31G 14% / -----------當前36G
/dev/sdb1 591G 4.8G 556G 1% /data
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 1.6G 12K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# fdisk -l -----查看磁盤大小
磁盤 /dev/sda:107.4 GB, 107374182400 字節,209715200 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x0000eb92
設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
磁盤 /dev/sdb:644.2 GB, 644245094400 字節,1258291200 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0xa583bdd7
設備 Boot Start End Blocks Id System
/dev/sdb1 2048 1258291199 629144576 83 Linux
磁盤 /dev/mapper/centos-root:37.7 GB, 37706792960 字節,73646080 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/mapper/centos-swap:4160 MB, 4160749568 字節,8126464 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
[root@zabbix ~]# fdisk /dev/sda ---對磁盤進行分區
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
命令(輸入 m 獲取幫助):m ------查看幫助
命令操作
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
命令(輸入 m 獲取幫助):n ---------輸入 n 新增分區
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p -------------------輸入p 選擇新增主分區並選擇分區號、第一個扇區、最后一個扇區號(在此均用默認值):
分區號 (3,4,默認 3):
起始 扇區 (83886080-209715199,默認為 83886080):
將使用默認值 83886080
Last 扇區, +扇區 or +size{K,M,G} (83886080-209715199,默認為 209715199):
將使用默認值 209715199
分區 3 已設置為 Linux 類型,大小設為 60 GiB
命令(輸入 m 獲取幫助):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: 設備或資源忙.
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)
正在同步磁盤。
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# fdisk -l ------------------------分區完成后再次查看磁盤大小
磁盤 /dev/sda:107.4 GB, 107374182400 字節,209715200 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x0000eb92
設備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
/dev/sda3 83886080 209715199 62914560 83 Linux -----------------------這里多了一個剛分好的磁盤
磁盤 /dev/sdb:644.2 GB, 644245094400 字節,1258291200 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0xa583bdd7
設備 Boot Start End Blocks Id System
/dev/sdb1 2048 1258291199 629144576 83 Linux
磁盤 /dev/mapper/centos-root:37.7 GB, 37706792960 字節,73646080 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤 /dev/mapper/centos-swap:4160 MB, 4160749568 字節,8126464 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# vgdisplay -v -----------------查看卷分組
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <39.00 GiB
PE Size 4.00 MiB
Total PE 9983
Alloc PE / Size 9982 / 38.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID OqYA0k-8Xl3-WXXZ-LnYz-FGiO-LWce-iDBkvS
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ZQAvzL-hZ5D-Pi9v-OweB-JJmL-Xjb1-2pm34N
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:11 +0800
LV Status available
# open 2
LV Size <3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID zg2AcT-jRMl-H5lm-871w-umwY-7DJo-y81b00
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:12 +0800
LV Status available
# open 1
LV Size <35.12 GiB
Current LE 8990
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID W8i5G8-dIuP-6cf6-oS7j-iKYV-Y8Lj-pViCO8
PV Status allocatable
Total PE / Free PE 9983 / 1
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# pvcreate /dev/sda3 -------------為之前新增的分區創建物理卷
Device /dev/sda3 not found. -------------輸入這個命令報錯
[root@zabbix ~]# partprobe ------------輸入 partprobe 解決
[root@zabbix ~]# pvcreate /dev/sda3 ---------------為之前新增的分區創建物理卷
Physical volume "/dev/sda3" successfully created. -----看到提示
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# pvdisplay ------------------------查看結果
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <39.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 9983
Free PE 1
Allocated PE 9982
PV UUID W8i5G8-dIuP-6cf6-oS7j-iKYV-Y8Lj-pViCO8
"/dev/sda3" is a new physical volume of "60.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 60.00 GiB ---------------------------------這個新增的磁盤60G
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID O6ASsi-jn6p-5hEN-iHqj-2Uh1-MRCI-f6nffz
[root@zabbix ~]# vgextend centos /dev/sda3 --------------------擴展卷分組
Volume group "centos" successfully extended
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# lvdisplay -----------------------查看邏輯卷
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID ZQAvzL-hZ5D-Pi9v-OweB-JJmL-Xjb1-2pm34N
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:11 +0800
LV Status available
# open 2
LV Size <3.88 GiB
Current LE 992
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID zg2AcT-jRMl-H5lm-871w-umwY-7DJo-y81b00
LV Write Access read/write
LV Creation host, time localhost, 2020-10-19 10:10:12 +0800
LV Status available
# open 1
LV Size <35.12 GiB
Current LE 8990
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# lvextend -L +60G /dev/centos/root -------------------------------擴展邏輯卷
Size of logical volume centos/root changed from <35.12 GiB (8990 extents) to <95.12 GiB (24350 extents).
Logical volume centos/root successfully resized.
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# xfs_growfs /dev/centos/root --------------------------------擴大文件系統
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2301440 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9205760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4495, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9205760 to 24934400
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]#
[root@zabbix ~]# df -TH ------------------------------完成后再次查看磁盤
文件系統 類型 容量 已用 可用 已用% 掛載點
devtmpfs devtmpfs 8.4G 0 8.4G 0% /dev
tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm
tmpfs tmpfs 8.4G 27M 8.4G 1% /run
tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 103G 5.2G 97G 6% / --------------------------------容量已增加
/dev/sdb1 ext3 635G 5.2G 597G 1% /data
/dev/sda1 xfs 1.1G 194M 871M 19% /boot
tmpfs tmpfs 1.7G 13k 1.7G 1% /run/user/42
tmpfs tmpfs 1.7G 0 1.7G 0% /run/user/0
[root@zabbix ~]#
