Home > Mobile >  Extend rootfs partition at runtime
Extend rootfs partition at runtime

Time:09-23

I have an embedded Linux board with 16Go eMMC flash.

When I boot the image and I run fdisk -l I get this:

root@menzu:~# fdisk -l
Disk /dev/mmcblk2: 14.62 GiB, 15678308352 bytes, 30621696 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
Disklabel type: dos
Disk identifier: 0xe00e5569

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk2p1 *     16384  186775  170392 83.2M  c W95 FAT32 (LBA)
/dev/mmcblk2p2      196608 9177991 8981384  4.3G 83 Linux

As you can see, my eMMC /dev/mmcblk2 has 14.62 Gb size.

But, my Linux rootfs partiton has only 4.3G,

How can I extend its size at runtime to be 10Gb or 12Gb for example?

I tried resize2fs /dev/mmcblk2p2 but it changed the blocks size to 1K and after that it only shows:

root@menzu:~# resize2fs /dev/mmcblk2p2
resize2fs 1.45.3 (14-Jul-2019)
The filesystem is already 1122673 (4k) blocks long.  Nothing to do!

I can force the Yocto build to be 12Go, but that's not a good solution cuz the image will be large.

CodePudding user response:

You need to change the size of your partition with fdisk before using resize2fs: delete the current partition and create a new one that starts at the same block as the one you deleted.

For example:

$ fdisk /dev/mmcblk1

Welcome to fdisk (util-linux 2.34).
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/mmcblk1: 27.86 GiB, 29896998912 bytes, 58392576 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
Disklabel type: dos
Disk identifier: 0x35a60061

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk1p1 *     16384  186775  170392 83.2M  c W95 FAT32 (LBA)
/dev/mmcblk1p2      196608 7071881 6875274  3.3G 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/mmcblk1: 27.86 GiB, 29896998912 bytes, 58392576 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
Disklabel type: dos
Disk identifier: 0x35a60061

Device         Boot Start    End Sectors  Size Id Type
/dev/mmcblk1p1 *    16384 186775  170392 83.2M  c W95 FAT32 (LBA)

Command (m for help): 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-58392575, default 2048): 196608
Last sector,  /-sectors or  /-size{K,M,G,T,P} (196608-58392575, default 58392575): 

Created a new partition 2 of type 'Linux' and of size 27.8 GiB.
Partition #2 contains a ext4 signature.

Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): p

Disk /dev/mmcblk1: 27.86 GiB, 29896998912 bytes, 58392576 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
Disklabel type: dos
Disk identifier: 0x35a60061

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk1p1 *     16384   186775   170392 83.2M  c W95 FAT32 (LBA)
/dev/mmcblk1p2      196608 58392575 58195968 27.8G 83 Linux

Command (m for help): w
The partition table has been altered.
Syncing disks.

After that you need to reboot and run resize2fs.

  • Related