美文网首页
Linux 服务器磁盘在线扩容

Linux 服务器磁盘在线扩容

作者: 1ea3ddc2812b | 来源:发表于2022-06-19 14:34 被阅读0次

    CentOS 7 非 LVM 根分区扩容步骤

    1、查看现有分区大小

    [root@localhost ~]# df -Th
    Filesystem Type Size Used Avail Use% Mounted on
    devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
    tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
    tmpfs tmpfs 3.9G 13M 3.8G 1% /run
    tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
    /dev/sda3 xfs 18G 18G 654M 97% /
    /dev/sda1 xfs 297M 164M 134M 55% /boot
    tmpfs tmpfs 781M 48K 781M 1% /run/user/1000
    tmpfs tmpfs 781M 0 781M 0% /run/user/0
    [root@localhost ~]#

    如果你的磁盘空间还很大,可以快速写入一个大文件将磁盘空间填充
    下面的命令是快速的生成一个文件名为 big_file 大小为 1300*10MB 大小的文件
    [root@localhost ~]# dd if=/dev/zero of=big_file count=1300 bs=10MB

    2、对磁盘空间进行扩容,扩容后再查看磁盘空间的大小

    [root@localhost ~]# df -Th
    Filesystem Type Size Used Avail Use% Mounted on
    devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
    tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
    tmpfs tmpfs 3.9G 13M 3.8G 1% /run
    tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
    /dev/sda3 xfs 18G 18G 655M 97% /
    /dev/sda1 xfs 297M 164M 134M 55% /boot
    tmpfs tmpfs 781M 8.0K 781M 1% /run/user/42
    tmpfs tmpfs 781M 0 781M 0% /run/user/0
    [root@localhost ~]#

    [root@localhost ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 25G 0 disk
    ├─sda1 8:1 0 300M 0 part /boot
    ├─sda2 8:2 0 2G 0 part [SWAP]
    └─sda3 8:3 0 17.7G 0 part /
    sr0 11:0 1 1024M 0 rom
    [root@localhost ~]#

    3、进行分区扩展磁盘

    [root@localhost ~]# fdisk /dev/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: 26.8 GB, 26843545600 bytes, 52428800 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: 0x000ad816

    Device Boot Start End Blocks Id System
    /dev/sda1 * 2048 616447 307200 83 Linux
    /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
    /dev/sda3 4810752 41943039 18566144 83 Linux

    Command (m for help): d
    Partition number (1-3, default 3):
    Partition 3 is deleted

    Command (m for help): n
    Partition type:
    p primary (2 primary, 0 extended, 2 free)
    e extended
    Select (default p): p
    Partition number (3,4, default 3):
    First sector (4810752-52428799, default 4810752):
    Using default value 4810752
    Last sector, +sectors or +size{K,M,G} (4810752-52428799, default 52428799):
    Using default value 52428799
    Partition 3 of type Linux and of size 22.7 GiB is set

    Command (m for help): p

    Disk /dev/sda: 26.8 GB, 26843545600 bytes, 52428800 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: 0x000ad816

    Device Boot Start End Blocks Id System
    /dev/sda1 * 2048 616447 307200 83 Linux
    /dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris
    /dev/sda3 4810752 52428799 23809024 83 Linux

    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@localhost ~]#

    4、刷新分区

    [root@localhost ~]# partprobe /dev/sda

    5、查看分区状态

    [root@localhost ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 25G 0 disk
    ├─sda1 8:1 0 300M 0 part /boot
    ├─sda2 8:2 0 2G 0 part [SWAP]
    └─sda3 8:3 0 22.7G 0 part /
    sr0 11:0 1 1024M 0 rom
    [root@localhost ~]#

    6、刷新根分区并查看状态

    [root@localhost ~]# xfs_growfs /dev/sda3
    meta-data=/dev/sda3 isize=512 agcount=4, agsize=1160384 blks
    = sectsz=512 attr=2, projid32bit=1
    = crc=1 finobt=0 spinodes=0
    data = bsize=4096 blocks=4641536, 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 4641536 to 5952256
    [root@localhost ~]#

    [root@localhost ~]# df -Th
    Filesystem Type Size Used Avail Use% Mounted on
    devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev
    tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
    tmpfs tmpfs 3.9G 13M 3.8G 1% /run
    tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
    /dev/sda3 xfs 23G 18G 5.7G 76% /
    /dev/sda1 xfs 297M 164M 134M 55% /boot
    tmpfs tmpfs 781M 12K 781M 1% /run/user/42
    tmpfs tmpfs 781M 0 781M 0% /run/user/0
    [root@localhost ~]#

    相关文章

      网友评论

          本文标题:Linux 服务器磁盘在线扩容

          本文链接:https://www.haomeiwen.com/subject/dosrvrtx.html