93 lines
2.1 KiB
Bash
93 lines
2.1 KiB
Bash
|
#!/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 <<EOF
|
||
|
label: dos
|
||
|
|
||
|
${DEV}1 : start=2048, type=83
|
||
|
EOF
|
||
|
|
||
|
mkfs.ext4 -F $PART
|
||
|
|
||
|
UUID=`blkid -o value -s UUID $PART`
|
||
|
|
||
|
# Mount new filesystems
|
||
|
mount $PART /root/target
|
||
|
|
||
|
# Copy Debian to the new partition
|
||
|
cp -av /overlay/lower/* /root/target
|
||
|
|
||
|
# Remove overlayroot from initramfs settings
|
||
|
rm /root/target/etc/initramfs-tools/hooks/hooks-overlay
|
||
|
rm /root/target/etc/initramfs-tools/scripts/init-bottom/init-bottom-overlay
|
||
|
>/root/target/etc/initramfs-tools/modules
|
||
|
cat >/root/target/etc/initramfs-tools/initramfs.conf <<EOF
|
||
|
MODULES=most
|
||
|
BUSYBOX=auto
|
||
|
KEYMAP=n
|
||
|
COMPRESS=gzip
|
||
|
DEVICE=
|
||
|
EOF
|
||
|
|
||
|
# Remove ssh-keygen -A
|
||
|
(echo '#!/bin/bash'; echo 'exit 0') > /root/target/etc/rc.local
|
||
|
|
||
|
# Set fstab
|
||
|
cp /etc/resolv.conf /root/target/etc/resolv.conf
|
||
|
cat >/root/target/etc/fstab <<EOF
|
||
|
UUID=$UUID / ext4 rw,relatime 0 0
|
||
|
EOF
|
||
|
|
||
|
# Install GRUB
|
||
|
for i in dev dev/pts proc sys; do mount --bind /$i /root/target/$i; done
|
||
|
chroot /root/target <<EOF
|
||
|
ssh-keygen -A
|
||
|
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install grub-pc
|
||
|
update-initramfs -u -k all
|
||
|
update-grub
|
||
|
grub-install $DEV
|
||
|
EOF
|
||
|
for i in dev/pts dev proc sys; do umount /root/target/$i; done
|
||
|
|
||
|
# Unmount filesystems
|
||
|
umount /root/target
|