WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: LiveCD for GRUB installation  (Read 3994 times)

Offline bh3

  • Newbie
  • *
  • Posts: 3
LiveCD for GRUB installation
« on: April 01, 2015, 05:27:35 PM »
I'm really sorry, I'm your typical annoying newbie who's had a brief search but not found what (s)he's looking for. I want to create a LiveCD to install GRUB by running the following commands:

mount /dev/vda2 /mnt
mount --rbind /dev /mnt/dev
mount --rbind /proc /mnt/proc
mount --rbind /sys /mnt/sys
LANG=C chroot /mnt update-grub
LANG=C chroot /mnt grub-install --modules="biosdisk part_msdos" /dev/vda
reboot

That's literally all I want to do - I've already set up the virtual machine using debootstrap on the virtual machine host.

Please could somebody point me in the right direction? Sorry for wasting time!

Offline bh3

  • Newbie
  • *
  • Posts: 3
Re: LiveCD for GRUB installation
« Reply #1 on: April 02, 2015, 10:29:58 PM »
Solved my own problem, yippee!

Bash script included below (for Debian Wheezy). Please read it before running it - I'm not responsible if it sets your server on fire etc. It should probably be commented, but...

Code: [Select]
#! /bin/bash

apt-get install -y advancecomp genisoimage
cd /tmp/tcl
wget http://distro.ibiblio.org/tinycorelinux/6.x/x86_64/release/CorePure64-6.1.iso
mv CorePure64-6.1.iso corepure64-6.1.iso
mount corepure64-6.1.iso /mnt -o loop,ro
cp -a /mnt/boot /tmp/tcl
mv /tmp/tcl/boot/corepure64.gz /tmp/tcl
umount /mnt
mkdir extract
cd extract
zcat ../corepure64.gz | cpio -i -H newc -d
cat >> opt/bootlocal.sh <<CONF
sudo mount /dev/hda2 /mnt
sudo mount --rbind /dev /mnt/dev
sudo mount --rbind /proc /mnt/proc
sudo mount --rbind /sys /mnt/sys
sudo LANG=C chroot /mnt update-grub
sudo LANG=C chroot /mnt grub-install --modules="biosdisk part_msdos" /dev/hda
sudo mount /dev/sda2 /mnt
sudo mount --rbind /dev /mnt/dev
sudo mount --rbind /proc /mnt/proc
sudo mount --rbind /sys /mnt/sys
sudo LANG=C chroot /mnt update-grub
sudo LANG=C chroot /mnt grub-install --modules="biosdisk part_msdos" /dev/sda
sudo mount /dev/vda2 /mnt
sudo mount --rbind /dev /mnt/dev
sudo mount --rbind /proc /mnt/proc
sudo mount --rbind /sys /mnt/sys
sudo LANG=C chroot /mnt update-grub
sudo LANG=C chroot /mnt grub-install --modules="biosdisk part_msdos" /dev/vda
sudo poweroff
CONF
find | cpio -o -H newc | gzip -2 > ../corepure64.gz
cd ..
advdef -z4 corepure64.gz
mkdir newiso
mv corepure64.gz boot
cat > boot/isolinux/isolinux.cfg <<CONF
default corepure64
label corepure64
kernel /boot/vmlinuz64
append initrd=/boot/corepure64.gz loglevel=3
CONF
mv boot newiso
genisoimage -l -J -R -V tc-grub -no-emul-boot -boot-load-size 4 -boot-info-table -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -o install-grub.iso newiso
mv install-grub.iso /isos
cd ~
rm -r /tmp/tcl

EDIT: This uses the CorePure fork as I'm running 64-bit guests.

Offline bh3

  • Newbie
  • *
  • Posts: 3
Re: LiveCD for GRUB installation
« Reply #2 on: April 03, 2015, 04:14:36 PM »
PS: I've just realised it's not entirely clear what I'm doing - explanation below:

I've installed Debian on my VM from the host using debootstrap (https://wiki.debian.org/Debootstrap) - however I cannot install grub from outside the virtual machine. Therefore, I'm using the 64-bit port of Tiny Core to install grub.