diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2013-02-15 16:55:27 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2013-02-15 16:55:27 -0200 |
commit | 3da2c597b446de65cbbb67b27decb8378a9fdcc2 (patch) | |
tree | f90307c7b5232ccac68977caea5cc6a496082545 | |
parent | 75e0c79ab60ad93192a1e992ac8a87237039f42f (diff) | |
download | hydra-3da2c597b446de65cbbb67b27decb8378a9fdcc2.tar.gz hydra-3da2c597b446de65cbbb67b27decb8378a9fdcc2.tar.bz2 |
Using grub-mkrescue to create bootless image
-rwxr-xr-x | share/hydra/bootless | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/share/hydra/bootless b/share/hydra/bootless index 8eb268a..65ff1e7 100755 --- a/share/hydra/bootless +++ b/share/hydra/bootless @@ -310,72 +310,23 @@ function hydra_bootless_device { # Generate a bootless disk image function hydra_bootless_image { local output="$1" - local size="$2" if [ -z "$output" ]; then output="bootless.img" fi - if [ -z "$size" ]; then - # TODO: calculate minimum size. Hint: - # du --exclude='.git' -hs ${BOOTLESS_DIR} - size="200" - fi - # Set folder hydra_bootless_folder - # Set sudo config - local sudo - if [ "`whoami`" != 'root' ]; then - sudo="sudo" - fi - - echo "Creating an empty image..." - dd if=/dev/zero of=$output bs=1M count=$size - - echo "Partitioning image..." - parted -s -- ${output} mklabel msdos - parted -s -- ${output} mkpart primary ext2 2 -1 - parted -s -- ${output} set 1 boot on - - echo "Creating device mappings..." - tmpdir=`mktemp -d` - mapping="`$sudo kpartx -av ${output}`" - if [ "$?" != "0" ]; then - echo "Error: failed to create device mapping for \"${output}\" (errno: $?)." - exit 1 - fi - - # Set devices - device="`echo $mapping | head | awk '{ print $8 }'`" - subdevice="/dev/mapper/`echo $mapping | head | awk '{ print $3 }'`" - - # Create filesystem - $sudo mke2fs ${subdevice} - - # Mount - $sudo mount ${subdevice} ${tmpdir} - if [ $? != 0 ]; then - echo "Error: failed to mount \"${subdevice}\" filesystem in \"${tmpdir}\" (errno: $?)." - exit 1 - fi - # Copy data + tmpdir=`mktemp -d` $sudo rsync -Cav ${BOOTLESS_DIR}/ ${tmpdir}/boot/ - # Install grub - #$sudo grub-install --root-directory=${tmpdir} ${device} --force - $sudo grub-install --boot-directory=${tmpdir} ${device} --force - if [ $? != 0 ]; then - echo "Error: grub-install failed (errno: $?)." - exit 1 - fi + # Make rescue disk + grub-mkrescue -o ${output} ${tmpdir} - # Finalize - $sudo umount ${tmpdir} - $sudo kpartx -dv ${output} - $sudo rm -rf ${tmpdir} + # Cleanup + rm -rf ${tmpdir} echo "Image saved at ${output}" } |