#!/bin/bash # Copy NFS-booted Debian to the local drive and setup boot # Install with grub-pc (non-UEFI boot) set -e DEV=$1 if [ ! -b $DEV ]; then echo "USAGE: $0 /dev/sdXXX (sdXXX must be a block device)" exit 1 fi PART=${DEV}1 mkdir -p /root/target # Unmount old chroot-mounts if any for i in boot/efi dev/pts dev proc sys; do if grep -q " /root/target/$i " /proc/mounts; then umount /root/target/$i fi done if grep -q " /root/target " /proc/mounts; then umount /root/target fi # Check if $PART already contains a filesystem if mount $PART /root/target &>/dev/null; then umount /root/target if [ "$WIPE" = "1" ]; then echo "Device $PART already contains a filesystem. WIPE=1 specified. Wiping" wipefs -a $DEV else echo "Device $PART already contains a filesystem. Wipe it first" exit 1 fi fi # Make root partition SIZE=`blockdev --getsz $DEV` ROOT_SIZE=$((SIZE-2048-1048576)) sfdisk $DEV </root/target/etc/initramfs-tools/modules cat >/root/target/etc/initramfs-tools/initramfs.conf < /root/target/etc/rc.local # Set fstab cp /etc/resolv.conf /root/target/etc/resolv.conf cat >/root/target/etc/fstab <