Linux磁盘扩容
上一篇文章https://www.cnblogs.com/zh-dream/p/12683071.html已经对一块盘进行了 分区、创建文件系统、挂载本文展示如何以分区磁盘进行扩容
我们先看分区表格式
[root@master ~]# fdisk -lu /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x45ef390c Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux
再查看分区的文件系统类型
只有创建了文件系统的分区才会有返回结果
[root@master ~]# fdisk -lu /dev/sdc Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0xeed0d630 Device Boot Start End Blocks Id System /dev/sdc1 2048 10487807 5242880 83 Linux /dev/sdc2 10487808 14682111 2097152 83 Linux
[root@master ~]# blkid /dev/sdc2 ## 由于未创建文件系统,并没有输出
[root@master ~]# blkid /dev/sdc1 /dev/sdc1: UUID="9399025f-d5ca-4951-b90a-92e5141f7e7d" TYPE="ext4"
检查文件系统状态
[root@master ~]# echo 123 >/data/num [root@master ~]# xfs_repair /dev/sdb1 xfs_repair: /dev/sdb1 contains a mounted filesystem xfs_repair: /dev/sdb1 contains a mounted and writable filesystem fatal error -- couldn't initialize XFS library [root@master ~]# xfs_repair /dev/sdb1 Phase 1 - find and verify superblock... Phase 2 - using internal log - zero log... - scan filesystem freespace and inode maps... - found root inode chunk Phase 3 - for each AG... - scan and clear agi unlinked lists... - process known inodes and perform inode discovery... - agno = 0 - agno = 1 - agno = 2 - agno = 3 - process newly discovered inodes... Phase 4 - check for duplicate blocks... - setting up duplicate extent list... - check for inodes claiming duplicate blocks... - agno = 0 - agno = 1 - agno = 2 - agno = 3 Phase 5 - rebuild AG headers and trees... - reset superblock... Phase 6 - check inode connectivity... - resetting contents of realtime bitmap and summary inodes - traversing filesystem ... - traversal finished ... - moving disconnected inodes to lost+found ... Phase 7 - verify and correct link counts... done
xfs_repair执行结果解释
1、获取并检查超块信息,如果没有找到超块数据,就结束 2、检查AG头结构信息(AGI,AGF和AGFL)并扫描AGF和AGI btree。 3、使用第2阶段的AGI b+tree,扫描inode树,处理已删除的inode的未链接列表,并查找可能缺少的inode集群。 遍历查找所有的inode,记录使用过的文件系统块(extents)。 对于目录inode,扫描目录结构并查找丢失的inode信息。 所有错误的inode数据都会被删除,包括不可恢复的损坏目录 4、再次扫描inode extents。具有覆盖已使用数据的范围的任何inode都将被删除 5、无论是否发现错误,都会重建AG头结构数据,包括AGI b+tree,AGF b+tree和AGFL。 实时inode也被重建。 6、该阶段,文件系统会处于挂载状态,xfs_repair使用libxfs_mount挂载,修复过程是处于一个挂载状态下执行的,程序会分给它一个挂载入口。 通过扫描分析所有数据的目录。 (1)任何有一定损坏的目录都会用任何可以恢复的条目重建。 (2)重新创建缺少的根目录。 (3)目标中的所有inode都标记为reached.。 最后,所有状态为unreached的inode都会被放到lost+found目录下。 lost+found目录的文件通常是未链接的文件(名字以及被删除),这些文件还被一些进程使用(数据没有删除),比如系统突然关机时(内核panic或突然断电)出现。这些文件会被系统删除。 7、根据阶段6收集的数据修复inode的nlinks
注意:如果之前在/etc/fstab中写入了待扩容分区的自动挂载信息,请务必将其注释掉,以免操作的时候系统突然掉电,出现异常。出现的异常见https://www.cnblogs.com/zh-dream/p/12683769.html
fdisk删除已有分区
查看挂载情况
如果有挂载,请先umount卸载,在执行后面的操作
[root@master ~]# mount|grep /dev/sdc
删除已有分区
[root@master ~]# fdisk /dev/sdc 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/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0x45ef390c Device Boot Start End Blocks Id System /dev/sdc1 2048 4196351 2097152 83 Linux Command (m for help): d Selected partition 1 Partition 1 is deleted Command (m for help): p Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: 0x45ef390c Device Boot Start End Blocks Id System Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
扩容分区
[root@master ~]# fdisk /dev/sdb 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/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x45ef390c Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): Using default value 41943039 Partition 1 of type Linux and of size 20 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
通知内核分区表已更改
[root@master ~]# partprobe /dev/sdb [root@master ~]# lsblk /dev/sdb NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part
扩容文件系统
xfs文件系统:先挂载,在扩容
[root@master ~]# mount /dev/sdb1 /data [root@master ~]# ll /data total 4 -rw-r--r--. 1 root root 4 Apr 11 23:48 num [root@master ~]# xfs_growfs /dev/sdb1 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=524288, 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 524288 to 5242624
对于ext类型的文件系统扩容:先扩容文件系统,再挂载
[root@master ~]# resize2fs /dev/sdb1 resize2fs 1.42.9 (28-Dec-2013) The filesystem is already 5242624 blocks long. Nothing to do! [root@master ~]# mount /dev/sdb1 /data
posted on 2020-04-12 11:17 hopeless-dream 阅读(506) 评论(0) 编辑 收藏 举报