vmware中給centos擴展磁盤大小


起因

一開始安裝虛擬機centos的時候給虛擬機分配了100G的磁盤空間,但是呢,安裝的時候我自己給每一個目錄單獨分配了空間。其中一個目錄 “/” 我分配了20G,但是后面有一次打開虛擬機的時候發現這個 “/dev/mapper/centos-root” 路徑提升磁盤利用率99%,建議擴展空間。

[hi@hi~]$ df -hl
文件系統                 容量  已用  可用 已用% 掛載點
...
/dev/mapper/centos-root   20G   20G   0G  99% /
...

 

當時覺得不可思議,明明一開始給虛擬機分配了100G,為啥提示還不夠,后面才知道,這些好像是我自定義分配的大小。既然這樣,只能加大空間了。

謎題破解了:是由於筆者用了docker,但是沒有對docker的日志大小進行限制,導致容器的日志十幾個G

# cd /var/lib/docker/containers
# echo "" > xxx.log

進入到這個目錄上,查看各個文件夾的大小,確定是否是由於docker的日志導致的,是的話把日志清除即可。此外還要對docker-compose.yml或者docker啟動命令加上日志大小限制的命令

方法一:docker-compose.yml
---------------------------
nginx: 
  image: nginx:1.12.1 
  restart: always 
  logging: driver: "json-file"
    options: 
      max-size: "5g"
max-file: "1"
--------------------------- 方法二: docker run增加如下參數,限制生成的json.log單個文件大小和保留文件個數:--log-opt max-size=100m --log-opt max-file=3

 

解決

1、運行 “fdisk -l” 查看一下目前的分區情況,如下,可以看到目前的最大分區是 “/dev/sda2”,一般情況下,新創建的分區默認是 “/dev/sda3”,此外,可以用的磁盤空間是 “/dev/sda”,共107.4GB

[hi@hi ~]# fdisk -l

磁盤 /dev/sda:107.4 GB, 107374182400 字節,209715200 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000aa910

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648    46565375    23076864   8e  Linux LVM

磁盤 /dev/mapper/centos-root:20.5 GB, 21474836480 字節,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節


磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節

 

2、運行 “fdisk /dev/sda”,如下,接着輸入 “m” 查看菜單,"n" 創建新的分區,“p” 主分區(然后設置分區的起始,筆者這里創建一個20G的分區),“w” 保存

[hi@hi ~]# 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
  Partition type:
  p primary (2 primary, 0 extended, 2 free)
  e extended
  Select (default p): p
  分區號 (3,4,默認 3):回車
  起始 扇區 (46565376-209715199,默認為 46565376):回車
  將使用默認值 46565376
  Last 扇區, +扇區 or +size{K,M,G} (46565376-209715199,默認為 209715199):+20G
  分區 3 已設置為 Linux 類型,大小設為 20 GiB

  命令(輸入 m 獲取幫助):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)
  正在同步磁盤。

 

3、查看分區情況,可以看到我們剛剛創建的 sda3

[hi@hi ~]# fdisk -l

磁盤 /dev/sda:107.4 GB, 107374182400 字節,209715200 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節
磁盤標簽類型:dos
磁盤標識符:0x000aa910

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648    46565375    23076864   8e  Linux LVM
/dev/sda3        46565376    88508415    20971520   83  Linux

磁盤 /dev/mapper/centos-root:42.9 GB, 42949672960 字節,83886080 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節


磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/物理):512 字節 / 512 字節
I/O 大小(最小/最佳):512 字節 / 512 字節

 

4、重啟下

[hi@hi ~]# reboot

 

5、創建邏輯卷

[hi@hi ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created

 

6、vgs查看vg組

[hi@hi ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   1   3   0 wz--n- 40.00g 4.00m

 

7、擴展vg

[hi@hi ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended

 

8、vg已經擴展了,查看lv情況

[hi@hi ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree 
  centos   2   3   0 wz--n- 60.00g 20.00g
[hi@hi ~]# lvs LV VG Attr LSize Pool Origin Data
% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- 10.00g root centos -wi-ao---- 20.00g swap centos -wi-ao---- 10.00g

 

9、擴展lv

[hi@hi ~]# lvextend -L +20G /dev/mapper/centos-root
  Size of logical volume centos/root changed from 20.00 GiB (5120 extents) to 40.00 GiB (10240 extents).
  Logical volume centos/root successfully resized.

 

10、lv已經擴展,查看磁盤情況

[hi@hi ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  home centos -wi-ao---- 10.00g                                                    
  root centos -wi-ao---- 40.00g                                                    
  swap centos -wi-ao---- 10.00g       
[hi@hi ~]#
df -hl 文件系統 容量 已用 可用 已用% 掛載點 ... /dev/mapper/centos-root 20G 20G 0G 99% / ...

 

11、由於磁盤大小還每刷新,這里刷新下,再次查看,擴展成功

[hi@hi ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1310720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5242880, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5242880 to 10485760

[hi@hi ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 ... /dev/mapper/centos-root 40G 20.0G 20G 50% / ... [hi@hi ~]#

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM