1

I am doing wipefs -af /dev/sda1 and then creating pv but its throwing error

I am creating with command

pvcreate -qq --metadatasize=128M --dataalignment=256K '/dev/sda1'

and following is error

  [root@xxx]# pvcreate -qq --metadatasize=128M --dataalignment=256K '/dev/sda1'
  Can't open /dev/sda1 exclusively.  Mounted filesystem?
  Can't open /dev/sda1 exclusively.  Mounted filesystem?

After google i tried following options but still no success

[root@xxx]# pvremove /dev/sda1
  No PV found on device /dev/sda1.

I am running this on centos7.6

Update1: After getting updates i tried following

[root@xxx]# umount /dev/sda1
umount: /dev/sda1: not mounted

To check which processes are accessing the device

fuser -m -v /dev/sda1
  • Im not quite sure why this is happening but i think you have to unmount /dev/sda1 first – Qasim May 10 at 10:23
  • 1
    It sounds like you 1) confirmed /dev/sda1 is not mounted, 2) used fuser to check that no user process is accessing the device. You could also check lsblk and see if you have any existing lvm/device-mapper/mdraid device as a subsidiary of sda1. If you do, it will be indented and linked to sda1, in the same way that sda1 is indented and linked as a subsidiary of sda. (Or use ls -l /sys/class/block/sda1/holders ) – sourcejedi May 10 at 15:01
2

There seems to be a misunderstanding of some sort.

pvcreate is telling you that the device /dev/sda1 is still in use (this can be anything, for example it could still be mounted, or part of a RAID array, or device-mapped, or looped, or any running process like if you're in the middle of dd copying the device...).

wipefs would be telling you the same thing, if you didn't use -f

   -f, --force
          Force  erasure,  even if the filesystem is mounted.

If the device is still in use, that's a serious issue as whatever is using the device might modify data on the device. So you really should umount the device first (or otherwise make sure it's not in use anymore) before doing anything with wipefs, pvcreate, mkfs and the like.

wipefs at best only erases some magic bytes on the device, it does not solve any other problem for you, if it's still mounted you have to umount it yourself (or reboot and hope it won't be able to mount then), if it's still in use you'll have to find out what is still using it and why and then decide how to stop that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.