• centos 7下使用parted扩展根分区(非LVM)


    非LVM意思是底层分区是物理分区不是通过lvm管理的逻辑卷。

    问题是这样的:

    使用中突然发现根分区空间不足,结果发现分区配成下面这样:

    # lsblk
    NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0     11:0    1 1024M  0 rom
    sr1     11:1    1 1024M  0 rom
    vda    253:0    0  100G  0 disk
    ├─vda1 253:1    0  200M  0 part [SWAP]
    └─vda2 253:2    0  1.8G  0 part /
    vdb    253:16   0  300G  0 disk
    └─vdb1 253:17   0  300G  0 part /data1

    根分区是/dev/vda2,虽然/dev/vda共有100G,但是不知怎么滴给vda2只分配了1.8G(我估计最初是要把vda除了vda1之余的所有空间都给vda2的)。

    如何处理?经过查找资料发现parted有个resizepart命令可以使用,而文件系统好像也有resize之类的命令(没有细看)。因为错误的认知,以为resize之类的操作需要在文件系统unmounted的状态才能进行,所以考虑重启系统进入一种不使用根文件系统的模式,然后再进行处理(当然后面明白,这种做法是完全多余的,因为文件系统的扩大操作可以在文件系统处于挂载状态的时候进行——注意只是扩大)。虽然走了弯路,但是也记录下。

    根分区是xfs文件系统,而且需要显示终端连接了机器。

    步骤:

    1. 重启系统进入启动菜单界面,然后编辑默认的启动菜单项。

    2. 进入编辑界面后,找到linux启动参数那一行。64-Bit IBM Power Series是linux那一行,x86-64 BIOS-based systems是linux16那一行,UEFI systems是linuxefi那一行。然后先从这一行参数中删除rhgbquiet ,再添加 rd.break enforcing=0 到参数行中。(这些操作是参考的RHEL7的system_administrators_guide中关于"Resetting the Root Password Using rd.break"的做法)

    3. 按Ctrl-x,以修改后的参数启动系统。

    4. 启动后,根文件系统是个临时的文件系统,不包含parted命令。原有根分区以只读的方式挂载在/sysroot下面,所以使用parted之前(实际上可以执行使用/sysroot下面的命令,然后当时以为需要卸载/dev/vda2上的文件系统才能操作对/dev/vda进行操作,所以采取的方法是将parted拷贝出来运行),需要执行:
    cp /sysroot/sbin/parted /sbin/
    cp /sysroot/lib64/libparted.so.2 /lib64/
    cp /sysroot/lib64/libdevmapper.so.1.02 /lib64/
    cp /sysroot/lib64/libsepol.so.1 /lib64/
    可能实际中因为版本不同导致这些需要拷贝的文件不同。可以先拷贝parted可执行程序本身,然后运行/sbin/parted /dev/vda,如果缺某个库文件,会报错提示,根据提示再拷贝即可。

    5. 运行/sbin/parted /dev/vda,进入parted界面。先查看下分区状态,确认根分区正好是最后一个分区,然后执行 resizepart 2 100%,其中2是/dev/vda2的分区号(之前可用p命令查看获知),100%表示扩展到最尾部。

    6. 然后以rw方式重新挂载原来的根分区:mount -o remount,rw /sysroot

    7. 执行文件系统扩展: /sysroot/sbin/xfs_growfs /sysroot 。注意xfs_growfs命令也不在那个临时根文件系统下。执行成功后,显示信息的最后一行会提示 "data blocks changed from xxxx to yyyyyy" 只在的信息。

    8. 重启系统,根分区应该就扩展成功了。

    ========================================================================

    实际上对于文件系统增大(扩展)是可以在线(即文件系统本身处于挂载状态)进行的:

    resize2fs的man page说明:

           The resize2fs program will resize ext2, ext3, or ext4 file systems.  It can be used to enlarge or shrink an unmounted file system located on device.  If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the  kernel  supports  on-line resizing.  (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.).

    https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/storage_administration_guide/xfsgrow

    An XFS file system may be grown while mounted using the xfs_growfs command:
    # xfs_growfs /mount/point -D size
    The -D size option grows the file system to the specified size (expressed in file system blocks). Without the -D size option, xfs_growfs will grow the file system to the maximum size supported by the device.

    Note

    While XFS file systems can be grown while mounted, their size cannot be reduced at all.
     
    而parted对分区的操作,我感觉它是不管分区上的文件系统是否处于挂载状态的(补充20211026:后续实践操作表明,parted对/dev/vda2进行resize操作时要求/dev/vda2不处于挂载状态;或者参考末尾两篇文章使用一下fdisk?)。
    所以最后我感觉整个过程可以直接在系统正常启动的情况下,在root账户下,先用parted对/dev/vda2进行resizepart操作,然后执行执行xfs_growfs / 即可。
    我也没有对此进行专门测试,但是参考下面两篇文章,我认为是没有问题的,因为这些文章里面没有提到需要操作系统进到某种特殊模式。
    参考:
    https://www.cnblogs.com/youngchaolin/p/11478740.html
    https://www.jianshu.com/p/9db2df60fd0a
     
     
  • 相关阅读:
    机器学习项目流程(二)探索并可视化数据
    机器学习项目流程(一)初探数据集
    数据类型.md
    keepalived.md
    LVS.md
    tomcat多实例.md
    LANMP常用配置.md
    php-fpm配置参数.md
    Nginx学习.md
    Redis.md
  • 原文地址:https://www.cnblogs.com/csmountains/p/15389937.html
Copyright © 2020-2023  润新知