Skip to content

Commit

Permalink
Tested on fresh machine. The only thing that doesn't work out-of-the-box
Browse files Browse the repository at this point in the history
is spike due to issue firesim#211.
  • Loading branch information
Nathan Pemberton committed Jan 25, 2019
1 parent c379f20 commit a2d1c40
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
3 changes: 2 additions & 1 deletion centos-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
python34
python34-devel

python34-pip
rsync
2 changes: 1 addition & 1 deletion python-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
psutil

doit
3 changes: 1 addition & 2 deletions wlutil/fedora/overlay/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# This file is autogenerated by the scripts
firesim.sh
etc/systemd/system/firesim.service
2 changes: 2 additions & 0 deletions wlutil/fedora/overlay/etc/firesim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is auto-generated by the build system
firesim.sh
9 changes: 0 additions & 9 deletions wlutil/fedora/overlay/etc/systemd/system/firesim.service

This file was deleted.

66 changes: 50 additions & 16 deletions wlutil/wlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import collections
import shutil
from contextlib import contextmanager

wlutil_dir = os.path.normpath(os.path.dirname(__file__))
root_dir = os.getcwd()
Expand Down Expand Up @@ -106,15 +107,59 @@ def genRunScript(command):

return commandScript

# XXX This isn't working with the initramfs option. Go back to requiring sudo
# for now, I'll revisit later.

# Frustratingly, the same commands don't work/exist on various platforms so we
# need to figure out what mounting options are available to us:
# if shutil.which('guestmount') is not None:
# # This is the preferred method because it doesn't require sudo
# @contextmanager
# def mountImg(imgPath, mntPath):
# run(['guestmount', '-a', imgPath, '-m', '/dev/sda', mntPath])
# try:
# yield mntPath
# finally:
# run(['guestunmount', mntPath])
#
# elif shutil.whcih('fuse-ext2') is not None:
# # Roughly the same as guestmount
# @contextmanager
# def mountImg(imgPath, mntPath):
# run(['fuse-ext2', '-o', 'rw+', imgPath, mntPath])
# try:
# yield mntPath
# finally:
# run(['fusermount', '-u', mntPath])
#
# elif shutil.which('mount') is not None:
# # if True:
# # Should be available everywhere, requires sudo
# @contextmanager
# def mountImg(imgPath, mntPath):
# run(['sudo', 'mount', '-o', 'loop', imgPath, mntPath])
# try:
# yield mntPath
# finally:
# run(['sudo', 'umount', mntPath])
#
# else:
# raise ImportError("No compatible 'mount' command found")

@contextmanager
def mountImg(imgPath, mntPath):
run(['sudo', 'mount', '-o', 'loop', imgPath, mntPath])
try:
yield mntPath
finally:
run(['sudo', 'umount', mntPath])

def toCpio(config, src, dst):
log = logging.getLogger()

run(['sudo', 'mount', '-o', 'loop', src, mnt])
try:
with mountImg(src, mnt):
# Fedora needs a special init in order to boot from initramfs
run("sudo find -print0 | sudo cpio --owner root:root --null -ov --format=newc > " + dst, shell=True, cwd=mnt)
finally:
run(['sudo', 'umount', mnt])

# fedora needs a special init to work
if config['distro'] == 'fedora':
Expand All @@ -136,27 +181,16 @@ def copyImgFiles(img, files, direction):
if not os.path.exists(mnt):
run(['mkdir', mnt])

# The guestmount options (and rsync without chown) are to avoid dependence
# on sudo, but they require libguestfs-tools to be installed. There are
# other sudo dependencies in fedora.py though.
# run(['guestmount', '-a', img, '-m', '/dev/sda', mnt])
# run(['fuse-ext2', '-o', 'rw+', img, mnt])
run(['sudo', 'mount', '-o', 'loop', img, mnt])
try:
with mountImg(img, mnt):
for f in files:
# Overlays may not be owned by root, but the filesystem must be.
# Rsync lets us chown while copying.
# Note: shell=True because f.src is allowed to contain globs
# Note: os.path.join can't handle overlay-style concats (e.g. join('foo/bar', '/baz') == '/baz')
# run('cp -a ' + f.src + " " + os.path.normpath(mnt + f.dst), shell=True)
if direction == 'in':
run('sudo rsync -a --chown=root:root ' + f.src + " " + os.path.normpath(mnt + f.dst), shell=True)
elif direction == 'out':
uid = os.getuid()
run('sudo rsync -a --chown=' + str(uid) + ':' + str(uid) + ' ' + os.path.normpath(mnt + f.src) + " " + f.dst, shell=True)
else:
raise ValueError("direction option must be either 'in' or 'out'")
finally:
# run(['guestunmount', mnt])
# run(['fusermount', '-u', mnt])
run(['sudo', 'umount', mnt])

0 comments on commit a2d1c40

Please sign in to comment.