11

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.

Rachid K.
  • 4,490
  • 3
  • 11
  • 30
fault-tolerant
  • 451
  • 5
  • 15

2 Answers2

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.

Nayfe
  • 2,130
  • 13
  • 18
  • 2
    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. – fault-tolerant May 17 '19 at 17:11
  • It took so much time to understand how to do it the first time, glad it helped :) – Nayfe May 17 '19 at 18:00
  • 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. – Raxesh Oriya Mar 31 '20 at 13:29
  • 1
    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 = ""`, `IMAGE_ROOTFS_MAXSIZE = ""`. – Nayfe Apr 01 '20 at 19:50
  • You can also add `--fixed-size=1024M` to wic lines (and also --align=). – Nayfe Apr 01 '20 at 19:53
  • 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? – alebo611 Nov 06 '20 at 14:23
  • 1
    @alebo611 you can create a "foo" folder from recipe or ROOTFS_POSTPROCESS_COMMAND, it should work – Nayfe Nov 24 '20 at 16:21
  • 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? – Tomy Dec 14 '20 at 23:52
  • @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? – Nayfe Dec 15 '20 at 11:38
  • @Nayfe 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? – Tibor Takács Apr 01 '22 at 16:10
  • @TiborTakács I see that there is a patch for this [wic: Fix permissions when using exclude or include path](https://patchwork.openembedded.org/patch/170778/), do your Yocto includes this ? – Nayfe Apr 04 '22 at 12:36
  • 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. – sopryshko Jan 25 '23 at 04:09
  • 1
    @sopryshko it's what --exclude-path=home/ does, it removes "home" folder from rootfs partition. Or I didn't understand your question :( – Nayfe Jan 25 '23 at 09:00
  • @Nayfe thank you for the quick reply. Oh, I missed that part of your answer. Now everything works well – sopryshko Jan 30 '23 at 04:06
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)