fdisk question

Does anyone know if there is a way to clear all partitions on a disk
without every having to enter interactive mode. I am trying to create an
autoinstall process that could be done by anyone, (including someone who
know’s nothing of computers). Everything is fine except when the
harddrive, or CompactFlash disk, or DOC, or whatever already has a
partition on it taking up some or all the space. Right now I can’t clear
the harddrive without having the screen pop up and the user having to
press S. Is there any way around this?
Why is it so easy to create partitions but not to delete them?


Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.

Previously, Chris Nasr wrote in qdn.public.qnx4:

Does anyone know if there is a way to clear all partitions on a disk
without every having to enter interactive mode. I am trying to create an
autoinstall process that could be done by anyone, (including someone who
know’s nothing of computers). Everything is fine except when the
harddrive, or CompactFlash disk, or DOC, or whatever already has a
partition on it taking up some or all the space. Right now I can’t clear
the harddrive without having the screen pop up and the user having to
press S. Is there any way around this?
Why is it so easy to create partitions but not to delete them?

You could write a short program that would open /dev/hd0, read the
first sector, zero out the partition table, and write it back.
Once you do that, you might be inclined to do more.

Mitchell Schoenbrun --------- maschoen@pobox.com

Thanks, but…
Do you maybe have an example of how to do this? I’ve never done such a thing
and wouldn’t even know where to begin. (I do know how to program in C++, just
never done anything working with hardware.)

Mitchell Schoenbrun wrote:

Previously, Chris Nasr wrote in qdn.public.qnx4:
Does anyone know if there is a way to clear all partitions on a disk
without every having to enter interactive mode. I am trying to create an
autoinstall process that could be done by anyone, (including someone who
know’s nothing of computers). Everything is fine except when the
harddrive, or CompactFlash disk, or DOC, or whatever already has a
partition on it taking up some or all the space. Right now I can’t clear
the harddrive without having the screen pop up and the user having to
press S. Is there any way around this?
Why is it so easy to create partitions but not to delete them?

You could write a short program that would open /dev/hd0, read the
first sector, zero out the partition table, and write it back.
Once you do that, you might be inclined to do more.

Mitchell Schoenbrun --------- > maschoen@pobox.com


Chris Nasr
cnasr[at]mechtronix[dot]ca
Mechtronix Systems Inc.

Chris Nasr <cnasr@mechtronix.ca> wrote:
:> > Does anyone know if there is a way to clear all partitions on a disk
:> > without every having to enter interactive mode. I am trying to create an
:> > autoinstall process that could be done by anyone, (including someone who
: Do you maybe have an example of how to do this? I’ve never done such a thing
: and wouldn’t even know where to begin. (I do know how to program in C++,
: just never done anything working with hardware.)

No hardware knowledge required. Something like …

char ptable[512];
int fd;
fd = open("/dev/hd0", O_RDWR);
block_read(fd, 1L, 1, ptable);
memset(&ptable[446], 0, 64);
block_write(fd, 1L, 1, ptable);
close(fd);

Or avoid QNXisms by replacing the block_*() routines with read/lseek/write.

Alternatively, if you have a source of 0s (like /dev/zero) then you
can use “dd” to zero out the 64-bytes that comprise the partition table
(“dd if=/dev/zero of=/dev/hd0 bs=1 seek=446 count=64”).

If you also want to replace the boot loader as well to just erasing the
partition table entries (the full action taken by “fdisk -z”) then use
either of the above methods to kill the 55AA signature at bytes 510-511
in the first disk block and then invoke “fdisk” to re-initialise it.