Yes. And no. Maybe.
Not everything is a file; obviously a hard drive can't contain a partition that then contains a filesystem, that then contains the hard drive itself. It's just that a number of things are accessible through names visible through the filesystem tree.
As far as the filesystem is concerned (the logical filesystem, or a concrete one in the data structure sense, like ext4), it's just that some files are marked as "device nodes" for some particular numbered device. But their functionality is implemented by separate drivers. When a process access them, the OS just diverts the access to the appropriate driver, not to the filesystem. Think of them as references, or pointers, or such.
With that in mind, it's easy to understand that e.g. /proc
is in no way mandatory. The system can function and it can run processes even without it. You just won't have that method of viewing those processes. But stuff like fork()
, kill()
and wait*()
will still work, since they refer to processes by PID, not by some filesystem name. Network sockets also don't appear as named files, in general. Unix domain sockets can do that, but IIRC they don't have to. And TCP or UDP sockets etc. just don't. But network sockets do appear as file descriptors to processes, and the read()
and write()
system calls work with them the same as with pipes or "real" files. So in some sense, network sockets also walk, talk and quack like files, even though the network protocols have not much to do with storing bits on a disk.
But, as far as I can think of, you don't really have a way to refer to an arbitrary hard drive without those named device nodes. Your hardware still exists, the system still has the necessary SATA/USB/whatever drivers required to work with them, but you have no way of telling it to do so. Though you could mount a filesystem, and then remove the device node pointing to the device the filesystem was on. There's no problem here, since the device node is just a way for userspace to access the device.
You asked, "Can unix/linux function without filesystems?". Linux doesn't run without a file system, for one, because it starts userspace by looking for an executable file to run (eventually running what stays around as init
). That filesystem doesn't need to be one on a regular disk drive, though, it can be the special rootfs filesystem the kernel sets up from data included with the kernel image. (Incidentally, you can't get rid of rootfs. It's always there, even if empty, so that the kernel doesn't need to deal with the idea of not having any mounted filesystems.) See ramfs-rootfs-initramfs.txt in the kernel documentation for the details on rootfs.
I suppose we could assume some hypothetical OS that could function without the filesystem, but e.g. the execve()
system call takes a file name, so whatever was running couldn't launch other programs (the one running would need to become loaded some other way), and without the named device nodes, accessing storage would also be hard. It wouldn't look a lot like other Unixen anyway.
On Linux, it might be possible to engineer an oddball single-purpose system that would launch a single userspace program from rootfs at bootup, then clear up rootfs and never mount any other filesystems. That would get as close to having no filesystem as possible, and the program could still run and e.g. access the network. I doubt it would have any practical use, though, and as usual, any open files would still exist until closed, so removing their names might not be very useful.
See also Does the Linux kernel need a file system to run?, parts of the answers to which I echoed above. For a longer discussion on that "everything is a file" mantra, see this answer on A layman's explanation for "Everything is a file" — what differs from Windows?.