Linux最詳細最新的擴容教程以及異常分析

本文基於centos7進行磁盤擴容

1.查看原有磁盤大小

在這裏插入圖片描述

  1. 查看新的磁盤空間是否已經分配
fdisk -l //可以查看空間大小是否已經分配,分配後進行下一步

如果是虛擬機可以使用下圖方式進行擴容

在這裏插入圖片描述

  1. 對新空間進行分區
fdisk /dev/sda

輸入m ,可以查看幫助信息

Command (m for help): m
Command action
  a  toggle a bootable flag
  b  edit bsd disklabel
  c  toggle the dos compatibility flag
  d  delete a partition
  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)

Command (m for help):

增加新的分區

command (m for help):n

選擇基本信息分區,輸入:p

Command (m for help): n
Command action
  e  extended
  p  primary partition (1-4)

回車

 First cylinder (1-15908,default 1):Enter 
(這是回車是指分的默認大小)
    寫入並退出 
        command (m for help):w

在這裏插入圖片描述
在這裏插入圖片描述
在這裏插入圖片描述
完成後,如果提示:
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)
就重啓一下系統識別該磁盤空間

  1. 爲新分配的空間創建一個新的物理卷

鍵入命令:pvcreate /dev/sda3

在這裏插入圖片描述

如果提示sda3找不到,鍵入:partprobe或者重啓虛擬機

在這裏插入圖片描述
在這裏插入圖片描述

  1. 查詢創建的物理卷

可以查到本機物理卷名稱爲“centos”
在這裏插入圖片描述

  1. 使用新增物理卷擴展本地物理卷

在這裏插入圖片描述
在這裏插入圖片描述

  1. 擴展 LVM 的邏輯卷 centos-root

鍵入命令:lvextend -L +1G 加上要擴展的分區名

lvextend -L +1G /dev/centos/root

在這裏插入圖片描述

  1. 調整邏輯卷的大小

此時系統還不認識剛剛添加進來的磁盤的文件系統,所以還需要對文件系統進行擴容。

鍵入:xfs_growfs 加上要擴展的分區名

或者

resize2fs – f 加 上要擴展的分區名

在這裏插入圖片描述

  1. 結束
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章