Can I use a read-write root filesystem disk image as an OverlayFS upperdir?
Is it possible to union-mount an existing disk image containing a root filesystem to the upperdir of an overlayfs mount for read-write access?
I'm trying to union-mount some old disk images to a /tmp/ directory on an Ubuntu 16.04 machine using pre-existing scripts (originally written on Ubuntu 12.04 and ported to 14.04).
The old automation scripts used overlayfs to create and union-mount writable ext2/3 disk images on top of squashfs images — something like this:
cd /tmp
mkdir lower upper union
losetup /dev/loop1 /tmp/image.sfs
losetup /dev/loop2 /tmp/image.ext2
mount -t squashfs -o ro /dev/loop1 /tmp/lower
mount -t ext2 -o rw /dev/loop2 /tmp/upper
mount -t overlayfs -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper overlayfs /tmp/union
They were last used on an 3.x kernel (likely pre-3.18), and that method doesn't seem to work anymore. Overlay now requires a workdir option—e.g.:
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper,workdir=/tmp/work overlay /tmp/union
Q: Is it possible to tweak the automation scripts to mount and use the existing images in a writable state on a 4.x kernel? Can I avoid reformulating them to contain something like root and work directories? In some cases that may break their use elsewhere.
Per the documentation, the workdir has to be an empty directory on the same filesystem as the upperdir to allow for atomic writes. That sounds to me like it is impossible to union-mount root filesystem images as read-write. The workdir would have to exist within the images (separate from their data directory) which isn't possible in a root filesystem image.
I've considered loading up stock Ubuntu 14.04 in a VM for a couple one-offs, but it's not a long term solution.
Best Attempt So Far:
The only solution I've come up with that avoids double-writing the same data to disk is to mount both images as lowerdir values, with upperdir and workdir directories sitting on a tmpfs mount. Then I can use rsync to copy the changes from the tmpfs location to the mounted ext2/3 image after the automated writes are complete and the overlay union has been unmounted—i.e.:
mount -t overlay -o rw,lowerdir=/tmp/upper:/tmp/lower,upperdir=/tmp/tmpfs/root,workdir=/tmp/tmpfs/work overlay /tmp/union
...perform automated reads/writes...
umount /tmp/union
...rsync contents from /tmp/tmpfs/root to /tmp/upper...
It's strictly limited to available RAM, though, and it's an ugly hack to add to all of the automation scripts.
linux root-filesystem overlayfs union-mount
bumped to the homepage by Community♦ 53 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
Is it possible to union-mount an existing disk image containing a root filesystem to the upperdir of an overlayfs mount for read-write access?
I'm trying to union-mount some old disk images to a /tmp/ directory on an Ubuntu 16.04 machine using pre-existing scripts (originally written on Ubuntu 12.04 and ported to 14.04).
The old automation scripts used overlayfs to create and union-mount writable ext2/3 disk images on top of squashfs images — something like this:
cd /tmp
mkdir lower upper union
losetup /dev/loop1 /tmp/image.sfs
losetup /dev/loop2 /tmp/image.ext2
mount -t squashfs -o ro /dev/loop1 /tmp/lower
mount -t ext2 -o rw /dev/loop2 /tmp/upper
mount -t overlayfs -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper overlayfs /tmp/union
They were last used on an 3.x kernel (likely pre-3.18), and that method doesn't seem to work anymore. Overlay now requires a workdir option—e.g.:
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper,workdir=/tmp/work overlay /tmp/union
Q: Is it possible to tweak the automation scripts to mount and use the existing images in a writable state on a 4.x kernel? Can I avoid reformulating them to contain something like root and work directories? In some cases that may break their use elsewhere.
Per the documentation, the workdir has to be an empty directory on the same filesystem as the upperdir to allow for atomic writes. That sounds to me like it is impossible to union-mount root filesystem images as read-write. The workdir would have to exist within the images (separate from their data directory) which isn't possible in a root filesystem image.
I've considered loading up stock Ubuntu 14.04 in a VM for a couple one-offs, but it's not a long term solution.
Best Attempt So Far:
The only solution I've come up with that avoids double-writing the same data to disk is to mount both images as lowerdir values, with upperdir and workdir directories sitting on a tmpfs mount. Then I can use rsync to copy the changes from the tmpfs location to the mounted ext2/3 image after the automated writes are complete and the overlay union has been unmounted—i.e.:
mount -t overlay -o rw,lowerdir=/tmp/upper:/tmp/lower,upperdir=/tmp/tmpfs/root,workdir=/tmp/tmpfs/work overlay /tmp/union
...perform automated reads/writes...
umount /tmp/union
...rsync contents from /tmp/tmpfs/root to /tmp/upper...
It's strictly limited to available RAM, though, and it's an ugly hack to add to all of the automation scripts.
linux root-filesystem overlayfs union-mount
bumped to the homepage by Community♦ 53 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
@Gilles thanks for the retitle to help with exposure, but I do not want to use overlayfs for my root filesystem. I'm trying to union-mount an overlay disk image (that contains root filesystem changes and whiteouts) to theupperdirposition above a read-onlylowerdirroot filesystem image as a temporary mount under/tmp/. Effectively, the old automation scripts are remotely modifying offline user system images that are based on a shared disk image (conceptually similar to how Docker works). The new title may confuse people.
– codewithmichael
Sep 11 '16 at 1:56
add a comment |
Is it possible to union-mount an existing disk image containing a root filesystem to the upperdir of an overlayfs mount for read-write access?
I'm trying to union-mount some old disk images to a /tmp/ directory on an Ubuntu 16.04 machine using pre-existing scripts (originally written on Ubuntu 12.04 and ported to 14.04).
The old automation scripts used overlayfs to create and union-mount writable ext2/3 disk images on top of squashfs images — something like this:
cd /tmp
mkdir lower upper union
losetup /dev/loop1 /tmp/image.sfs
losetup /dev/loop2 /tmp/image.ext2
mount -t squashfs -o ro /dev/loop1 /tmp/lower
mount -t ext2 -o rw /dev/loop2 /tmp/upper
mount -t overlayfs -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper overlayfs /tmp/union
They were last used on an 3.x kernel (likely pre-3.18), and that method doesn't seem to work anymore. Overlay now requires a workdir option—e.g.:
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper,workdir=/tmp/work overlay /tmp/union
Q: Is it possible to tweak the automation scripts to mount and use the existing images in a writable state on a 4.x kernel? Can I avoid reformulating them to contain something like root and work directories? In some cases that may break their use elsewhere.
Per the documentation, the workdir has to be an empty directory on the same filesystem as the upperdir to allow for atomic writes. That sounds to me like it is impossible to union-mount root filesystem images as read-write. The workdir would have to exist within the images (separate from their data directory) which isn't possible in a root filesystem image.
I've considered loading up stock Ubuntu 14.04 in a VM for a couple one-offs, but it's not a long term solution.
Best Attempt So Far:
The only solution I've come up with that avoids double-writing the same data to disk is to mount both images as lowerdir values, with upperdir and workdir directories sitting on a tmpfs mount. Then I can use rsync to copy the changes from the tmpfs location to the mounted ext2/3 image after the automated writes are complete and the overlay union has been unmounted—i.e.:
mount -t overlay -o rw,lowerdir=/tmp/upper:/tmp/lower,upperdir=/tmp/tmpfs/root,workdir=/tmp/tmpfs/work overlay /tmp/union
...perform automated reads/writes...
umount /tmp/union
...rsync contents from /tmp/tmpfs/root to /tmp/upper...
It's strictly limited to available RAM, though, and it's an ugly hack to add to all of the automation scripts.
linux root-filesystem overlayfs union-mount
Is it possible to union-mount an existing disk image containing a root filesystem to the upperdir of an overlayfs mount for read-write access?
I'm trying to union-mount some old disk images to a /tmp/ directory on an Ubuntu 16.04 machine using pre-existing scripts (originally written on Ubuntu 12.04 and ported to 14.04).
The old automation scripts used overlayfs to create and union-mount writable ext2/3 disk images on top of squashfs images — something like this:
cd /tmp
mkdir lower upper union
losetup /dev/loop1 /tmp/image.sfs
losetup /dev/loop2 /tmp/image.ext2
mount -t squashfs -o ro /dev/loop1 /tmp/lower
mount -t ext2 -o rw /dev/loop2 /tmp/upper
mount -t overlayfs -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper overlayfs /tmp/union
They were last used on an 3.x kernel (likely pre-3.18), and that method doesn't seem to work anymore. Overlay now requires a workdir option—e.g.:
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper,workdir=/tmp/work overlay /tmp/union
Q: Is it possible to tweak the automation scripts to mount and use the existing images in a writable state on a 4.x kernel? Can I avoid reformulating them to contain something like root and work directories? In some cases that may break their use elsewhere.
Per the documentation, the workdir has to be an empty directory on the same filesystem as the upperdir to allow for atomic writes. That sounds to me like it is impossible to union-mount root filesystem images as read-write. The workdir would have to exist within the images (separate from their data directory) which isn't possible in a root filesystem image.
I've considered loading up stock Ubuntu 14.04 in a VM for a couple one-offs, but it's not a long term solution.
Best Attempt So Far:
The only solution I've come up with that avoids double-writing the same data to disk is to mount both images as lowerdir values, with upperdir and workdir directories sitting on a tmpfs mount. Then I can use rsync to copy the changes from the tmpfs location to the mounted ext2/3 image after the automated writes are complete and the overlay union has been unmounted—i.e.:
mount -t overlay -o rw,lowerdir=/tmp/upper:/tmp/lower,upperdir=/tmp/tmpfs/root,workdir=/tmp/tmpfs/work overlay /tmp/union
...perform automated reads/writes...
umount /tmp/union
...rsync contents from /tmp/tmpfs/root to /tmp/upper...
It's strictly limited to available RAM, though, and it's an ugly hack to add to all of the automation scripts.
linux root-filesystem overlayfs union-mount
linux root-filesystem overlayfs union-mount
edited Sep 11 '16 at 14:57
codewithmichael
asked Sep 10 '16 at 1:28
codewithmichaelcodewithmichael
1214
1214
bumped to the homepage by Community♦ 53 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 53 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
@Gilles thanks for the retitle to help with exposure, but I do not want to use overlayfs for my root filesystem. I'm trying to union-mount an overlay disk image (that contains root filesystem changes and whiteouts) to theupperdirposition above a read-onlylowerdirroot filesystem image as a temporary mount under/tmp/. Effectively, the old automation scripts are remotely modifying offline user system images that are based on a shared disk image (conceptually similar to how Docker works). The new title may confuse people.
– codewithmichael
Sep 11 '16 at 1:56
add a comment |
1
@Gilles thanks for the retitle to help with exposure, but I do not want to use overlayfs for my root filesystem. I'm trying to union-mount an overlay disk image (that contains root filesystem changes and whiteouts) to theupperdirposition above a read-onlylowerdirroot filesystem image as a temporary mount under/tmp/. Effectively, the old automation scripts are remotely modifying offline user system images that are based on a shared disk image (conceptually similar to how Docker works). The new title may confuse people.
– codewithmichael
Sep 11 '16 at 1:56
1
1
@Gilles thanks for the retitle to help with exposure, but I do not want to use overlayfs for my root filesystem. I'm trying to union-mount an overlay disk image (that contains root filesystem changes and whiteouts) to the
upperdir position above a read-only lowerdir root filesystem image as a temporary mount under /tmp/. Effectively, the old automation scripts are remotely modifying offline user system images that are based on a shared disk image (conceptually similar to how Docker works). The new title may confuse people.– codewithmichael
Sep 11 '16 at 1:56
@Gilles thanks for the retitle to help with exposure, but I do not want to use overlayfs for my root filesystem. I'm trying to union-mount an overlay disk image (that contains root filesystem changes and whiteouts) to the
upperdir position above a read-only lowerdir root filesystem image as a temporary mount under /tmp/. Effectively, the old automation scripts are remotely modifying offline user system images that are based on a shared disk image (conceptually similar to how Docker works). The new title may confuse people.– codewithmichael
Sep 11 '16 at 1:56
add a comment |
1 Answer
1
active
oldest
votes
Create an additional level of nesting in the image file:
mkdir /tmp/upper/upper
mkdir /tmp/upper/work
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper/upper,workdir=/tmp/upper/work overlay /tmp/union
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f308980%2fcan-i-use-a-read-write-root-filesystem-disk-image-as-an-overlayfs-upperdir%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create an additional level of nesting in the image file:
mkdir /tmp/upper/upper
mkdir /tmp/upper/work
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper/upper,workdir=/tmp/upper/work overlay /tmp/union
add a comment |
Create an additional level of nesting in the image file:
mkdir /tmp/upper/upper
mkdir /tmp/upper/work
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper/upper,workdir=/tmp/upper/work overlay /tmp/union
add a comment |
Create an additional level of nesting in the image file:
mkdir /tmp/upper/upper
mkdir /tmp/upper/work
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper/upper,workdir=/tmp/upper/work overlay /tmp/union
Create an additional level of nesting in the image file:
mkdir /tmp/upper/upper
mkdir /tmp/upper/work
mount -t overlay -o rw,lowerdir=/tmp/lower,upperdir=/tmp/upper/upper,workdir=/tmp/upper/work overlay /tmp/union
edited May 3 '18 at 16:10
Jeff Schaller
43.8k1161141
43.8k1161141
answered May 3 '18 at 15:34
AlexanderAlexander
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f308980%2fcan-i-use-a-read-write-root-filesystem-disk-image-as-an-overlayfs-upperdir%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
@Gilles thanks for the retitle to help with exposure, but I do not want to use overlayfs for my root filesystem. I'm trying to union-mount an overlay disk image (that contains root filesystem changes and whiteouts) to the
upperdirposition above a read-onlylowerdirroot filesystem image as a temporary mount under/tmp/. Effectively, the old automation scripts are remotely modifying offline user system images that are based on a shared disk image (conceptually similar to how Docker works). The new title may confuse people.– codewithmichael
Sep 11 '16 at 1:56