centos 7 扩容 根目录

  1. 先看下我现在根目录的大小

    [root@localhost ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 1.4G     0  1.4G   0% /dev
    tmpfs                    1.4G     0  1.4G   0% /dev/shm
    tmpfs                    1.4G  9.5M  1.4G   1% /run
    tmpfs                    1.4G     0  1.4G   0% /sys/fs/cgroup
    /dev/mapper/centos-root   37G   30G  7.1G  81% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    283M     0  283M   0% /run/user/0
    

    一共37G,用了30G

    fdisk -l 命令查看下磁盘信息

    [root@localhost ~]# fdisk -lu
    
    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: 0x000245fd
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    /dev/sda3        41943040    83886079    20971520   83  Linux
    
    Disk /dev/mapper/centos-root: 39.6 GB, 39619395584 bytes, 77381632 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
    

    /dev/sda 一共42.9G

    /dev/mapper/centos-root 39.6G

    我们就是要扩 /dev/mapper/centos-root

  2. 先在vmware里加硬盘

    需要先将虚拟机断电

    原先40G,扩展到80G

在这里插入图片描述
确定后有一个提示
在这里插入图片描述

我们需要进入操作系统进行分区和扩展文件系统

  1. 开机

    fdisk -lu命令查看,发现 /dev/sda 变成了86.9G

    [root@localhost ~]# fdisk -lu
    
    Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000245fd
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    /dev/sda3        41943040    83886079    20971520   83  Linux
    
    Disk /dev/mapper/centos-root: 39.6 GB, 39619395584 bytes, 77381632 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
    
  2. 从主磁盘创建新空间

    [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.
    
    # n 表示新建
    Command (m for help): n
    Partition type:
       p   primary (3 primary, 0 extended, 1 free)
       e   extended
    Select (default e): p
    Selected partition 4
    First sector (83886080-167772159, default 83886080): 
    Using default value 83886080
    Last sector, +sectors or +size{K,M,G} (83886080-167772159, default 167772159): 
    Using default value 167772159
    Partition 4 of type Linux and of size 40 GiB is set
    # w 表示保存
    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.
    
    # 查看一下添加的情况 /dev/sda4创建出来了
    [root@localhost ~]# fdisk -l
    
    Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000245fd
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200    41943039    19921920   8e  Linux LVM
    /dev/sda3        41943040    83886079    20971520   83  Linux
    /dev/sda4        83886080   167772159    41943040   83  Linux
    
    Disk /dev/mapper/centos-root: 39.6 GB, 39619395584 bytes, 77381632 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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
    
  3. 重启虚拟机

  4. 格式化新分区

    [root@localhost ~]# mkfs.ext3 /dev/sda4
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    2621440 inodes, 10485760 blocks
    524288 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=4294967296
    320 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
    	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    	4096000, 7962624
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   
    
    [root@localhost ~]# 
    
  5. 进入lvm管理

    # 进入lvm
    [root@localhost ~]# lvm
    # 将物理硬盘分区初始化物理卷
    lvm> pvcreate /dev/sda4
    WARNING: ext3 signature detected on /dev/sda4 at offset 1080. Wipe it? [y/n]: y
      Wiping ext3 signature on /dev/sda4.
      Physical volume "/dev/sda4" successfully created.
    # 将初始化分区加入虚拟卷组 这里虚拟卷组要跟之前根目录所在的磁盘的相同
    lvm> vgextend centos /dev/sda4
      Volume group "centos" successfully extended
    # 查看物理卷组情况 (非必须) 
    lvm> pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               <19.00 GiB / not usable 3.00 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              4863
      Free PE               0
      Allocated PE          4863
      PV UUID               dLyV0N-V0ch-qKjf-0gUS-b2Pf-k0lZ-tGjQDZ
       
      --- Physical volume ---
      PV Name               /dev/sda3
      VG Name               centos
      PV Size               20.00 GiB / not usable 4.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              5119
      Free PE               24
      Allocated PE          5095
      PV UUID               E4xrup-R7CN-Jorg-9Zjl-P6jV-4Xq6-3CYQ7X
       
      --- Physical volume ---
      PV Name               /dev/sda4
      VG Name               centos
      PV Size               40.00 GiB / not usable 4.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              10239
      Free PE               10239
      Allocated PE          0
      PV UUID               GVurAS-MceF-0rGj-OUIL-XEAF-nwkE-ww1JCP
    # 进行扩展操作   
    lvm> lvextend -L +40G /dev/mapper/centos-root
      Size of logical volume centos/root changed from <36.90 GiB (9446 extents) to <76.90 GiB (19686 extents).
      Logical volume centos/root successfully resized.
    # 离开lvm
    lvm> quit
      Exiting.
    [root@localhost ~]# 
    
  6. xfs_growfs刷新

    [root@localhost ~]# xfs_growfs /dev/mapper/centos-root
    meta-data=/dev/mapper/centos-root isize=512    agcount=9, agsize=1113856 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=9672704, 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 9672704 to 20158464
    [root@localhost ~]#
    
  7. df -h 查看一下现在根目录

    [root@localhost ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    devtmpfs                 1.4G     0  1.4G   0% /dev
    tmpfs                    1.4G     0  1.4G   0% /dev/shm
    tmpfs                    1.4G  9.4M  1.4G   1% /run
    tmpfs                    1.4G     0  1.4G   0% /sys/fs/cgroup
    # 可用空间变成了48G
    /dev/mapper/centos-root   77G   30G   48G  39% /
    /dev/sda1               1014M  150M  865M  15% /boot
    tmpfs                    283M     0  283M   0% /run/user/0
    

    搞定

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值