2

How would you remotely wipe a linux system so that on the next boot it will not attempt to boot from the hard drive, instead it will prefer booting from the network?

Reasoning

I am setting up an environment where servers will pxe boot. I have one working example, however it installs the OS to the drive. When I want to run another test, I need to walk over to the machine, restart it, and boot off of a live disk and format the drive. On the next boot it will attempt to network boot again.

What I've tried

I am able to ssh to the machine, and have tried the following:

  • fdisk
  • rm -rf / --no-preserve-root

Both fail because the device is in use. I've tried to unmount the device with no luck.

  • umount /dev/sda

Is there a way to remotely make a machine unbootable so I can more quickly test pxe configs?

spuder
  • 1,725
  • 3
  • 26
  • 42
  • Change the boot order from the BIOS ? – yagmoth555 Jun 18 '20 at 04:22
  • I could, but that would _also_ require walking over to the machine. – spuder Jun 18 '20 at 04:23
  • 4
    Not with a DRAC/iLO. You should just make all server network boot at first, and integrate a check inside your service that would make it answer a pxe boot request from a server you currently target (mac targetting) – yagmoth555 Jun 18 '20 at 04:28
  • legacy pcbios, replace first 512 bytes on disk with bootcode that returns to bios, if EFI remove all partitions, or at least the FAT32 ones that has boot code. Note tho that this is no guarantee that PXE boot will run instead, all of course depends on configuration. – NiKiZe Jul 13 '21 at 18:06

1 Answers1

1

Have your computer's boot sequence configured as hard disk first, network second. In this case, if you erase the boot sector of your hard disk, making it unbootable, the computer will resort to PXE boot, because no valid boot devices are present.

Simply zero the beginning of the hard disk:

dd if=/dev/zero of=/dev/sda bs=512 count=1

Although, as @yagmoth555 suggested, having a DRAC or something equivalent is probably the better idea.

Lacek
  • 7,233
  • 24
  • 28
  • will zero always do that, since it is executed it will run a bunch of ADD instructions and then depend on what is beyond it, it might need to have some minimal boot code inserted to actually return to bios. (this assumes pcbios) – NiKiZe Jul 13 '21 at 18:05