Topics

Compressing btrfs image

Edson Seabra
 

Hi all.

I'm trying to compress a btrfs rootfs

I added  in "image_types.bbclass:IMAGE_CMD_btrfs ()"  two commands:

1) mount the btrfs image after mkfs.btrfs
2) btrfs filesystem defrag + compress option

But the command mount fails:

mount: /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/temp_btrfs: failed to setup loop device for /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/nodegrid-genericx86-64-20200328134151.rootfs.btrfs.

I saw in image.bbclass the creation of do_image_btrfs task with flag 'fakeroot'.

====== image.bbclass ====
        task = "do_image_%s" % t.replace("-", "_").replace(".", "_")

        d.setVar(task, '\n'.join(cmds))
        d.setVarFlag(task, 'func', '1')
        d.setVarFlag(task, 'fakeroot', '1')
=======================

would the fakeroot flag allow do_image_btrfs execute commands that requires root privilege ?

If not what would be the way to execute the mount command ?

I tried "pseudo mount" but it failed same way...

Thanks in advance.

Edson.

Edson Seabra

Principal Engineer

M +1 510 579 0843

1506169147061_OutlookEmoji-1505330244060_ZPELogo_Email.png1e6c5898-d340-4c90-8c28-e559c26bc7d1.png
46757 Fremont Blvd., Fremont, CA 94538
zpesystems.com | Request a Nodegrid Demo

Edson Seabra
 

I forget to say I'm using zeus...


From: Edson Seabra
Sent: Saturday, March 28, 2020 12:30 PM
To: yocto@... <yocto@...>
Subject: Compressing btrfs image
 
Hi all.

I'm trying to compress a btrfs rootfs

I added  in "image_types.bbclass:IMAGE_CMD_btrfs ()"  two commands:

1) mount the btrfs image after mkfs.btrfs
2) btrfs filesystem defrag + compress option

But the command mount fails:

mount: /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/temp_btrfs: failed to setup loop device for /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/nodegrid-genericx86-64-20200328134151.rootfs.btrfs.

I saw in image.bbclass the creation of do_image_btrfs task with flag 'fakeroot'.

====== image.bbclass ====
        task = "do_image_%s" % t.replace("-", "_").replace(".", "_")

        d.setVar(task, '\n'.join(cmds))
        d.setVarFlag(task, 'func', '1')
        d.setVarFlag(task, 'fakeroot', '1')
=======================

would the fakeroot flag allow do_image_btrfs execute commands that requires root privilege ?

If not what would be the way to execute the mount command ?

I tried "pseudo mount" but it failed same way...

Thanks in advance.

Edson.

Edson Seabra

Principal Engineer

M +1 510 579 0843

1506169147061_OutlookEmoji-1505330244060_ZPELogo_Email.png1e6c5898-d340-4c90-8c28-e559c26bc7d1.png
46757 Fremont Blvd., Fremont, CA 94538
zpesystems.com | Request a Nodegrid Demo

Konrad Weihmann
 

AFAIK there is no way to mount something without root credentials.

fakeroot/pseudo is intercepting some calls before they will reach the kernel, but mounting isn't a supported option - it just makes all child processes think they running under uid 0.

What you could do is try to find an option (https://btrfs.wiki.kernel.org/index.php/Manpage/mkfs.btrfs) which does what you want directly while creating the image.

These options should go then to a variable called EXTRA_IMAGECMD.


On 28.03.20 16:30, Edson Seabra wrote:
Hi all.

I'm trying to compress a btrfs rootfs

I added  in "image_types.bbclass:IMAGE_CMD_btrfs ()"  two commands:

1) mount the btrfs image after mkfs.btrfs
2) btrfs filesystem defrag + compress option

But the command mount fails:

mount: /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/temp_btrfs: failed to setup loop device for /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/nodegrid-genericx86-64-20200328134151.rootfs.btrfs.

I saw in image.bbclass the creation of do_image_btrfs task with flag 'fakeroot'.

====== image.bbclass ====
        task = "do_image_%s" % t.replace("-", "_").replace(".", "_")

        d.setVar(task, '\n'.join(cmds))
        d.setVarFlag(task, 'func', '1')
        d.setVarFlag(task, 'fakeroot', '1')
=======================

would the fakeroot flag allow do_image_btrfs execute commands that requires root privilege ?

If not what would be the way to execute the mount command ?

I tried "pseudo mount" but it failed same way...

Thanks in advance.

Edson.

Edson Seabra

Principal Engineer

M +1 510 579 0843

1506169147061_OutlookEmoji-1505330244060_ZPELogo_Email.png1e6c5898-d340-4c90-8c28-e559c26bc7d1.png
46757 Fremont Blvd., Fremont, CA 94538
zpesystems.com | Request a Nodegrid Demo



      

Gmane Admin
 

Op 28-03-2020 om 21:06 schreef Konrad Weihmann:
AFAIK there is no way to mount something without root credentials.
You can loop mount the image file using udisksctl as an ordinary user, which mounts the image under /media/<user name>.

fakeroot/pseudo is intercepting some calls before they will reach the kernel, but mounting isn't a supported option - it just makes all child processes think they running under uid 0.
What you could do is try to find an option (https://btrfs.wiki.kernel.org/index.php/Manpage/mkfs.btrfs) which does what you want directly while creating the image.
These options should go then to a variable called EXTRA_IMAGECMD.
On 28.03.20 16:30, Edson Seabra wrote:
Hi all.

I'm trying to compress a btrfs rootfs
I wanted to take a snap shot, see this thread:
"How to create a btrfs snapshot in the rootfs image (during build)?"

I found you need to be owner of the root directory of the image, but there is no option to mkfs that with btrfs.
The only route for that I found was create and ext4 image with
'-E root_owner' then btrfs-convert.

But then I found there is no way to 'btrfs send' without becoming root...

See also "Howto take a snapshot from an image as ordinary user?" on lkml.

I added  in "image_types.bbclass:IMAGE_CMD_btrfs ()" two commands:

1) mount the btrfs image after mkfs.btrfs
2) btrfs filesystem defrag + compress option

But the command mount fails:

mount: /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/temp_btrfs: failed to setup loop device for /home/edson/ng-trunk/nodegrid/tmp/work/genericx86_64-poky-linux/nodegrid/1.0-r0/deploy-nodegrid-image-complete/nodegrid-genericx86-64-20200328134151.rootfs.btrfs.

I saw in image.bbclass the creation of do_image_btrfs task with flag 'fakeroot'.

====== image.bbclass ====
        task = "do_image_%s" % t.replace("-", "_").replace(".", "_")

        d.setVar(task, '\n'.join(cmds))
        d.setVarFlag(task, 'func', '1')
        d.setVarFlag(task, 'fakeroot', '1')
=======================

would the fakeroot flag allow do_image_btrfs execute commands that requires root privilege ?

If not what would be the way to execute the mount command ?

I tried "pseudo mount" but it failed same way...

Thanks in advance.

Edson.

*Edson Seabra*

Principal Engineer

M +1 510 579 0843

*E *edson.seabra@... <mailto:alvin.chan@...>

1506169147061_OutlookEmoji-1505330244060_ZPELogo_Email.png1e6c5898-d340-4c90-8c28-e559c26bc7d1.png
46757 Fremont Blvd., Fremont, CA 94538
*zpesystems.com* <https://www.zpesystems.com/>* | **Request a Nodegrid Demo <https://www.zpesystems.com/demo/>*