Skip to main content

目录扩容

[root@aioCloud ~]# lsblk    #查看硬盘容量
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 17.5G  0 part /
sr0     11:0    1  918M  0 rom  
[root@aioCloud ~]# df -Th    #查看目录容量
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        18G  994M   17G   6% /
devtmpfs       devtmpfs  476M     0  476M   0% /dev
tmpfs          tmpfs     487M     0  487M   0% /dev/shm
tmpfs          tmpfs     487M  7.6M  479M   2% /run
tmpfs          tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/sda1      xfs       497M  120M  378M  25% /boot
tmpfs          tmpfs      98M     0   98M   0% /run/user/0
[root@aioCloud ~]# fdisk /dev/sda    #对sda这块硬盘操作
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p    #打印现有分区

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0000ca56

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048     5220351     2097152   82  Linux swap / Solaris
/dev/sda3         5220352    41943039    18361344   83  Linux

Command (m for help): d    #删除分区
Partition number (1-3, default 3): 3    #删除第3块硬盘
Partition 3 is deleted    #第3块硬盘已删除

Command (m for help): n    #新建1个分区
Partition type:
   p   primary (2 primary, 0 extended, 2 free)    #主分区
   e   extended    #扩展分区
Select (default p): p    #选择主分区
Partition number (3,4, default 3):     #默认是3
First sector (5220352-83886079, default 5220352):     #默认是5220352
Using default value 5220352
Last sector, +sectors or +size{K,M,G} (5220352-83886079, default 83886079):     #默认到最大
Using default value 83886079
Partition 3 of type Linux and of size 37.5 GiB is set    #已经设置了第3分区为37.5G

Command (m for help): p    #再次打印分区

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0000ca56

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048     5220351     2097152   82  Linux swap / Solaris
/dev/sda3         5220352    83886079    39332864   83  Linux    #第3个分区已经扩容

Command (m for help): w    #保存所有设置
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
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)
Syncing disks.
[root@aioCloud ~]# partprobe /dev/sda    #刷新sda,通知它硬盘分区发生了变化
[root@aioCloud ~]# lsblk    #查看实际的变化情况
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   40G  0 disk 
├─sda1   8:1    0  500M  0 part /boot
├─sda2   8:2    0    2G  0 part [SWAP]
└─sda3   8:3    0 37.5G  0 part /
sr0     11:0    1  918M  0 rom  
[root@aioCloud ~]# df -Th    #再次查看目录,未更新
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        18G  994M   17G   6% /
devtmpfs       devtmpfs  476M     0  476M   0% /dev
tmpfs          tmpfs     487M     0  487M   0% /dev/shm
tmpfs          tmpfs     487M  7.6M  479M   2% /run
tmpfs          tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/sda1      xfs       497M  120M  378M  25% /boot
tmpfs          tmpfs      98M     0   98M   0% /run/user/0
[root@aioCloud ~]# xfs_growfs /dev/sda3    #使用xfs_growfs对sda3进行同步
meta-data=/dev/sda3              isize=512    agcount=4, agsize=1147584 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4590336, 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 4590336 to 9833216
[root@aioCloud ~]# df -Th    #同步结束后再次查看目录容量情况
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda3      xfs        38G  994M   37G   3% /
devtmpfs       devtmpfs  476M     0  476M   0% /dev
tmpfs          tmpfs     487M     0  487M   0% /dev/shm
tmpfs          tmpfs     487M  7.6M  479M   2% /run
tmpfs          tmpfs     487M     0  487M   0% /sys/fs/cgroup
/dev/sda1      xfs       497M  120M  378M  25% /boot
tmpfs          tmpfs      98M     0   98M   0% /run/user/0
[root@aioCloud ~]#reboot    #最后确定没问题重启测试