chroot fails with mount point passed to subprocess.Popen?

N

newton10471

Hi,

I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
point passed in as a parameter to the following function:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
print "type of linuxFsRoot is %s" % type(linuxFsRoot)
installedKernelVersionResult =
subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
return installedKernelVersionResult

and it dies with the following:

type of linuxFsRoot is <type 'str'>
chroot: cannot change root directory to /storage/mounts/
mnt_3786314034939740895.mnt/root: No such file or directory

When I explicitly set linuxFsRoot = "/storage/mounts/
mnt_3786314034939740895.mnt/root", it works fine.

I also tried this to concatenate the mountpoint + /root, and it failed
in the same way:

linuxFsRoot = ("%s/root") % mountPoint

Anyone know what might be happening here?

Thanks in advance,

Matt Newton
 
A

Alf P. Steinbach

* newton10471:
Hi,

I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
point passed in as a parameter to the following function:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
print "type of linuxFsRoot is %s" % type(linuxFsRoot)
installedKernelVersionResult =
subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
return installedKernelVersionResult

and it dies with the following:

type of linuxFsRoot is <type 'str'>
chroot: cannot change root directory to /storage/mounts/
mnt_3786314034939740895.mnt/root: No such file or directory

When I explicitly set linuxFsRoot = "/storage/mounts/
mnt_3786314034939740895.mnt/root", it works fine.

I also tried this to concatenate the mountpoint + /root, and it failed
in the same way:

linuxFsRoot = ("%s/root") % mountPoint

Use the os.path functions.

Anyone know what might be happening here?

Since the computed and literal paths /look/ identical and same type, the only
thing I can imagine is that there is some invisible character. Try comparing the
computed and literal path character by character. Print the difference or if
they're identical, that they are.

Possibly you have GIGO problem.


Cheers & hth.,

- Alf
 
N

newton10471

Hi Alf,

After doing some more research, including the character-by-character
comparison you suggested (thank you!), I was able to get things
working the way I wanted using the following:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
installedKernelVersionResult = subprocess.Popen(['/usr/sbin/
chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'],
stdout=subprocess.PIPE).communicate()[0]
return installedKernelVersionResult


Thanks very much for you help,

-Matt


* newton10471:


I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
point passed in as a parameter to the following function:
def getInstalledKernelVersion(mountPoint):
    linuxFsRoot = mountPoint + "/root"
    print "type of linuxFsRoot is %s" % type(linuxFsRoot)
    installedKernelVersionResult =
subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
    return installedKernelVersionResult
and it dies with the following:
type of linuxFsRoot is <type 'str'>
chroot: cannot change root directory to /storage/mounts/
mnt_3786314034939740895.mnt/root: No such file or directory
When I explicitly set linuxFsRoot = "/storage/mounts/
mnt_3786314034939740895.mnt/root", it works fine.
I also tried this to concatenate the mountpoint + /root, and it failed
in the same way:
linuxFsRoot = ("%s/root") % mountPoint

Use the os.path functions.
Anyone know what might be happening here?

Since the computed and literal paths /look/ identical and same type, the only
thing I can imagine is that there is some invisible character. Try comparing the
computed and literal path character by character. Print the difference or if
they're identical, that they are.

Possibly you have GIGO problem.

Cheers & hth.,

- Alf
 
N

newton10471

Hi Alf,

After doing some more research, including the character-by-character
comparison you suggested (thank you!), I was able to get things
working the way I wanted using the following:

def getInstalledKernelVersion(mountPoint):
linuxFsRoot = mountPoint + "/root"
installedKernelVersionResult = subprocess.Popen(['/usr/sbin/
chroot',linuxFsRoot,'/bin/rpm','-q','kernel-xen'],
stdout=subprocess.PIPE).communicate()[0]
return installedKernelVersionResult


Thanks very much for you help,

-Matt


* newton10471:


I'm trying to use subprocess.Popen() to do a Linux chroot to a mount
point passed in as a parameter to the following function:
def getInstalledKernelVersion(mountPoint):
    linuxFsRoot = mountPoint + "/root"
    print "type of linuxFsRoot is %s" % type(linuxFsRoot)
    installedKernelVersionResult =
subprocess.Popen(['chroot',linuxFsRoot,'rpm','-q','kernel-xen'])
    return installedKernelVersionResult
and it dies with the following:
type of linuxFsRoot is <type 'str'>
chroot: cannot change root directory to /storage/mounts/
mnt_3786314034939740895.mnt/root: No such file or directory
When I explicitly set linuxFsRoot = "/storage/mounts/
mnt_3786314034939740895.mnt/root", it works fine.
I also tried this to concatenate the mountpoint + /root, and it failed
in the same way:
linuxFsRoot = ("%s/root") % mountPoint

Use the os.path functions.
Anyone know what might be happening here?

Since the computed and literal paths /look/ identical and same type, the only
thing I can imagine is that there is some invisible character. Try comparing the
computed and literal path character by character. Print the difference or if
they're identical, that they are.

Possibly you have GIGO problem.

Cheers & hth.,

- Alf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top