]> gitweb.fluxo.info Git - hydra.git/commitdiff
Using grub-mkrescue to create bootless image
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 15 Feb 2013 18:55:27 +0000 (16:55 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 15 Feb 2013 18:55:27 +0000 (16:55 -0200)
share/hydra/bootless

index 8eb268a9e89ce90dde82881e91dafed6ae14a33a..65ff1e721466884aa1050dd0c7d2c423cc37764e 100755 (executable)
@@ -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}"
 }