centos7 xfs文件系統的磁盤擴容


1. 找到未使用的磁盤

 df -hT,目前是1T的空間

文件系統                類型      容量  已用  可用 已用% 掛載點
devtmpfs                devtmpfs  7.8G     0  7.8G    0% /dev
tmpfs                   tmpfs     7.8G     0  7.8G    0% /dev/shm
tmpfs                   tmpfs     7.8G  8.9M  7.8G    1% /run
tmpfs                   tmpfs     7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       965G   85G  881G    9% /
/dev/sda1               xfs      1014M  188M  827M   19% /boot
/dev/mapper/centos-home xfs        50G   33M   50G    1% /home
tmpfs                   tmpfs     1.6G     0  1.6G    0% /run/user/0

   fdisk -l

磁盤是2T的容量

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

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  2147483647  1072692224   8e  Linux LVM

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


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


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

  

 

2. 新建分區

fdisk /dev/sda

然后輸入m->n->p->回車->回車->回車->w

然后重起機器 reboot

 

WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).

歡迎使用 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):
起始 扇區 (2147483648-4294967295,默認為 2147483648):
將使用默認值 2147483648
Last 扇區, +扇區 or +size{K,M,G} (2147483648-4294967294,默認為 4294967294):
將使用默認值 4294967294
分區 3 已設置為 Linux 類型,大小設為 1024 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

 

3. 對分區進行格式化,格式化后的文件系統也是xfs格式 

fdisk -l,可以看到新的分區號是3

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

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  2147483647  1072692224   8e  Linux LVM
/dev/sda3      2147483648  4294967294  1073741823+  83  Linux

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


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


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

 對/dev/sda3進行格式化

mkfs.xfs /dev/sda3

meta-data=/dev/sda3              isize=512    agcount=4, agsize=67108864 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=268435455, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=131071, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

  

4. 創建pv

pvcreate /dev/sda3

然后輸入y

WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.

  

5. 處理邏輯卷

vgs

  VG     #PV #LV #SN Attr   VSize     VFree
  centos   1   3   0 wz--n- <1023.00g 4.00m

vgextend centos /dev/sda3

  Volume group "centos" successfully extended

vgs

  VG     #PV #LV #SN Attr   VSize  VFree
  centos   2   3   0 wz--n- <2.00t 1.00t

 可以看到由原來的1023G變成了2T。其中1T是空閑的

df -h 

查看要擴容的文件系統的位置 ,這是是/dev/mapper/centos-root

文件系統                 容量  已用  可用 已用% 掛載點
devtmpfs                 7.8G     0  7.8G    0% /dev
tmpfs                    7.8G     0  7.8G    0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G    1% /run
tmpfs                    7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/centos-root  965G   85G  881G    9% /
/dev/sda1               1014M  188M  827M   19% /boot
/dev/mapper/centos-home   50G   33M   50G    1% /home
tmpfs                    1.6G     0  1.6G    0% /run/user/0

 

lvextend -l +100%free /dev/mapper/centos-root

  Size of logical volume centos/root changed from <965.12 GiB (247070 extents) to 1.94 TiB (509214 extents).
  Logical volume centos/root successfully resized.

 

 

6. 擴容,調整分區

xfs_growfs /dev/mapper/centos-root

meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=63249920 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=252999680, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=123535, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 252999680 to 521435136

 df -h

擴容成功

文件系統                 容量  已用  可用 已用% 掛載點
devtmpfs                 7.8G     0  7.8G    0% /dev
tmpfs                    7.8G     0  7.8G    0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G    1% /run
tmpfs                    7.8G     0  7.8G    0% /sys/fs/cgroup
/dev/mapper/centos-root  2.0T   85G  1.9T    5% /
/dev/sda1               1014M  188M  827M   19% /boot
/dev/mapper/centos-home   50G   33M   50G    1% /home
tmpfs                    1.6G     0  1.6G    0% /run/user/0

  

 

參考文檔  https://blog.51cto.com/11403002/2044689 


免責聲明!

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



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