Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I asked a question here Is it mandatory to have a file system

One of the comments is :

how a system without file system would work on linux as even a printer or ethernet card is considered as a file ? What is your goal here ? ...Kiwy Feb 24 at 14:18

Now here is a log message when booting linux without a file system (which is hanging at the end):

    [Tue Apr 08 20:07:18.298 2014] 
[Tue Apr 08 20:07:18.298 2014] 
[Tue Apr 08 20:07:18.298 2014] U-Boot 2013.07 (Apr 08 2014 - 14:27:03)
[Tue Apr 08 20:07:18.298 2014] 
[Tue Apr 08 20:07:18.298 2014] Memory: ECC disabled
[Tue Apr 08 20:07:18.298 2014] DRAM:  1 GiB
[Tue Apr 08 20:07:18.308 2014] SF: Detected N25Q128A with page size 64 KiB, total 16 MiB
[Tue Apr 08 20:07:18.341 2014] *** Warning - bad CRC, using default environment
[Tue Apr 08 20:07:18.341 2014] 
[Tue Apr 08 20:07:18.341 2014] In:    serial
[Tue Apr 08 20:07:18.341 2014] Out:   serial
[Tue Apr 08 20:07:18.341 2014] Err:   serial
[Tue Apr 08 20:07:18.341 2014] U-BOOT for Xilinx-ZC702-14.7
[Tue Apr 08 20:07:18.341 2014] 
[Tue Apr 08 20:07:18.341 2014] 
[Tue Apr 08 20:07:18.341 2014] SF: Detected N25Q128A with page size 64 KiB, total 16 MiB
[Tue Apr 08 20:07:18.697 2014] Linux
[Tue Apr 08 20:07:18.697 2014]      Load Address: 0x00008000
[Tue Apr 08 20:07:18.697 2014]      Entry Point:  0x00008000
[Tue Apr 08 20:07:18.697 2014]    Verifying Hash Integrity ... OK
[Tue Apr 08 20:07:18.697 2014] ## Loading fdt from FIT Image at 01000000 ...
[Tue Apr 08 20:07:18.697 2014]    Using 'conf@1' configuration
[Tue Apr 08 20:07:18.697 2014]    Trying 'fdt@1' fdt subimage
[Tue Apr 08 20:07:18.697 2014]      Description:  Flattened Device Tree blob
[Tue Apr 08 20:07:18.697 2014]      Type:         Flat Device Tree
[Tue Apr 08 20:07:18.697 2014]      Compression:  uncompressed
[Tue Apr 08 20:07:18.697 2014]      Data Start:   0x0111d344
[Tue Apr 08 20:07:18.697 2014]      Data Size:    11179 Bytes = 10.9 KiB
[Tue Apr 08 20:07:18.697 2014]      Architecture: ARM
[Tue Apr 08 20:07:18.697 2014]      Hash algo:    crc32
[Tue Apr 08 20:07:18.697 2014]      Hash value:   a7a92b47
[Tue Apr 08 20:07:18.697 2014]      Hash algo:    sha1sha1+ OK
[Tue Apr 08 20:07:18.702 2014]    Booting using the fdt blob at 0x111d344
[Tue Apr 08 20:07:18.702 2014]    UncomprOK
[Tue Apr 08 20:07:18.702 2014]    Loading Device Tree to 07ffa000, end 07fffbaa ... OK
[Tue Apr 08 20:07:18.702 2014] 
[Tue Apr 08 20:07:18.702 2014] Starting kernel ...
[Tue Apr 08 20:07:18.702 2014] 
[Tue Apr 08 20:07:19.453 2014] u @c0a7b000 s5568 r8192 d14912 u32768
[Tue Apr 08 20:07:19.453 2014] Built 1 zonelists in Zone order, mobility grouping on.  Total pages: 260096
[Tue Apr 08 20:07:19.453 2014] Kernel command line: root=mtd:jffs2 rw rootfstype=jffs2 console=ttyPS0,115200
[Tue Apr 08 20:07:19.453 2014] PID hash table entries: 4096 (order: 2, 16384 bytes)
[Tue Apr 08 20:07:19.453 2014] Dentry cache hash table entries: 131072 (order: 7, 524288 bytes)
[Tue Apr 08 20:07:19.453 2014] Inode-cache hash table entries: 65536 (order: 6, 262144 bytes)
[Tue Apr 08 20:07:19.453 2014] __ex_table already sorted, skipping sort
[Tue Apr 08 20:07:19.453 2014] Memory: 1024MB = 1024MB total
[Tue Apr 08 20:07:19.453 2014] Memory: 1036960k/1036960k available, 11616k reserved, 270339 16




