Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Apr 2020 15:53:12 -0400
From:      Paul Mather <paul@gromit.dlib.vt.edu>
To:        ian@dijix.com
Cc:        freebsd-stable@freebsd.org
Subject:   Re: Issue with gpart "Device Busy"
Message-ID:  <DA9DEB5E-3EAB-4B8D-9FCB-B05C89E6E85C@gromit.dlib.vt.edu>
In-Reply-To: <3BF9F702-81FD-4156-B6A2-E32C549ACA90@dijix.com>
References:  <3BF9F702-81FD-4156-B6A2-E32C549ACA90@dijix.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Apr 15, 2020, at 2:35 PM, ian@dijix.com wrote:

> I have an issue with gpart, it will not let me delete partition ada0p2  
> responding with “Device Busy”
> The man page gpart(8) says this may be shown if a partition exists but I  
> cannot seem to delete partition 2 in my case via gpart delete or gpart  
> destroy
>
> This is a used disk but new to the machine, I can modify the partition  
> type and create partitions before and after partition 2 but I cannot  
> delete it.
>
> Here’s what I have tried so far:
>
>
> root@beastie:~ # gpart show
> =>        34  1250263661  ada0  GPT  (596G)
>        34      409606        - free -  (200M)
>    409640  1249591904     2  freebsd-ufs  (596G)
> 1250001544      262151        - free -  (128M)
>
> =>       40  976773088  ada1  GPT  (466G)
>       40       1024     1  freebsd-boot  (512K)
>     1064        984        - free -  (492K)
>     2048    4194304     2  freebsd-swap  (2.0G)
>  4196352  972576768     3  freebsd-zfs  (464G)
> 976773120          8        - free -  (4.0K)
>
> root@beastie:~ # gpart delete -i2 ada0
> gpart: Device busy
>
> root@beastie:~ # gpart add -t freebsd-boot ada0
> ada0p1 added
>
> root@beastie:~ # gpart show
> =>        34  1250263661  ada0  GPT  (596G)
>        34      409606     1  freebsd-boot  (200M)
>    409640  1249591904     2  freebsd-ufs  (596G)
> 1250001544      262151        - free -  (128M)
>
> =>       40  976773088  ada1  GPT  (466G)
>       40       1024     1  freebsd-boot  (512K)
>     1064        984        - free -  (492K)
>     2048    4194304     2  freebsd-swap  (2.0G)
>  4196352  972576768     3  freebsd-zfs  (464G)
> 976773120          8        - free -  (4.0K)
>
> root@beastie:~ # gpart delete -i2 ada0
> gpart: Device busy
>
> root@beastie:~ # gpart delete -i1 ada0
> ada0p1 deleted
>
> root@beastie:~ # gpart show
> =>        34  1250263661  ada0  GPT  (596G)
>        34      409606        - free -  (200M)
>    409640  1249591904     2  freebsd-ufs  (596G)
> 1250001544      262151        - free -  (128M)
>
> =>       40  976773088  ada1  GPT  (466G)
>       40       1024     1  freebsd-boot  (512K)
>     1064        984        - free -  (492K)
>     2048    4194304     2  freebsd-swap  (2.0G)
>  4196352  972576768     3  freebsd-zfs  (464G)
> 976773120          8        - free -  (4.0K)
>
> root@beastie:~ # gpart destroy -F ada0
> gpart: Device busy
>
> root@beastie:~ # gpart modify -i2 -t freebsd-boot ada0
> ada0p2 modified
> root@beastie:~ # gpart show
> =>        34  1250263661  ada0  GPT  (596G)
>        34      409606        - free -  (200M)
>    409640  1249591904     2  freebsd-boot  (596G)
> 1250001544      262151        - free -  (128M)
>
> =>       40  976773088  ada1  GPT  (466G)
>       40       1024     1  freebsd-boot  (512K)
>     1064        984        - free -  (492K)
>     2048    4194304     2  freebsd-swap  (2.0G)
>  4196352  972576768     3  freebsd-zfs  (464G)
> 976773120          8        - free -  (4.0K)
>
>
> I’m not sure where to go from here, I’m tempted to pull the drive and  
> reformat elsewhere
>
> I have all tried dd’ing the disk as root but dd /dev/ada0 errors with  
> unauthorised.
>
> Am I missing something obvious?


I don't know whether it can be considered obvious, but, in my experience,  
this sort of inability to delete a partition can happen because another  
GEOM layer has that partition open under some other guise.  Typical  
culprits are the various "label" classes and other GEOM classes that  
"autodetect" things belonging to them.

A case in point that happened to me recently: I was trying to install on  
what I thought were two empty drives.  Unfortunately, when it came to  
actually partitioning ada0 and ada1 it failed.  It turned out that the  
drives were previously used in a "fake RAID" setup and GEOM_RAID was  
detecting an old RAID volume on the drives because the RAID metadata/label  
was being detected.  This meant I couldn't directly access the underlying  
devices, ada0 and ada1.

My solution was to use graid to destroy the errant RAID volume, after which  
I was able to write/partition ada0 and ada1 directly.

Sometimes it is sufficient to disable autodetection of various label  
classes in /boot/loader.conf to be able to access the lower devices.

Cheers,

Paul.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DA9DEB5E-3EAB-4B8D-9FCB-B05C89E6E85C>