问题原文
原帖链接 · c33s · CC BY-SA 3.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/sda
BLKRRPART: Device or resource busy
or
root@grml ~ # partprobe
Error: 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/debootstrap
umount /mnt/debootstrap/tmp
umount /mnt/debootstrap/var/log
umount /mnt/debootstrap/var
umount /mnt/debootstrap/home
service mdadm stop
service lvm2 stop
vgremove vg_main
pvremove /dev/md1
mdadm --stop /dev/md0
mdadm --stop /dev/md1
mdadm --remove /dev/md0
mdadm --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?
社区高分解答
原帖链接 · user144437 · CC BY-SA 4.0
The wipefs (Debian/Ubuntu package: util-linux) program lets you easily delete the partition-table signature:
wipefs -a /dev/sda
You still have to stop any process using the device though, such as LVM.
From man wipefs
wipefs can erase filesystem, raid or partition-table signatures (magic strings) from the specified device to make the signatures invisible for libblkid.
wipefs does not erase the filesystem itself nor any other data from the device. When used without any options, wipefs lists all visible filesystems and the offsets of their basic signatures.
wipefs calls the BLKRRPART ioctl when it has erased a partition-table signature to inform the kernel about the change.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
