Resize rootfs of Yocto image

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Resize rootfs of Yocto image

跳至解决方案
6,299 次查看
khang_letruong
Senior Contributor III

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

 

 

 

标签 (1)
0 项奖励
1 解答
6,090 次查看
khang_letruong
Senior Contributor III

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 项奖励
6 回复数
6,064 次查看
khang_letruong
Senior Contributor III

Hi @mrvinny12 ,

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

Regards,

K

标记 (1)
0 项奖励
6,287 次查看
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 项奖励
6,093 次查看
khang_letruong
Senior Contributor III

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 项奖励
6,091 次查看
khang_letruong
Senior Contributor III

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 项奖励
6,294 次查看
Zhiming_Liu
NXP TechSupport
NXP TechSupport

modify conf/local.conf:

IMAGE_ROOTFS_SIZE= "xxxx"

 

nxf65025_0-1646976373652.png

 

0 项奖励
6,292 次查看
khang_letruong
Senior Contributor III

Thanks @Zhiming_Liu ,

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 项奖励