zoukankan      html  css  js  c++  java
  • 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

    扩容完成

  • 相关阅读:
    ES6入门详解(二) 解构赋值
    python 入门简述
    webpack4x 简述
    ES6入门详解(一) let const
    关于HTML的简述
    按照in条件排序
    Oracle 优化效率
    input输入框校验
    <a>标签操作
    svn安装
  • 原文地址:https://www.cnblogs.com/blogscc/p/14692728.html
Copyright © 2011-2022 走看看