Resize rootfs of Yocto image

cancel
Showing results for 
Search instead for 
Did you mean: 

Resize rootfs of Yocto image

Jump to solution
691 Views
khang_letruong
Senior Contributor II

Dear Community,

I would like to know how to increase the size of the rootfs so that there's more freespace in runtime, please ? For example, I'm bitbaking the imx-image-multimediafor iMX8MP and it takes around 6GB of the 32GB-SDcard, and I expect to use the rest (32GB - 6GB) as freespace to stocking data.

Thanks in advance and best regards,
Khang

 

 

 

Labels (1)
0 Kudos
1 Solution
482 Views
khang_letruong
Senior Contributor II

Hi again @BiyongSUN ,

I found myself 2 things :

1. I should add the expected size for rootfs as long as it is smaller than the free space of SD card (in your example, it seems that you added 1000 MiB by doing 2403 + 1000 = 3403) :

sudo parted /dev/sdb unit MiB resizepart 2 3403

2. I should add partition number (2) into following commands :

$ sudo e2fsck -f /dev/sdb2
$ sudo resize2fs /dev/sdb2
$ sudo e2fsck -f /dev/sdb2

 

Could you confirm that my findings are correct, please ?

Thanks in advance,

Khang

View solution in original post

0 Kudos
6 Replies
456 Views
khang_letruong
Senior Contributor II

Hi @mrvinny12 ,

Thanks but sorry that I found no useful info in your post for my question.

Regards,

K

Tags (1)
0 Kudos
679 Views
BiyongSUN
NXP Employee
NXP Employee

I notice "runtime" in your question.
and it is pure linux command only.
yes it is pure linux command knowledge just. you can do it on your host pc.

The following is example for a sdcard mirror.
you can do it on a real sdcard.
you can burn the image and then resize it. it will be quicker. and save burning time.

you don't need truncate for a real sdcard, of course. 

resize sdcard mirror:

sudo parted imx-image-multimedia-imx8mmevk.wic unit MiB print

Number Start End Size Type File system Flags
1 8.00MiB 91.2MiB 83.2MiB primary fat16 boot, lba
2 96.0MiB 2499MiB 2403MiB primary ext4


truncate -s 3499M imx-image-multimedia-imx8mmevk.wic

sudo parted imx-image-multimedia-imx8mmevk.wic unit MiB resizepart 2 3403

 

Number Start End Size Type File system Flags
1 8.00MiB 91.2MiB 83.2MiB primary fat16 boot, lba
2 96.0MiB 3403MiB 3307MiB primary ext4

sudo kpartx -av imx-image-multimedia-imx8mmevk.wic

sudo e2fsck -f /dev/mapper/loop0p2

sudo resize2fs /dev/mapper/loop0p2

sudo e2fsck -f /dev/mapper/loop0p2

 


sudo kpartx -dv imx-image-multimedia-imx8mmevk.wic

 

sdcard:

assume the sdcard device is /dev/sdb

1. burn

2. resize 

sudo parted /dev/sdb unit MiB resizepart 2 3403

sudo e2fsck -f /dev/sdb

sudo resize2fs /dev/sdb

sudo e2fsck -f /dev/sdb

 

 

0 Kudos
485 Views
khang_letruong
Senior Contributor II

HI @BiyongSUN ,

Could you confirm my following steps for resize the real micro SD card after burning, please ?

1. Print :

 

 

$ sudo parted imx-image-multimedia-imx8mpevk-20220624041813.rootfs.wic unit MiB print
[sudo] password for khang:
Model: (file)
Disk /devel/SW/imx-yocto-bsp-5_10_52-2_1_0/build-xwayland/tmp/deploy/images/imx8mpevk/imx-image-multimedia-imx8mpevk-20220624041813.rootfs.wic: 3016MiB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags
1 8,00MiB 91,2MiB 83,2MiB primary fat16 boot, lba
2 96,0MiB 3016MiB 2920MiB primary ext4

 

 

2. Burn :

 

 

$ sudo dd bs=4M if=imx-image-multimedia-imx8mpevk-20220624041813.rootfs.wic of=/dev/sdb  status=progress
3145728000 bytes (3,1 GB, 2,9 GiB) copied, 102 s, 30,8 MB/s
754+1 records in
754+1 records out

 

 

3. Resize :

 

 

$ sudo parted /dev/sdb unit MiB resizepart 2 3920 // 2920 + 1000 !?!?
[sudo] password for khang: 
Information: You may need to update /etc/fstab.

$ sudo e2fsck -f /dev/sdb
$ sudo resize2fs /dev/sdb
$ sudo e2fsck -f /dev/sdb

 

 

I got Bad magic number error when executing `sudo e2fsck -f /dev/sdb` anyway :

$ sudo e2fsck -f /dev/sdb
e2fsck 1.44.1 (24-Mar-2018)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sdb

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem. If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
or
e2fsck -b 32768 <device>

Found a dos partition table in /dev/sdb

Best regards,

Khang

0 Kudos
483 Views
khang_letruong
Senior Contributor II

Hi again @BiyongSUN ,

I found myself 2 things :

1. I should add the expected size for rootfs as long as it is smaller than the free space of SD card (in your example, it seems that you added 1000 MiB by doing 2403 + 1000 = 3403) :

sudo parted /dev/sdb unit MiB resizepart 2 3403

2. I should add partition number (2) into following commands :

$ sudo e2fsck -f /dev/sdb2
$ sudo resize2fs /dev/sdb2
$ sudo e2fsck -f /dev/sdb2

 

Could you confirm that my findings are correct, please ?

Thanks in advance,

Khang

0 Kudos
686 Views
Qmiller
NXP Employee
NXP Employee

modify conf/local.conf:

IMAGE_ROOTFS_SIZE= "xxxx"

 

nxf65025_0-1646976373652.png

 

0 Kudos
684 Views
khang_letruong
Senior Contributor II

Thanks @Qmiller ,

In this case, will the bitbaked image has the size of xxxx which takes long time to be flashed into SD card, please ? Is there any more optimal solution to resize the rootfs on first boot for example ?

Best regards,
Khang

0 Kudos