Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6620653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:07:46+00:00 2026-05-25T21:07:46+00:00

While writing a perl script intended to fully automate the setup of virtual machines

  • 0

While writing a perl script intended to fully automate the setup of virtual machines (Xen pv) I hit a small maybe very simple problem.

Using perl’s chroot function I do my things on the guest file system and then I need to get back to my initial real root. How the hell I do that?

Script example:

`mount $disk_image $mount_point`;

chdir($mount_point);
chroot($mount_point);

#[Do my things...]

#<Exit chroot wanted here>

`umount $mount_point`;

#[Post install things...]

I’ve tried exit; but obviously that exit the whole script.

Searching for a way to exit the chroot I’ve found a number of scripts who aim to exit an already setup chroot (privilege escalation). Since I do the chroot here theses methods do not aplies.

Tried some crazy things like:

opendir REAL_ROOT, "/";
chdir($mount_point);
chroot($mount_point);
chdir(*REAL_ROOT);

But no go.

UPDATE
Some points to consider:

  • I can’t split the script in multiple files. (Silly reasons, but really, I can’t)
  • The chrooted part involve using a lot of data gathered earlier by the script (before the chroot), enforcing the need of not lunching another script inside the chroot.
  • Using open, system or backticks is not good, I need to run commands and based on the output (not the exit code, the actual output) do other things.
  • Steps after the chroot depends on what was done inside the chroot, hence I need to have all the variables I defined or changed while inside, outside.
  • Fork is possible, but I don’t know a good way to handle correctly the passing of informations from and to the child.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:07:47+00:00Added an answer on May 25, 2026 at 9:07 pm

    The chrooted process() cannot “unchroot” itself by exiting (which would just exit).

    You have to spawn a children process, which will chroot.

    Something along the lines of the following should do the trick:

    if (fork())
    {
       # parent
       wait;
    }
    else
    {
       # children
       chroot("/path/to/somewhere/");
       # do some Perl stuff inside the chroot...
       exit;  
    }
    
    # The parent can continue it's stuff after his chrooted children did some others stuff...
    

    It stills lacks of some error checking thought.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This popped-up while writing a script for vim. Using the well-documented ':normal' command: :normal
While writing JavaScript code, I Separate each code block with <script> tags <script type=text/javascript>
I am writing a Perl script which needs to perform some validations. I have
I'm writing a perl script where a should process the text and then provide
I'm writing a Perl script and I've come to a point where I need
I'm writing a Bash script in which I am running a perl script which
I am writing a Perl script to change all URLs within several files in
I am writing a Perl Script to find out the frequency of occurrence of
I have the following code in in a Perl script I'm writing: #!/usr/bin/perl use
I'm writing a Perl script in which I need to loop over each character

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.