3 # livecd-mount: Mount a live CD at the specified point, and log
6 # Copyright 2010, Red Hat Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; version 2 of the License.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 print "Usage: %s ISO.iso MOUNTPOINT [COMMAND] [ARGS]"
33 opts
,args
= getopt
.getopt(sys
.argv
[1:], 'h', ['help', 'chroot', 'mount-hacks'])
34 except getopt
.GetoptError
, e
:
41 if o
in ('-h', '--help'):
43 elif o
in ('--chroot', ):
45 elif o
in ('--mount-hacks', ):
57 isomnt
= tempfile
.mkdtemp(prefix
='livemnt-iso')
58 squashmnt
= tempfile
.mkdtemp(prefix
='livemnt-squash')
60 mountflags
= ['loop', 'ro']
61 mountflags_str
= ','.join(mountflags
)
64 subprocess
.check_call(['mount', '-o', mountflags_str
, isopath
, isomnt
], stderr
=sys
.stderr
)
65 squash_img_path
= os
.path
.join(isomnt
, 'LiveOS', 'squashfs.img')
66 subprocess
.check_call(['mount', '-o', mountflags_str
, squash_img_path
, squashmnt
], stderr
=sys
.stderr
)
67 ext3_img_path
= os
.path
.join(squashmnt
, 'LiveOS', 'ext3fs.img')
68 subprocess
.check_call(['mount', '-o', mountflags_str
, ext3_img_path
, destmnt
], stderr
=sys
.stderr
)
71 subprocess
.check_call(['mount', '-t', 'proc', 'proc', os
.path
.join(destmnt
, 'proc')], stderr
=sys
.stderr
)
72 subprocess
.check_call(['mount', '-t', 'tmpfs', 'tmpfs', os
.path
.join(destmnt
, 'var', 'run')], stderr
=sys
.stderr
)
75 args
= ['chroot', destmnt
]
77 ecode
= subprocess
.call(args
, stdin
=sys
.stdin
, stdout
=sys
.stdout
, stderr
=sys
.stderr
)
79 print "Starting subshell in chroot, press Ctrl-D to exit..."
80 ecode
= subprocess
.call(['chroot', destmnt
], stdin
=sys
.stdin
, stdout
=sys
.stdout
, stderr
=sys
.stderr
)
82 print "Starting subshell, press Ctrl-D to exit..."
83 ecode
= subprocess
.call([os
.environ
['SHELL']], cwd
=destmnt
, stdin
=sys
.stdin
, stdout
=sys
.stdout
, stderr
=sys
.stderr
)
86 print "Cleaning up..."
88 subprocess
.call(['umount', os
.path
.join(destmnt
, 'var', 'run')])
89 subprocess
.call(['umount', os
.path
.join(destmnt
, 'proc')])
90 subprocess
.call(['umount', destmnt
])
91 subprocess
.call(['umount', squashmnt
])
93 subprocess
.call(['umount', isomnt
])
96 print "Cleanup complete"
100 if __name__
== '__main__':