zoukankan      html  css  js  c++  java
  • Centos7扩容磁盘实操

    实操
    查看使用情况

    列出各分区使用情况

    [root@space ~]# df -hl
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   36G   33G  3.2G   92% /
    devtmpfs                 3.9G     0  3.9G    0% /dev
    tmpfs                    3.9G   88K  3.9G    1% /dev/shm
    tmpfs                    3.9G  8.7M  3.9G    1% /run
    tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
    /dev/sda1                497M  261M  237M   53% /boot
    tmpfs                    782M   12K  782M    1% /run/user/0
    tmpfs                    782M  4.0K  782M    1% /run/user/988

     
    可以看见/dev/mapper/centos-root 已经使用了92%,我们准备为它扩容。
    创建新分区

    先看一下现有磁盘情况:

    [root@space ~]# fdisk -l

    磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x0008f3a5

       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048    83886079    41430016   8e  Linux LVM

    磁盘 /dev/sdb:214.7 GB, 214748364800 字节,419430400 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节


    磁盘 /dev/mapper/centos-swap:4177 MB, 4177526784 字节,8159232 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节


    磁盘 /dev/mapper/centos-root:38.2 GB, 38243663872 字节,74694656 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节

    [root@space ~]# lvs
      LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root centos -wi-ao---- 35.62g                                                    
      swap centos -wi-ao----  3.89g                                                    

     
    已经可以看到新磁盘/dev/sdb。
    对新磁盘进行分区

    在fdisk的交互模式中,依次输入:

        n --创建新分区
        p --创建主分区
        <回车> --默认分区编号
        <回车> --默认起始扇区位置。
        <回车> --默认结束扇区位置。
        w --写入分区表

    [root@space ~]# fdisk /dev/sdb
    欢迎使用 fdisk (util-linux 2.23.2)。

    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。

    Device does not contain a recognized partition table
    使用磁盘标识符 0xa91cbf10 创建新的 DOS 磁盘标签。

    命令(输入 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 (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    分区号 (1-4,默认 1):
    起始 扇区 (2048-419430399,默认为 2048):
    将使用默认值 2048
    Last 扇区, +扇区 or +size{K,M,G} (2048-419430399,默认为 419430399):
    将使用默认值 419430399
    分区 1 已设置为 Linux 类型,大小设为 200 GiB

    命令(输入 m 获取帮助):w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    正在同步磁盘。

     

    这样就把整个磁盘分成了一个区。

    再看一下现有磁盘情况

    [root@space ~]# fdisk -l

    磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x0008f3a5

       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048    83886079    41430016   8e  Linux LVM

    磁盘 /dev/sdb:214.7 GB, 214748364800 字节,419430400 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0xa91cbf10

       设备 Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048   419430399   209714176   83  Linux

    磁盘 /dev/mapper/centos-swap:4177 MB, 4177526784 字节,8159232 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节


    磁盘 /dev/mapper/centos-root:38.2 GB, 38243663872 字节,74694656 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节

     

    已经多出了一个新分区

    设备 Boot      Start      End           Blocks   Id  System
    /dev/sdb1      2048       419430399   209714176   83  Linux

     
    扩展根目录

    将新分区用于扩展/root

    先看一下卷分组

    [root@space ~]# vgdisplay -v
        Using volume group(s) on command line.
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               39.51 GiB
      PE Size               4.00 MiB
      Total PE              10114
      Alloc PE / Size       10114 / 39.51 GiB
      Free  PE / Size       0 / 0   
      VG UUID               Ykx8CQ-951y-7BC0-vfDm-h05J-AyyK-XVwBY4
       
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                NarvTO-dKF1-dAfu-3yZD-g1Bd-jUvt-qTGIP6
      LV Write Access        read/write
      LV Creation host, time localhost, 2015-03-31 10:58:34 +0800
      LV Status              available
      # open                 2
      LV Size                3.89 GiB
      Current LE             996
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                nVjnIr-3kdo-ncmg-Qoyw-DQeG-F0Lh-cdzVhi
      LV Write Access        read/write
      LV Creation host, time localhost, 2015-03-31 10:58:35 +0800
      LV Status              available
      # open                 1
      LV Size                35.62 GiB
      Current LE             9118
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
       
      --- Physical volumes ---
      PV Name               /dev/sda2     
      PV UUID               BWUVqr-mVpy-x6gX-bqxU-NJP7-l48n-Lrx9Ke
      PV Status             allocatable
      Total PE / Free PE    10114 / 0

     

    可以看到当前卷分组名为"centos"。

    为之前新增的分区创建物理卷:

    [root@space ~]# pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created

      
    查看结果:

    [root@space ~]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               39.51 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              10114
      Free PE               0
      Allocated PE          10114
      PV UUID               BWUVqr-mVpy-x6gX-bqxU-NJP7-l48n-Lrx9Ke
       
      "/dev/sdb1" is a new physical volume of "200.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb1
      VG Name               
      PV Size               200.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               cKQd9i-eDVI-BO2Y-BNCS-Yaxj-ouKo-PPdRQC

    已经看到新创建的200G大小的物理卷

    扩展卷分组,"centos"是vgdisplay命令查到的卷分组名

    [root@space ~]# vgextend centos /dev/sdb1
      Volume group "centos" successfully extended

        1
        2

    提示成功扩展。

    下面查看一下逻辑卷:

    [root@space ~]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                NarvTO-dKF1-dAfu-3yZD-g1Bd-jUvt-qTGIP6
      LV Write Access        read/write
      LV Creation host, time localhost, 2015-03-31 10:58:34 +0800
      LV Status              available
      # open                 2
      LV Size                3.89 GiB
      Current LE             996
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                nVjnIr-3kdo-ncmg-Qoyw-DQeG-F0Lh-cdzVhi
      LV Write Access        read/write
      LV Creation host, time localhost, 2015-03-31 10:58:35 +0800
      LV Status              available
      # open                 1
      LV Size                35.62 GiB
      Current LE             9118
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1

    可以看到/dev/centos/root目前的LV Size是35.62 G。

    下面扩展逻辑卷/dev/centos/root

    [root@space ~]# lvextend -l +200G /dev/centos/root
      Invalid argument for --extents: +200G
      Error during parsing of command line.
    [root@space ~]# lvextend -L +200G /dev/centos/root
      Insufficient free space: 51200 extents needed, but only 51199 available
    [root@space ~]# lvextend -L +199G /dev/centos/root
      Size of logical volume centos/root changed from 35.62 GiB (9118 extents) to 234.62 GiB (60062 extents).
      Logical volume root successfully resized.

      

    注:+199G是我们新增加的分区大小。

    扩展后,还要执行一步:

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


    将文件系统扩大。
    完成。

        因为安装CentOS用的xfs分区,所以使用命令xfs_growfs扩展文件系统大小。否则的话使用resize2fs命令。

    查看结果:

    [root@space bin]# df -hl
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root  235G   33G  202G   14% /
    devtmpfs                 3.9G     0  3.9G    0% /dev
    tmpfs                    3.9G   88K  3.9G    1% /dev/shm
    tmpfs                    3.9G  8.7M  3.9G    1% /run
    tmpfs                    3.9G     0  3.9G    0% /sys/fs/cgroup
    /dev/sda1                497M  261M  237M   53% /boot
    tmpfs                    782M   16K  782M    1% /run/user/0
    tmpfs                    782M  4.0K  782M    1% /run/user/988



    /root已经扩充到235G
    ————————————————
    版权声明:本文为CSDN博主「zuozewei」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/zuozewei/article/details/82912239

  • 相关阅读:
    IT 已成为最疯狂的加班行业,没有之一
    编程和音乐真的很像吗?
    jquery:
    内存管理机制/垃圾回收机制:
    处理跨域:
    创建Djongo需要改url的地方:
    数据库连接池 DBUtils:
    C# 使用 SAP NCO3.0 调用SAP RFC函数接口
    java反射机制的原理与简单使用
    java反射机制的原理与简单使用
  • 原文地址:https://www.cnblogs.com/quqibinggan/p/13156639.html
Copyright © 2011-2022 走看看