Other Writing to a raw disk while it is mounted - Is it possible?

Is is possible to write to a raw disk like /dev/da0 or /dev/da0s1 while it is mounted?
I've been trying an asking around IRC but nobody knows how or even if its possible.
This is trivial on a linux system. sorry that i have to bring it up but really...

Things I tried (as root, obviously)
setting
kern.geom.debugflags=16

and remounting and trying again, doesn't work.
Doing the same in single-user mode, doesn't work.

Using gpart to partition the disk, using fdisk-linux to partition the disk, neither helps

Tried finding a 'nowriteprotect' type of flag for mount but couldn't find any.

Looked around for other sysctl parameters to tweak but honestly don't know what else could be changed.

The disk is writable when it is mounted, so its not read-only.
I found the same problem in a mailing list from 2005: https://lists.freebsd.org/pipermail/freebsd-hackers/2005-May/012092.html

It appears that since FreeBSD 5.x this is simply not possible. Root or not, permissions or not, freebsd just refuses to do what i tell it to.
Sorry but I am quite frustrated from this since i've spend over 5 hours on this and the OS just refuses to stop stopping me from doing what i know should be doable.
 
Classic case of XY problem. What are you really trying to accomplish? Why do you want to do this? In general, this is an extremely bad idea, so you must have an extraordinary use case for it.

And to answer your question: read the man page for geom. Understand what rank means, and read the description of debugflag = 0x10.
 
I don't know what you're trying to achieve (as you do want to mount it). But after you set the debug flags to 0x10 (16) you can dd to the raw device, i.e. from start of the disk.
Imagine the situation:
Code:
# gpart show da0
=>       40  146800567  da0  GPT  (70G)
         40        512    1  freebsd-boot  (256K)
        552     532480    2  efi  (260M)
     533032       1496       - free -  (748K)
     534528  146266079    3  freebsd-zfs  (70G)
Code:
# sysctl kern.geom.debugflags=0x10
kern.geom.debugflags: 0 -> 16

Now I'll seek to the start of the partition and kill it:
Code:
# dd if=/dev/zero of=/dev/da0 bs=512 seek=534528 count=1024
1024+0 records in
1024+0 records out
524288 bytes transferred in 0.171573 secs (3055769 bytes/sec)

What ralphbsz is saying above though it is worth checking out geom(4), especially the TERMINOLOGY ANDTOPOLOGY paragraph. There's a reason why this 0x10 flag is called G_F_FOOTSHOOTING.
 
If its a bad idea or not is not really relevant. If you must know, I merely following installation instructions for slax. After unpacking it into my usb, I am instructed to run ./bootinst.sh which calls ./extlinux64 --install /mnt/slax/boot/ from which it identifies the drive and configuration files necessary for a bootloader installation. This happens while the usb drive is mounted, but fails with an error 'could not open device' from extlinux64.
I tried various things to do this. Its really not my idea, the installation process requires it. So its not an XY problem. Its a prerequisite in order to complete the installation.
Thanks for the suggestions, I will read through geom man pages but I've pretty much decided to use a different distro and switch full time. Thanks for the help.
 
To add a bit to ralphbsz and _martin's guidance:

Is is possible to write to a raw disk like /dev/da0 or /dev/da0s1 while it is mounted?

Write, how? dd works, for anything from one byte up, in foot-shooting mode. Actually it's very easy to blow both your legs off!

This is trivial on a linux system.

That's a scary thought.

Things I tried (as root, obviously)
setting
kern.geom.debugflags=16
and remounting and trying again, doesn't work.

Trying what, exactly?

Why, exactly, must the disk be mounted before you write to it (somehow)?

The disk is writable when it is mounted, so its not read-only.
I found the same problem in a mailing list from 2005: https://lists.freebsd.org/pipermail/freebsd-hackers/2005-May/012092.html

That post provided context.

It appears that since FreeBSD 5.x this is simply not possible. Root or not, permissions or not, freebsd just refuses to do what i tell it to.

Do tell us what you're telling it to do, and how?

the OS just refuses to stop stopping me from doing what i know should be doable.

Which OS, precisely?
 
If its a bad idea or not is not really relevant. If you must know, I merely following installation instructions for slax. After unpacking it into my usb, I am instructed to run ./bootinst.sh which calls ./extlinux64 --install /mnt/slax/boot/ from which it identifies the drive and configuration files necessary for a bootloader installation. This happens while the usb drive is mounted, but fails with an error 'could not open device' from extlinux64.
How do you know this linux executable isn't going to find a different disk than the usb drive you're assuming it will? Linux and FreeBSD use different device names. Also it's going to run through the linuxulator, I'm guessing this will complicate things.
What _martin said above is correct, as long as you stay in FreeBSD world. Adding Linux binaries in the mix is going to make things harder. You can always run that extlinux64 binary through truss and see what calls it makes.
Thanks for the suggestions, I will read through geom man pages but I've pretty much decided to use a different distro and switch full time. Thanks for the help.
distro? Someone is going to remark - like we did in silence - a user with 2 posts comes here only to complain that FreeBSD isn't Linux? ...

I would have tested this out of curiosity but apparently I need to provide my e-mail address in order to download that slax thing, so no thanks.
 
Back
Top