openwrt分区有很多方式, 可以直接ssh到openwrt上, 也可以将TF卡拔出来, 放到其他Linux上进行分区操作 当时想着图简单, 将TF卡拔出来放到Ubuntu上使用Gparted分区, 但是总是在最后一步报错. 使用命令行进行最后一步也是报错. resize2fs: Invalid argument While trying to add group #1
查了相关资料后解决了分区问题.记录如下:
一、 查看当前分区详情
sda 8:0 1 14.8G 0 disk ├─sda1 8:1 1 64M 0 part /media/wang/boot └─sda2 8:2 1 5G 0 part /media/wang/rootfs
二、 重新对/media/wang/rootfs进行分区
分区思路: 先删除/media/wang/rootfs 再从原来的起点重新分区达到扩容的目的
2.0 进入交互模式: fdisk /dev/sda
wang@ubuntu:~$ sudo fdisk /dev/sda Welcome to fdisk (util-linux 2.37.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea. It's recommended to umount all file systems, and swapoff all swap partitions on this disk.
2.1 打印当前分区表: p
记住/dev/sda2 开始的数值 147456
Command (m forhelp): p
Disk /dev/sda: 14.84 GiB, 15931539456 bytes, 31116288 sectors Disk model: Storage Device Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4005cfed
Device Boot Start End Sectors Size Id Type /dev/sda1 * 8192 139263 131072 64M c W95 FAT32 (LBA) /dev/sda2 147456 21121023 20973568 10G 83 Linux
2.2 删除分区: d
Command (m forhelp): d Partition number (1,2, default 2): 2 Partition 2 has been deleted.
2.3 创建新分区: n
Command (m forhelp): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): 2 First sector (2048-31116287, default 2048): 147456 ## 注意这里的First sector的数值是上面我们要记住的147456 Last sector, +/-sectors or +/-size{K,M,G,T,P} (147456-31116287, default 31116287): +5g ## 要扩容的大小
Created a new partition 2 of type'Linux' and of size 5 GiB. Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n ## 保留原有标识
2.4 保存分区信息: w
Command (m forhelp): w The partition table has been altered. Syncing disks.
2.5 更新分区大小
wang@ubuntu:~$ sudo resize2fs -p /dev/sda2 resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/sda2 is mounted on /media/wang/rootfs; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/sda2 to 1310720 (4k) blocks. resize2fs: Invalid argument While trying to add group #1
可以看到这里resize2fs 发生报错 报错信息: resize2fs: Invalid argument While trying to add group #1
wang@ubuntu:~$ sudo e2fsck -f /dev/loop100 e2fsck 1.46.5 (30-Dec-2021) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information Padding at end of inode bitmap is not set. Fix<y>? yes
rootfs: ***** FILE SYSTEM WAS MODIFIED ***** rootfs: 1421/6656 files (0.0% non-contiguous), 5486/32768 blocks wang@ubuntu:~$ wang@ubuntu:~$ sudo resize2fs /dev/loop100 resize2fs 1.46.5 (30-Dec-2021) Resizing the filesystem on /dev/loop100 to 1310720 (4k) blocks. The filesystem on /dev/loop100 is now 1310720 (4k) blocks long.