I'm trying to make a subtle modification to the partition table of a disk on the Mac; in particular, I need to change the type of a partition. diskutil
doesn't support this, so I can't use it. It works fine (e.g. via a modified gpt
command-line utility) if the disk isn't in use. If it is, it fails when opening the device file:
int fd = open("/dev/disk1", O_RDWR);
fd
is -1 and errno
indicates the error "resource busy".
I realise I can reboot the machine from a different drive, modify the original disk from there, then boot back. This is, however, not exactly easy to automate/reliable from inside my application. Besides, diskutil
has no problem editing the partition table of the live device, and neither has the bootcamp installer.
Is there a known way to do this? Worst case, I can try to do it in the kernel, but kexts aren't really designed for doing one-off things, and what I need to do is really quite conceptually simple in userspace but quite hard in the kernel.
Any ideas?
Note: I'm running everything with sudo
, so it should not be a permissions problem.