Linux下擴展非LVM根分區


引言

  由於機器比較老,沒有采用LVM進行磁盤管理,   以下方案給根磁盤進行擴容

 

第一步:

  修改Vcenter / Vmware 上虛機磁盤容量  50->200

 

 

第二步:

  重建分區

[root@localhost usr]# df -h
文件系統        容量  已用  可用 已用% 掛載點
/dev/sda2        46G   46G  183M  100% /
devtmpfs        906M     0  906M    0% /dev
tmpfs           921M   84K  920M    1% /dev/shm
tmpfs           921M  8.9M  912M    1% /run
tmpfs           921M     0  921M    0% /sys/fs/cgroup
tmpfs           185M   16K  184M    1% /run/user/42
tmpfs           185M     0  185M    0% /run/user/0

 這里需要對 sda2 分區進行重建

 

使用 fdisk /dev/sda

[root@localhost usr]# 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 獲取幫助):p

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

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     8390655     4194304   82  Linux swap / Solaris
/dev/sda2   *     8390656   104857599    48233472   83  Linux

 

 先刪除 /dev/sda2  再新建

命令(輸入 m 獲取幫助):d
分區號 (1,2,默認 2):2
分區 2 已刪除

命令(輸入 m 獲取幫助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
分區號 (2-4,默認 2):
起始 扇區 (8390656-419430399,默認為 8390656):
將使用默認值 8390656
Last 扇區, +扇區 or +size{K,M,G} (8390656-419430399,默認為 419430399):
將使用默認值 419430399
分區 2 已設置為 Linux 類型,大小設為 196 GiB

命令(輸入 m 獲取幫助):p

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

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     8390655     4194304   82  Linux swap / Solaris
/dev/sda2         8390656   419430399   205519872   83  Linux


 

再給 /dev/sda2 打上 boot 標記

命令(輸入 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 獲取幫助):a
分區號 (1,2,默認 2):2

命令(輸入 m 獲取幫助):p

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

   設備 Boot      Start         End      Blocks   Id  System
/dev/sda1            2048     8390655     4194304   82  Linux swap / Solaris
/dev/sda2   *     8390656   419430399   205519872   83  Linux

 

最后保存

命令(輸入 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)
正在同步磁盤。
[root@localhost usr]#

 

第三步:

  重啟機器 並 執行  partprobe 和   partprobe /dev/sda2

[root@localhost usr]# reboot

[root@localhost usr]# partprobe 
[root@localhost ~]# partprobe /dev/sda2

 

第四步:

  擴容根分區

使用 resize2fs或xfs_growfs 對掛載目錄在線擴容
resize2fs 針對文件系統ext2 ext3 ext4
xfs_growfs 針對文件系統xfs

 

查看 fstab 文件 根分區 是 xfs 文件類型

[root@localhost ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed May 22 11:06:24 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=44e9efd2-a177-4740-b042-ef6c68474782 /                       xfs     defaults        0 0
UUID=8b74331f-77a5-4200-9edd-aec674d3010f swap                    swap    defaults        0 0

 

使用  xfs_growfs /dev/sda2 命令進行擴容

[root@localhost ~]# df -h
文件系統        容量  已用  可用 已用% 掛載點
/dev/sda2        46G   46G  182M  100% /
devtmpfs        906M     0  906M    0% /dev
tmpfs           921M   84K  920M    1% /dev/shm
tmpfs           921M  8.9M  912M    1% /run
tmpfs           921M     0  921M    0% /sys/fs/cgroup
tmpfs           185M   16K  184M    1% /run/user/42
tmpfs           185M     0  185M    0% /run/user/0
[root@localhost ~]# xfs_growfs /dev/sda2 
meta-data=/dev/sda2              isize=256    agcount=4, agsize=3014592 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=12058368, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=5887, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12058368 to 51379968
[root@localhost ~]# 
[root@localhost ~]# df -h
文件系統        容量  已用  可用 已用% 掛載點
/dev/sda2       196G   46G  151G   24% /
devtmpfs        906M     0  906M    0% /dev
tmpfs           921M   84K  920M    1% /dev/shm
tmpfs           921M  8.9M  912M    1% /run
tmpfs           921M     0  921M    0% /sys/fs/cgroup
tmpfs           185M   16K  184M    1% /run/user/42
tmpfs           185M     0  185M    0% /run/user/0

 

擴容完成


免責聲明!

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



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