How to use/test pivot_root?

211

Solution 1

Are you really sure that arch-root is on a separate filesystem that can be mounted and umounted?

pivot_root, as well as the more current switch_root, works by juggling information about mounted filesystems in the kernel.

The new root file system must be "the root" of a file system, you cannot pass "." as the new root unless "." is the root directory of a mounted filesystem.

I believe the easiest way if you want to try pivot_root from your current setup (assuming arch-root is a subdirectory and not a root directory) is to create a tmpfs filesystem to switch to, and copy the required stuff there.

Something along these lines might get you started: (adjust 500M to fit du -sh arch-root)

mkdir /ramroot
mount -n -t tmpfs -o size=500M none /ramroot
cd arch-root # (containing the root filesystem contents)
find . -depth -xdev -print | cpio -pd --quiet /ramroot
cd /ramroot
mkdir oldroot
pivot_root . oldroot
exec chroot . bin/sh

Solution 2

From the man page, I believe this is your issue:

The following restrictions apply to new_root and put_old:

- They must be directories.

- new_root and put_old must not be on the same file system as the current
root.

- put_old must be underneath new_root, that is, adding a nonzero number of
/.. to the string pointed to by put_old must yield the same directory as
new_root.

- No other file system may be mounted on put_old.

According to the above neither put_old or new_root filesystems should reside on the same filesystem as current_root.

References

Share:
211

Related videos on Youtube

Nixiean
Author by

Nixiean

Updated on September 18, 2022

Comments

  • Nixiean
    Nixiean over 1 year

    I have a variable in which I populate the image location dynamically.

    I need to change the background image with that variable. I am not able to find a way to do that.

    var myImg = '/images/example1.jpg';
    
    document.body.style.background = "url(myImg) no-repeat"; 
    

    This doesn't seem to work.

    Is there a syntax issue or should this be done in a different way?

  • Nixiean
    Nixiean about 11 years
    Thanks a lot for the answer. I am just learning. Really appreciate the quick help..
  • vvilp
    vvilp over 9 years
    Thank you for your reply. I update the question. I also try to test in Docker. But Operation not permitted
  • vvilp
    vvilp over 9 years
    Thank you very much, For now I am testing it in a docker container. it works. I will try your method later
  • koalo
    koalo almost 6 years
    You might need to do an unshare -m before the pivot_root. bugzilla.redhat.com/show_bug.cgi?id=1361043
  • iBug
    iBug about 4 years
    Your summary is wrong. new_root and put_old can be on the same FS, it's just that neither should reside on the same FS as the current root.
  • slm
    slm about 4 years
    @iBug - ty fixed.