[Tue Apr 08 20:07:19.625 2014] I reach build/linux/kernel/xlnx-3.8/source/net/socket.c:





[Tue Apr 08 20:07:19.625 2014] DMA: preallocated 256 KiB pool for atomic coherent allocations
[Tue Apr 08 20:07:19.625 2014] xgpiops e000a000.ps7-gpio: gpio at 0xe000a000 mapped to 0xf004e000
[Tue Apr 08 20:07:19.625 2014] GPIO IRQ not connected
[Tue Apr 08 20:07:19.625 2014] XGpio: /amba@0/gpio@41220000: registered, base is 255
[Tue Apr 08 20:07:19.625 2014] GPIO IRQ not connected
[Tue Apr 08 20:07:19.625 2014] XGpio: /amba@0/gpio@41200000: registered, base is 251
[Tue Apr 08 20:07:19.625 2014] usbcore: registered new interface driver usbfs
[Tue Apr 08 20:07:19.625 2014] usbcore: registered new interface driver hub
[Tue Apr 08 20:07:19.625 2014] usbcore: registered new device driver usb
[Tue Apr 08 20:07:19.625 2014] Switching to clocksoutyPS0 at MMIO 0xe0001000 (irq = 82) is a xuartps
[Tue Apr 08 20:07:19.629 2014] console [ttyPSxusbps-ehci xusbps-ehci.0: irq 53, io mem 0x00000000
[Tue Apr 08 20:07:19.670 2014] xusbps-ehci xusbps-ehci.0: USB 2.0 started, EHCI 1.00
[Tue Apr 08 20:07:19.675 2014] hub 1-0:1.0: USB hub found
[Tue Apr 08 20:07:19.675 2014] hub 1-0:1.0: 1 port detected
[Tue Apr 08 20:07:19.681 2014] xi2cps e0004000.ps7-i2c: 400 kHz mmio e0004000 irq 57
[Tue Apr 08 20:07:19.686 2014] xadcps f8007100.ps7-xadc: enabled:   yes reference:  external
[Tue Apr 08 20:07:19.709 2014] xwdtps f8005000.ps7-wdt: Xilinx Watchdog Timer at f00ea000 with timeout 10s
[Tue Apr 08 20:07:19.709 2014] sdhci: Secure Digital Host Controller Interface driver
[Tue Apr 08 20:07:19.709 2014] sdhci: Copyright(c) Pierre Ossman
[Tue Apr 08 20:07:19.709 2014] sdhci-pltfm: SDHCI platform and OF driver helper
[Tue Apr 08 20:07:19.729 2014] usbcore: registered new interface driver usbhid
[Tue Apr 08 20:07:19.729 2014] usbhid: USB HID core driver


[Tue Apr 08 20:07:19.729 2014]  I am at build/linux/kernel/xlnx-3.8/source/drivers/hid/usbhid/hid-core.c



[Tue Apr 08 20:07:19.729 2014] VFP support v0.3: implementor 41 architecture 3 part 30 variant 9 rev 4
[Tue Apr 08 20:07:19.781 2014] MTD: MTD device with name "jffs2" not found.
[Tue Apr 08 20:07:19.781 2014] List of all partitions:
[Tue Apr 08 20:07:19.781 2014] No filesystem could mount root, tried:  jffs2
[Tue Apr 08 20:07:19.781 2014] Kernel panic - not syncing: VFS: Unable to mount root fs on mtd:jffs2
[Tue Apr 08 20:07:19.781 2014] CPU1: stopping
[Tue Apr 08 20:07:19.781 2014] Backtrace: 
[Tue Apr 08 20:07:19.781 2014] Function entered at [<c0011094>] from [<c01c6408>]
[Tue Apr 08 20:07:19.781 2014]  r6:c0246418 r5:00000000 r4:00000001 r3:60000193
[Tue Apr 08 20:07:19.781 2014] Function entered at [<c01c63f0>] from [<c0011fbc>]
[Tue Apr 08 20:07:19.781 2014] Function entered at [<c0011f78>] from [<c0012270>]
[Tue Apr 08 20:07:19.781 2014]  r4:c0247ef4 r3:c0011f78
[Tue Apr 08 20:07:19.781 2014] Function entered at [<c001220c>] from [<c00084e4>]
[Tue Apr 08 20:07:19.781 2014]  r5:ef07bf68 r4:f8f00100
[Tue Apr 08 20:07:19.824 2014] Function entered at [<c0008484>] from [<c000da00>]
[Tue Apr 08 20:07:19.824 2014] Exception stack(0xef07bf68 to 0xef07bfb0)
[Tue Apr 08 20:07:19.824 2014] bf60:                   c0a838d0 00000000 00000003 00000000 ef07a000 c01cd528
[Tue Apr 08 20:07:19.824 2014] bf80: ef07a000 c025c418 0000406a 413fc090 00000000 ef07bfbc ef07bfc0 ef07bfb0
[Tue Apr 08 20:07:19.824 2014] bfa0: c000e94c c000e950 60000113 ffffffff
[Tue Apr 08 20:07:19.824 2014]  r6:ffffffff r5:60000113 r4:c000e950 r3:c000e94c
[Tue Apr 08 20:07:19.824 2014] Function entered at [<c000e924>] from [<c000eacc>]
[Tue Apr 08 20:07:19.824 2014] Function entered at [<c000ea40>] from [<c01c4208>]
[Tue Apr 08 20:07:19.824 2014]  r5:00000001 r4:c024cf68
[Tue Apr 08 20:07:19.824 2014] Function entered at [<c01c4118>] from [<001c37c8>]
[Tue Apr 08 20:07:19.844 2014]  r6:10c03c7d r5:00000015 r4:2f06406a r3:c01c37b0
[Tue Apr 08 20:07:19.844 2014] MTD: MTD device with name "jffs2" not found.
[Tue Apr 08 20:07:19.844 2014] List of all partitions:
[Tue Apr 08 20:07:19.844 2014] No filesystem could mount root, tried:  jffs2
[Tue Apr 08 20:07:19.844 2014] Kernel panic - not syncing: VFS: Unable to mount root fs on mtd:

I am booting from flash.

Now from the log it is very clear that many of the drivers are already loaded even though file system loading is failed (because I intentionally did not put the file system rootfs.jffs2 in flash ).

Now referring to the comment above, if everything is file in linux, how come drivers are successfully loaded? You can see USB,GPIO, SD everything is coming before it asks for file system (and failed).

So is it technically correct to say that

linux MUST have a file system

Some background What I am trying to achieve is to have linux running on a system where a control application will be running. The application just captures some data and send it to some slaves. There is not question of storing data AT ALL. So would like to completely get rid of file system. As per my understanding file system is required for storing data and since I willnot storing any data so why have file system and increase the resource usage ?

Update

Although I have mentioned this in background, but to be specific the sending of the data would take place using USB or Ethernet, so it is natural to have corresponding drivers.

share|improve this question
1  
Nice to be quoted B-) –  Kiwy Apr 10 at 6:05
    
