Quantcast
Channel: Active questions tagged partition - Server Fault
Viewing all articles
Browse latest Browse all 65

How to reset a Harddisk (delete Mbr & delete Partitions) from the Command Line with a script without rebooting?

$
0
0

To start from a clean state I need to reset the hard disk to an empty state from command line.

It is not about running a wipe utility, the data don't have to be overwritten.

This question is quite similar to Deleting All Partitions From the Command Line

The solution there works quite well,

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

but if I want to work with such an overwritten disk, I get the error that the device is still in use.

root@grml ~ # blockdev --rereadpt /dev/sdaBLKRRPART: Device or resource busy

or

root@grml ~ # partprobeError: Partition(s) 2, 3 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.Error: Partition(s) 2, 3 on /dev/sdb have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.

So I have to manually disable everything which "sits" on the device

umount /mnt/debootstrapumount /mnt/debootstrap/tmpumount /mnt/debootstrap/var/logumount /mnt/debootstrap/varumount /mnt/debootstrap/homeservice mdadm stopservice lvm2 stopvgremove vg_mainpvremove /dev/md1mdadm --stop /dev/md0mdadm --stop /dev/md1mdadm --remove /dev/md0mdadm --remove /dev/md1

after that the partprobe command works.

is there some command which works simpler? like

harddiskreset /dev/sda

so it can easily be used on systems with different partition/lvm/md layout?


Viewing all articles
Browse latest Browse all 65

Trending Articles