From: Ferry Toth <fntoth@gmail.com> To: linux-btrfs@vger.kernel.org Subject: Re: Howto take a snapshot from an image as ordinary user? Date: Sun, 15 Mar 2020 16:48:09 +0100 [thread overview] Message-ID: <8df0a5eb-79ef-db9e-4b9b-94fc9a8554e6@gmail.com> (raw) In-Reply-To: <d87f9e87-0e77-c758-aae9-f0d069b0e6da@telfort.nl> Op 08-03-2020 om 16:39 schreef Ferry Toth: > Hi > > Op 07-03-2020 om 22:21 schreef Ferry Toth: >> I am generating a btrfs system image using Yocto. >> >> I want to take a snapshot from the image preferably inside a Yocto >> recipe. The snapshot I can send 'over the air' to the remote (IoT) >> device. >> >> Now I am able to loop mount the image file using udisksctl as an >> ordinary user, which mounts the image under /media/ferry. >> >> However, the owner of the mount point is root, and it appears I am not >> allowed to take a snapshot as an ordinary user. > > To clarify, I know that I can chown the mount point after mounting. > But to do that I need to sudo it. I found a way to own the mount point. The procedure is: 1) create an ext34 file system with EXTRA_IMAGECMD_ext3 += " -E root_owner=`/bin/ps -o user= -p $$`:`/bin/ps -o group= -p $$`" Yocto runs the image generation under pseudo (alternative fakeroot). The above allows to create an ext3 file system with the root owned by the real current user. 2) btrfs-convert the ext3 image to btrfs 3) take the snapshot The final step (btrfs send) fails with: ERROR: check if we support uuid tree fails - Operation not permitted ERROR: failed to initialize subvol search: Operation not permitted It appears it just can't be done currently as I could have from: https://webcache.googleusercontent.com/search?q=cache:oZR58gPBVRkJ:https://www.spinics.net/lists/linux-btrfs/msg31188.html+&cd=1&hl=en&ct=clnk&gl=nl&client=ubuntu HOSTTOOLS += " /usr/bin/udisksctl /bin/btrfs /bin/btrfs-convert /bin/ps" # we are running as pseudo but we need ownership of the root as the real user EXTRA_IMAGECMD_ext3 += " -E root_owner=`/bin/ps -o user= -p $$`:`/bin/ps -o group= -p $$`" IMAGE_FSTYPES += " ext3" python do_btrfs_snapshot() { import subprocess # convert the ext3 image cmd_mkimg = 'btrfs-convert ' + d.expand("${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.ext3") ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) # mount the converted ext3 image cmd_mkimg = '/usr/bin/udisksctl loop-setup --no-user-interaction -f ' + d.expand("${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.ext3") ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) loop = ret.stdout.split(' ').pop().split('.')[0] # find the mounted partition cmd_mkimg = 'lsblk -o MOUNTPOINT -n ' + loop ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) mount_point = ret.stdout.rstrip() # take a snapshot of the partition cmd_mkimg = '/bin/btrfs su snap -r ' + mount_point + ' ' + mount_point + '/@new' print(cmd_mkimg) ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) # btrfs send the partition cmd_mkimg = '/bin/btrfs send ' + mount_point + '/@new/ > ' + d.expand("${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.snapshot") ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) print(ret.stdout) print(ret.stderr) # unmount the btrfs image cmd_mkimg = '/usr/bin/udisksctl unmount -b ' + loop ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) # delete the loop device cmd_mkimg = '/usr/bin/udisksctl loop-delete -b ' + loop ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) return 0 } addtask btrfs_snapshot after image_ext3 before do_bootimg >> I think it is obvious that I don't want to run bitbake as root. >> >> So what is the recommended way to generate a snapshot without becoming >> root? >> >> Thanks, >> >> Ferry >> >> > >
WARNING: multiple messages have this Message-ID (diff)
From: Ferry Toth <fntoth@gmail.com> To: Ferry Toth <ftoth@telfort.nl>, linux-btrfs@vger.kernel.org Subject: Re: Howto take a snapshot from an image as ordinary user? Date: Sun, 15 Mar 2020 16:48:09 +0100 [thread overview] Message-ID: <8df0a5eb-79ef-db9e-4b9b-94fc9a8554e6@gmail.com> (raw) Message-ID: <20200315154809.91GT7uImLjBFRclhLHVGCD2iZELKM6B-xfMMwY8jUeU@z> (raw) In-Reply-To: <d87f9e87-0e77-c758-aae9-f0d069b0e6da@telfort.nl> Op 08-03-2020 om 16:39 schreef Ferry Toth: > Hi > > Op 07-03-2020 om 22:21 schreef Ferry Toth: >> I am generating a btrfs system image using Yocto. >> >> I want to take a snapshot from the image preferably inside a Yocto >> recipe. The snapshot I can send 'over the air' to the remote (IoT) >> device. >> >> Now I am able to loop mount the image file using udisksctl as an >> ordinary user, which mounts the image under /media/ferry. >> >> However, the owner of the mount point is root, and it appears I am not >> allowed to take a snapshot as an ordinary user. > > To clarify, I know that I can chown the mount point after mounting. > But to do that I need to sudo it. I found a way to own the mount point. The procedure is: 1) create an ext34 file system with EXTRA_IMAGECMD_ext3 += " -E root_owner=`/bin/ps -o user= -p $$`:`/bin/ps -o group= -p $$`" Yocto runs the image generation under pseudo (alternative fakeroot). The above allows to create an ext3 file system with the root owned by the real current user. 2) btrfs-convert the ext3 image to btrfs 3) take the snapshot The final step (btrfs send) fails with: ERROR: check if we support uuid tree fails - Operation not permitted ERROR: failed to initialize subvol search: Operation not permitted It appears it just can't be done currently as I could have from: https://webcache.googleusercontent.com/search?q=cache:oZR58gPBVRkJ:https://www.spinics.net/lists/linux-btrfs/msg31188.html+&cd=1&hl=en&ct=clnk&gl=nl&client=ubuntu HOSTTOOLS += " /usr/bin/udisksctl /bin/btrfs /bin/btrfs-convert /bin/ps" # we are running as pseudo but we need ownership of the root as the real user EXTRA_IMAGECMD_ext3 += " -E root_owner=`/bin/ps -o user= -p $$`:`/bin/ps -o group= -p $$`" IMAGE_FSTYPES += " ext3" python do_btrfs_snapshot() { import subprocess # convert the ext3 image cmd_mkimg = 'btrfs-convert ' + d.expand("${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.ext3") ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) # mount the converted ext3 image cmd_mkimg = '/usr/bin/udisksctl loop-setup --no-user-interaction -f ' + d.expand("${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.ext3") ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) loop = ret.stdout.split(' ').pop().split('.')[0] # find the mounted partition cmd_mkimg = 'lsblk -o MOUNTPOINT -n ' + loop ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) mount_point = ret.stdout.rstrip() # take a snapshot of the partition cmd_mkimg = '/bin/btrfs su snap -r ' + mount_point + ' ' + mount_point + '/@new' print(cmd_mkimg) ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) # btrfs send the partition cmd_mkimg = '/bin/btrfs send ' + mount_point + '/@new/ > ' + d.expand("${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.snapshot") ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) print(ret.stdout) print(ret.stderr) # unmount the btrfs image cmd_mkimg = '/usr/bin/udisksctl unmount -b ' + loop ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) # delete the loop device cmd_mkimg = '/usr/bin/udisksctl loop-delete -b ' + loop ret = subprocess.run(cmd_mkimg, shell=True, capture_output=True, text=True) return 0 } addtask btrfs_snapshot after image_ext3 before do_bootimg >> I think it is obvious that I don't want to run bitbake as root. >> >> So what is the recommended way to generate a snapshot without becoming >> root? >> >> Thanks, >> >> Ferry >> >> > >
next prev parent reply other threads:[~2020-03-15 15:45 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-03-07 21:21 Howto take a snapshot from an image as ordinary user? Ferry Toth 2020-03-08 15:39 ` Ferry Toth 2020-03-15 15:48 ` Ferry Toth [this message] 2020-03-15 15:48 ` Ferry Toth -- strict thread matches above, loose matches on Subject: below -- 2020-03-07 21:11 Ferry Toth
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=8df0a5eb-79ef-db9e-4b9b-94fc9a8554e6@gmail.com \ --to=fntoth@gmail.com \ --cc=linux-btrfs@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).