Where would you like to store your control application? –  el.pescado Apr 10 at 12:44
    
@el.pescado at the same place where I will keep OS,basically flash memory. –  user2799508 Apr 10 at 13:12
    
@user2799508 in initrd? –  el.pescado Apr 10 at 13:36
add comment

8 Answers 8

If you need Linux, you need a filesystem.

(I mean Linux the operating system here, rather than Linux the OS kernel. I'll get to that narrower interpretation below.)

Your observation about device drivers loading at boot before the filesystem exists is a red herring. You can load a driver without having a filesystem. What you can't do is fd = open("/dev/foo", O_RDONLY) without a filesystem.

That does not mean you need a persistent rewritable storage medium formatted with a traditional filesystem, as with your JFFS2 example. All you need to support a traditional /dev tree is a data structure that behaves like an on-disk filesystem. Modern Linuxes use udev on an in-memory filesystem to allow access to /dev nodes without needing persistent storage for the /dev nodes, for example.

You also need a filesystem to make use of several other capabilities of Linux-the-OS:

  • Need shared libraries or scripting language modules? You need a filesystem to store /lib/libfoo.*, /usr/lib/perl5/*, /lib/ld.so, /etc/ld.so.cache, etc.

  • Need loadable kernel modules? You need a filesystem for /lib/modules/$(uname -r)/*

  • Need more than one executable, like a shell, or a text editor? They need a filesystem to live in.

  • Need the kernel to enforce access control? Most of that is done via permission bits, ACLs, and SELinux labels on a file or directory somewhere.

I could probably come up with more examples, but that will do.

It is possible to load all the resources your system needs from persistent storage into RAM, so that once booted, the system does not use persistent storage at all. Live Linux distributions do this. It is also common for embedded Linux OSes to build their entire filesystem in RAM as they boot, so that once booted, they no longer continue to reference persistent storage such as a flash storage device.

If you are building a narrowly-scoped single-purpose single-task embedded system, you probably don't need Linux-the-OS. You might only need a smaller, less featureful embedded OS, or you might be able to write straight to the metal.

Some of the other answers here talk about stripping Linux down to the point where all you're left with is Linux-the-kernel, either paired with a single executable — your program, running under the kernel — or running as a monolithic program with your code statically incorporated within it. Either way, you can get completely away from the need for a filesystem, but what you end up with is no longer Linux-the-OS.

share|improve this answer
4  
Need shared libraries? Nah — you can use static binaries. Need loadable modules? Nah — you can compile a monolithic kernel. Need more than one executable? Nah — put everything into init. Oh, but where would init get loaded? Bingo! –  Gilles Apr 9 at 22:46
1  
@Gilles: Go far enough down that road, and you end up with Achmed's answer, and its consequent problem. –  Warren Young Apr 9 at 22:48
1  
No, there's a huge difference between having init and modifying the kernel to do something else than loading init. –  Gilles Apr 9 at 22:52
    
I know. You're describing the last step in the progression towards Achmed's answer. I'm just warning about a potential consequence of taking the idea too far. –  Warren Young Apr 9 at 23:07
    
I disagree with the idea that there can be a too far at all. The entire point of an open-source kernel is that its source is open to change. Tailoring open-sourced software to alternate purposes is the purpose of open-sourced software. If you do a bad job of it or if your purpose is too singular then your alterations die with you, but if your alteration is worthwhile then others will benefit from your efforts and likely you from theirs when they contribute their own. –  mikeserv Apr 10 at 9:19
show 5 more comments

I wrote an answer to to a related question that details how the concept of a file is core to the way Unix works, and since you can't have a file without some kind of filesystem, it means that you definitely need one.

However it is possible to survive without a filesystem that exists on any persistent storage media. Your initramfs image can be compiled into the kernel itself (or otherwise put somewhere where the bootloader can access it). Technically the image that gets written to storage media is an archive and not a filesystem; it only becomes such after it is loaded. If you put all the binary files that you need inside this, there is no need to put them in a filesystem on storage media. This way, you can ensure that all the necessary filesystems that the system needs to run exist purely in memory.

Of course the downsides are that since everything the system needs has to exist in memory, you might find that you just don't have enough for what you want to do. Also you will have a hard time writing any data that you want to persist after a reboot.

share|improve this answer
    
One very salient point about initramfs images is that you are not limited to only 1. Simply cpio another image atop the first and you're good to go. OR compile in the first and add the rest after boot. The possibilities are endless, Also note that because the cpio tools are included in-kernel, it is not inconceivable to save changes this way, though you would be limited to writing the saved cpio image to a raw device if you had no other filesystem. –  mikeserv Apr 10 at 6:56
    
Also, technically the cpio image does not become a filesystem but is unpacked into a filesystem - initramfs or rootfs as you prefer it. –  mikeserv Apr 10 at 9:52
add comment

Actually, technically speaking you don't need a file system. The default behaviour is to have a file system from which to boot. (e.g. /sbin/init is launched from there). However, if you like you can look at what happens in do_basic_setup() in linux-source/init/main.c. By the time that routine gets called, the kernel and CPU0 are ready for real work. You can shred all the work required to boot initramfs — which is a filesystem, too! — and anything afterwards and replace it with your own code to work without the filesystems.

You could then use kernel threads to spawn off whatever processes you want. However, all of this would be super ugly.

share|improve this answer
1  
While this is all true, wouldn't it pretty much require that you GPL your system? You can't use the kernel module licensing hole because no filesystem means no dynamically loadable kernel modules. –  Warren Young Apr 9 at 22:31
    
+1 for being concise, technically correct and the only answer to correctly answer the question so far. Linux is just a code base, you can use it however you wish, including removing the need for many basic components. –  Vality Apr 10 at 0:09
    
@Ahmed Masud Do you mean I still need one file system- initramfs? (I will need ethernet and usb in my application though) –  user2799508 Apr 10 at 3:59
    
@mikeserv, pre 2.6 kernels don't need initramfs - they use initrd. –  Graeme Apr 10 at 9:39
    
@Graeme This also is true, as i'm aware and have even noted myself elsewhere on this site. I tend to think more currently than that, even if doing so is a fallacy. But, in my defense - i am not alone. Even OpenWRT has been using 2.6+ for several years, despite the original Broadcom drivers which originally gave it purpose and a name never seeing an officially 2.6 compatible update. –  mikeserv Apr 10 at 9:43
add comment

A filesystem provides more than just a place to store files. It is where the executables (programs), libraries and configuration files for your system live. At a minimum the linux kernel requires a filesystem to allow it to find/execute the "init" process that is responsible for ensuring that other processes are started as appropriate for your system.

Regarding everything is a file that phrase means that Linux/Unix systems provide access to devices, resources, files via a file abstraction. That means that there is a consistent (open, close, read, write, ...) interface to (almost!) everything.

Your confusion with device drivers comes about because you are confusing the source of the device driver instructions with the actual executable machine instructions that implement the device driver. In the example you provided the device drivers are built directly into the kernel and are able to run once the kernel image has been loaded into memory. If the device drivers are built as modules they are contained in files in the filesystem and the executable machine instructions are loaded from the file into kernel memory where they are executed. Once the device driver is loaded and running it typically makes the devices that it controls available in /dev via the file system.

Once the kernel is running the init process and all of its children need to access the file to interact with other processes, access devices, to request virtual memory, to get sources of random numbers, to send messages to each other. This is for the main part done via filesystem access. Sending/receiving via the network is one exception to requiring filesystem access but you will likely find a need to access a filesystem very quickly anyway.

Really given your use-case you should be looking at using a small configurable distribution such as OpenWrt. With that you can build a system that has a minimal set of software installed and which basically runs from RAM without requiring to write anything to stable storage. Once you have that running you can always strip unneeded components out but don't underestimate the help that having a distribution that has debugging tools and an active userbase brings.

share|improve this answer
add comment

File systems are a means for operating systems to organize persistently stored data. Specifically, they enable the OS to store and retrieve data efficiently. When you say you have booted from a flash drive, that means that this flash drive certainly has a file system. The fact that the kernel has loaded a driver means that it must have had a way to find it somewhere. This "find it somewhere" is achieved by the file system. But even if the kernel is monolithic and has everything compiled in, then at least the boot loader must have had a way to find the kernel.

In theory, you could do that without a sophisticated file system, just put everything at some fixed location and hard code that location, but what purpose would that serve? And we're not talking about your data files like e-mails and everything else, yet. Without a file system, there is no sound way to store (and later find) those. Even if you don't want to store any file, the OS is more than just the kernel, it includes various services and user land programs which are stored in files.

To make a long story short, you must have a file system somewhere, for if the kernel finds none (as in your example) it panics (as your log shows) - which means that it refuses to do anything. But if running a linux installation off a flash drive (with a file system) suits your needs, then you don't need a file system on disk or anywhere else.

share|improve this answer
1  
Unixy OSes use the filesystem for more than just persistent data. There are impersistent trees (devfs, /proc, /sys...), it is the backbone of most access control, etc. –  Warren Young Apr 9 at 22:34
    
/proc and /sys are just helpers, the system could - in principle - work fine without them. /sys is linux-specific, /proc could be replaced by something like sysctl as FreeBSD does. –  countermode Apr 10 at 5:41
add comment

If you want the Linux OS to function then it has to have a file system.

But there is no requirement that the file system be on a hard disk (or SSD etc). In fact there is not even a requirement that Linux be on the device at all.

You can use the BOOTP protocol to load the OS over the network. You do need quite a bit of RAM though for this to be effective. The boot loader is a standard ROM on the network card. Everything else gets transfered via the network and stored in a Virtual File System that is created in RAM.

However for a dedicated device it would be better to install flash memory with the equivalent of a USB Live Boot disk and run your program from there. It sounds like you are already trying to do something like that. When running from a Flash Disk or ROM, a Virtual File System also gets created in RAM, but you need less RAM then if using the BOOTP method.

Unlike Ubuntu, Debian uses a Hybrid Boot image that can be directly copied to a USB flash disk using dd, you may find this easier to work with, especially since Ubuntu requires the use of a special program to create the bootable USB and that program is somewhat buggy.

You can add your own programs to an OS image using various tools to mount the ISO as a read/write file system. You can use rc.local to start the program, but beware that rc.local gets run multiple times during start up. You could also create an /etc/init.d/ script but that is more complicated.

In Summary: Your program does not need a file system, but the OS does, however no actual/physical disk is needed.

share|improve this answer
add comment

Earlier computers (and some modern embedded systems) do not have a filesystem. My Apple ][ (and the school's Commodore PET) had the OS in ROM and was ready to roll about 2 seconds after a cold boot. Want to load software? Either type the source in manually, or type LOAD, press enter, and then PLAY on the tape machine. Then we got a disk drive - and there was much rejoicing.

However, the very core of linux assumes a filesystem is present, and almost everything else builds on that. If you want to implement a true no-file-system OS it's certainly possible, but your hardware and OS will both have to be built around the concept.

Apple's method was to wire the OS in the last 16k of memory, the processor (MC6502) was hardwired to jump to the location permanently stored in the last 2 bytes of memory.

share|improve this answer
add comment

No, linux does not need to have a filesystem in a very strict sense. In your case you have a different issue.

"No filesystem could mount root, tried: jffs2" "MTD: MTD device with name "jffs2" not found."

My guess is some part of the load process either is not finding a/the place to mount or doesn't have the ability to mount that filesystem.

share|improve this answer
2  
Your answer says "you dont need a filesystem but your problem is that you do need a filesystem". It makes no sense and is not internally consistent. –  casey Apr 9 at 18:49
    
I dont understand this... that error is because there is no file system to mount, because he has no file system. The mounter is working fine, he just has no valid fs on his flash disk. –  Vality Apr 10 at 0:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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