Yocto - Create and populate a separate /home partition
Asked Answered
I

2

14

I'm creating quite a simple Yocto image based on x86.

I want the / file system to be readonly, so I set the

IMAGE_FEATURES_append = " read-only-rootfs "

in a custom copy of the original core-image-minimal.bb. I do want to have the /home writable and on a separate partition, though.

So, I'm adding a line

part /home --ondisk sda --fstype=ext4 --label home --align 1024 --size 600

in genericx86.wks. This creates the actual /home partition in the final wic image, but it naturally does not hold any data, as there's no corresponding rootfs for it. This leads to the following quite expected message after boot: No directory, logging in with HOME=/.

There's surprisingly little info about this on the internet. There's this explanation:

It's much more simpler to create or modify build recipes to prepare one rootfs directory per partition.

I just wish there was any reference in the documentation or example on how to achieve that.

I can see that the partitions are being populated by python scripts (plugins) like rootfs.py, and that the image parameters like IMAGE_ROOTFS_SIZE are specified in mentioned image recipe files like the genericx86.wks, but this is just not enough for me to connect these pieces together.

I've read the creating-partitioned-images-using-wic and the linked openembedded kickstart manuals, there are no clues there.

Appreciate someone's kind help.

Inartistic answered 17/5, 2019 at 13:15 Comment(0)
A
19

With WIC you can do something like this:

custom.wks.in:

...

part / --source rootfs --ondisk sda --fstype=ext4 --label system --exclude-path=home/    
part /home --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/home --ondisk sda --fstype=ext4 --label home

...

Note it is important if you want to use ${IMAGE_ROOTFS} in WKS file to name it with .in suffix.

Amphitryon answered 17/5, 2019 at 15:4 Comment(14)
Thanks a lot for your quick and correct reply. I've just tested it, works perfectly and also makes sense. I've copied the original wks file to my layer under wic folder: wic/myfile.wks.in, in my layer's layer.conf added WKS_FILE="myfile.wks.in", and inside the file changed the partitions as per your recommendation. Also there's no problem to add --size setting to set the /home's size.Inartistic
It took so much time to understand how to do it the first time, glad it helped :)Amphitryon
One question here, is size of image(.wic) increased when we add any extra partition? I have just created one partition of 1GB and my image size is increased by 1GB.Housecoat
Wic adds 1Gb when package-management feature is enabled. To fix partition size, you have to set IMAGE_ROOTFS_EXTRA_SPACE = "0", IMAGE_OVERHEAD_FACTOR = "1.0", IMAGE_ROOTFS_SIZE = "<size>", IMAGE_ROOTFS_MAXSIZE = "<size>".Amphitryon
You can also add --fixed-size=1024M to wic lines (and also --align=<blocksize>).Amphitryon
If I want to do this with a new directory that is not there from the beginning, like "foo" instead of "home", will I have to do that in the recipe or in the image?Changeup
@Changeup you can create a "foo" folder from recipe or ROOTFS_POSTPROCESS_COMMAND, it should workAmphitryon
Tried this - it creates the partition, but it's not mounted when the OS boots. What's the recommended way of mounting the partition created above? ROOTFS_POSTPROCESS_COMMAND or modifying the .wks file, or something else?Immiscible
@Tomy normally, WIC automatically adds an entry for each line in /etc/fstab, is it the case for you? maybe you can check boot logs to see if there are any errors regarding disk mounting?Amphitryon
@Amphitryon It is almost perfect but because of some reason, it doesn't preserve the permissions and the ownership of the files I put into the folder of the new partition. Any idea what is going wrong?Cark
@TiborTakács I see that there is a patch for this wic: Fix permissions when using exclude or include path, do your Yocto includes this ?Amphitryon
Hi @Nayfe. But what if the folder that I want to move to a separate partition contains files after rootfs build? How to clean that folder after partitioning? Because it takes space from rootfs partition.Freberg
@Freberg it's what --exclude-path=home/ does, it removes "home" folder from rootfs partition. Or I didn't understand your question :(Amphitryon
@Amphitryon thank you for the quick reply. Oh, I missed that part of your answer. Now everything works wellFreberg
A
0

I encountered the same issue, and the solution proposed by Nayfe did work (a bit) for me: it created the partition and filled it with the content of /home. But the partition was not mounted, and the file permissions in /home were broken.

To mount the partition, I added an entry in /etc/fstab (helped with: Yocto recipe to update /etc/fstab)

To fix the ownership/permission issue, I used --change-directory=home instead of --rootfs-dir=${IMAGE_ROOTFS}/home. (It also fixes the warning emitted during do_image_wic which was helpful in searching for the source of the issue: .../pseudo folder does not exist. Usernames and permissions will be invalid)

Abad answered 13/4, 2023 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.