Making Smallest Possible Linux Distro (x64)

Поділитися
Вставка
  • Опубліковано 18 січ 2025

КОМЕНТАРІ • 188

  • @nirlichtman
    @nirlichtman  9 годин тому +49

    @__kvik Pointed out that even smaller executable sizes can be achieved by using Zig cc with musl. With what I have tested, sizes with Zig are 7.8K on the only-C version and 6.4K with the C & Asm mixed version. Command to build with Zig: "zig cc -Os -target x86_64-linux-musl -static sys.S shell.c", I'll update this comment if I get the size of the shell any lower (and also welcome to offer suggestions in the comments)

    • @NeonFXFusion
      @NeonFXFusion 9 годин тому +2

      @@nirlichtman how about luajit compiled with musl since it has support for direct bindings to C would seem fitting :D

    • @maowtm
      @maowtm 9 годин тому

      zig might be doing this already but I think link time optimization would probably help reduce size without having to go without libc? Alternatively with the assembly version, I wonder if you can get it to be smaller by using a non standard executable format (like a.out?), but I won't bother to check since setting up the tooling is quite a hassle

    • @terraria9934
      @terraria9934 8 годин тому

      would it be posible to boot directly into lua instead of into the shell?

    • @nono1271
      @nono1271 8 годин тому

      Entirely pointless to use Zig for this. Zig is just using LLVM, which is a drop-in replacement for GCC in most cases, which you already use. You just don't pass the flags necessary to create an even smaller executable. Highly recommend reading Chris Wellons' blog, where he mostly focuses on Windows. The smallest possible Windows executable to print something without an import table and anything fancy beyond ASM entrypoint + normal C code for example is 1KB. You can get similar results on Linux as well.

    • @FreeScience
      @FreeScience 7 годин тому

      @@terraria9934 Yeah, no reason why not. I guess loading a default script would be a bit trickier, but you could write a shell in lua and have it available by running require "shell"

  • @RedSntDK
    @RedSntDK 6 годин тому +27

    "For this we're going to write a little bit of assembly.." this is what taking the red pill must feels like, seeing how deep the rabbit hole goes.

  • @PerfectT4ste
    @PerfectT4ste 10 годин тому +55

    As someone who daily drives Linux From Scratch, I have to say this is one of the clearest and most to-the-point videos I've seen on low-level Linux concepts-beyond interesting.

    • @vaibhavmishra5179
      @vaibhavmishra5179 4 години тому +3

      @@PerfectT4ste 'Daily drives'? 🤯

    • @PhysicsGamer
      @PhysicsGamer 3 години тому

      @@vaibhavmishra5179 LFS is a hugely fun project that takes shockingly little time to complete, considering what you get. I remember the first time I spun up Xorg I had to first reread the docs a few times since I had a hard time believing it was that straightforward. It's amazing how modular Linux is.

    • @craigmjackson
      @craigmjackson 3 години тому

      @@vaibhavmishra5179I believe @PerfectT2ste, I've done daily driving LFS also, many times since about LFS 6. I make myself do it again every few years, then the novelty wears off and I go back to the normal stuff (i3 on arch). I learn an insane amount of new stuff each time, there's no better way to catch up on what's going on in this space. Your reaction is warranted, it's not for the faint of heart. Dependency hell is real. :)

    • @GeminiRay-hs2bh
      @GeminiRay-hs2bh 3 години тому +1

      Bro compiles his OS himself! Take that arch users.

    • @alexander3293
      @alexander3293 45 хвилин тому

      What System do you have? On my system compiling chromium alone takes 9h.

  • @zettabitepragmara4031
    @zettabitepragmara4031 11 годин тому +32

    I love the small little mistake at 20:30
    It's always nice when small errors are kept like that because it shows no one is immune to making mistakes

  • @silvunar
    @silvunar 11 годин тому +24

    This man explained his process better than any other kind of tutorial that I have ever seen, even though this was just created for fun

  • @filip_sedlak
    @filip_sedlak 17 годин тому +153

    This is fascinating. How about a minimum distro that will boot straight into DOOM.

    • @DimDima09
      @DimDima09 17 годин тому +14

      Hm, how about making it as init process? Will it work?

    • @BlueEyedSexyPants
      @BlueEyedSexyPants 15 годин тому

      @@filip_sedlak This not the same thing, but I used to run Doom 3 as my xinit process when I wanted to play because it would significantly improve the framerate over launching from Gnome.

    • @4fortyfour
      @4fortyfour 13 годин тому +20

      UEFI Doom?

    • @309electronics5
      @309electronics5 11 годин тому +7

      @@DimDima09 i made a small iso that boots doom made using busybox and also a version with buildroot. You can patch the init file to run fbdoom but in my Experience i cant run it as the main init process

    • @nick-leffler
      @nick-leffler 10 годин тому

      @@309electronics5 dude we need a GitHub link.

  • @LucasHartmann
    @LucasHartmann 4 години тому +7

    Really cool. You can still remove debug symbols with strip for extra ~0.5kB on shell and ~100kB on lua.

  • @inputoutput1126
    @inputoutput1126 14 годин тому +20

    let's get this man the highest retention so the algorithm pushes him to good places

  • @schweinekillerlp2245
    @schweinekillerlp2245 18 годин тому +32

    Really cool video. Very interesting to see the different steps and it helps you understand how the kernel is built and how the whole system works in general.

  • @eitantal726
    @eitantal726 11 годин тому +12

    Makes me appreciate things like ATARI rom that have basic built-in, with some other OS utilities, in just a handful of KB, not MB

    • @vlc-cosplayer
      @vlc-cosplayer 4 години тому +2

      "in just a handful of KB, not MB" -- it's called BASIC for a reason ;3
      Then again Fabrice Bellard (same madlad who created ffmpeg and JSLinux) also created QuickJS, which supports the ES2023 standard in ~210 KB of code, which is smaller than the Lua interpreter, a notoriously bare-bones language. 👀

  • @morezco
    @morezco 7 годин тому +2

    You have a fantastic style of presentation, always showing the synopsis and allowing time to read before writing more code.

  • @comradepeter87
    @comradepeter87 6 годин тому +3

    Bro no way, just about a week back I was learning how to compile Linux kernel from scratch for RISC-V and now I see this vid. This vid is so nice as a minimal example for playing with a kernel. I learned a lot, thanks!

    • @VoyivodaFTW1
      @VoyivodaFTW1 Годину тому

      Did you get it working? Learning riscv is one of my goals.

  • @theitatit
    @theitatit 13 годин тому +64

    I hope no one gets inspired to release yet another distro that no one needs from this informative and educational video.

    • @toby9999
      @toby9999 12 годин тому

      Yeah, It all seems totally pointless.

    • @ANT-jm4qx
      @ANT-jm4qx 12 годин тому +3

      Mini Linux is coming out soon lol

    • @vilian9185
      @vilian9185 10 годин тому

      jukes on you i'm releasing bussinMiniOS

    • @VioletRM
      @VioletRM 10 годин тому +8

      "wahh too many distros wahhh"

    • @krazymeanie
      @krazymeanie 10 годин тому +7

      Who tf cares if there's a million distro's to choose from? This is the lamest mindset in the Linux community ong.

  • @RGD2k
    @RGD2k 8 хвилин тому

    Mad props for going right down to assembly and detailing really every step, and not glossing over minor mistakes either, but rather showing it as it is.
    I especially enjoyed it being mostly one-terminal with vim and tmux
    A suggestion: Please look into keypressOSD: I would love to see work done like this with a ticker-feed of actual keystrokes.
    No need to go slow if framestepping through the video is enough to figure out what the keyboard was getting, and I think that would add a lot to the pedagogal value of content like this.

  • @aaaidan
    @aaaidan 2 години тому

    Enthralling. I didn’t follow absolutely every step, but I never felt completely lost and learned a lot. Amazing journey, thank you.

  • @SreeTejaSimhaGemaraju
    @SreeTejaSimhaGemaraju 38 хвилин тому

    Holy shit! This is the most effective linux build tutorials I've ever laid my eyes on! I needed this kind of starter tutorial to start playing around instead of elaborate detailing on all the bells and whistles of linux build tooling or some other thing! Thank you OP!

  • @michaelutech4786
    @michaelutech4786 Годину тому

    This is one of the best tutorials I saw in a very long time. Thank you so much. This was really fun to watch!

  • @omerguzel8351
    @omerguzel8351 4 години тому +1

    The quality of your tutorial is insane. The thing is better than this is to show how documentations can be followed when you don't know.

  • @alexengineering3754
    @alexengineering3754 39 хвилин тому

    This Video is great! I have never seen such a simple tutorial on kernal building. No overhead and straight to the point. Keep going!
    Minor note: you could change the flags in make from the command line without changing the Makefile but maybe you are right by not making it more complex.

  • @mouseroot8053
    @mouseroot8053 38 хвилин тому

    We didnt just get a video on tiny linux, we got a video on creating a shell, learning to mitigate the C stdlib AND how to build lua for said distro that you also build to iso....A fucking banger, well done.

  • @JohnMitchellCalif
    @JohnMitchellCalif 15 годин тому +3

    super interesting! I adored Linux from Scratch but couldn't get all the commands to work 100%. This is way simpler

  • @Chris-on5bt
    @Chris-on5bt 12 годин тому +7

    Great content!
    I have deployed some super minimal edge computers in a manufacturing setting to run single programs. (communications back to ERP)
    Don't have screen output, take in character input through a barcode scanner, play sounds for user feedback, and use the gpio pins to have some status lights. Used the lepotato platform, but could easily do it on a raspberry pi or any other SBC provided there is networking support.
    Deployments like this aren't my specialty, so I just used Debian stripped down to the basics and it works great. But now I can see another level deeper would be I could write a custom init process for my application and use a custom kernel. I would have to handle DHCP with init as well, but otherwise would be very direct.
    Application was developed in Rust (yea, I know crucify me), so already statically linked.
    Debian was nice for initial roll out for debugging in the field. I could ssh into the endpoints, read log files, upload code changes, etc. But now that the solution is in a stable state these functions are vestigial.
    Though the setup is a bit more involved, I could see the advantage of this being a resultant simpler execution environment and a stronger default security stance (less running means less attack surface). While my deployment scale doesn't call for this level of effort, none-the-less its a stimulating thought experiment in deployment engineering.
    Thanks for the great video!

    • @mipsters
      @mipsters 2 години тому +1

      Was I under a rock? Why would you be crucified for Rust?
      I thought everybody loved it
      Also, the system you built sounds very cool

    • @Chris-on5bt
      @Chris-on5bt Годину тому

      @@mipsters A bit tongue in cheek, but there has been spicy controversy around Rust especially in the Linux Kernel developer world with attempts to integrate Rust into Kernel development. Mostly Rust gets pitted against C and a lot of the arguments thrown around are charactures or badly informed on both sides. There are some vocal people against Rust. You can lookup some videos from the recent Linux Plumbers conference if you are interested.
      Anywho, thanks for the boost. It was a fun project really helped with executing business operations. I have found Rust pretty great for application development. The compile time guarantees, static typing, concurrency model, and trait system in my experience are top notch.I built a couple hyper stable and fast applications quickly with it.

  • @DV-ml4fm
    @DV-ml4fm 12 годин тому +5

    Wow! This is great to learn. I thought tiny core linux at 10mb was the smallest.

  • @Toasterdemon
    @Toasterdemon 5 годин тому

    This is great. The explanation makes it so much simpler than I thought it would be!
    This video has given me many ideas for potential single purpose images I could run to deploy little containerised apps. Super cool!

  • @zach446
    @zach446 13 годин тому +7

    "stop typing so loud" lol -the lovely people I work with

  • @veorEL
    @veorEL 24 хвилини тому

    Anyone else started their Sunday with coffee and this video ?
    No ? Just me ? You don't know what you're missing. 🎉

  • @anotherglitchinthematrix
    @anotherglitchinthematrix 16 годин тому +1

    I am always fascinated by your content and leaving learning something new, thank you.

  • @fders938
    @fders938 16 годин тому +22

    Interesting video, but i have three things to say.
    1. For your minimal shell, I think it would be better to write the entire thing in assembler. You're already writing assembler to create C bindings for the syscalls. You also get more control over eliminating suboptimal instruction encodings and useless instructions. I reimplemented your shell in assembler and was able to get it down to 760 bytes, versus your 9.1KB.
    2. If you're going to compile libc and link it statically with lua, what was the point of eliminating libc from your shell? You could just link dynamically across both binaries and save space through the shared code. I'd recommend Musl libc for a tiny libc.
    3. If the only program you're able to run from your shell is the lua interpreter, why not just make that your init process? You could eliminate the shell entirely, then static linking of libc would make sense since it's the only program on the initramfs.

    • @maowtm
      @maowtm 9 годин тому

      dynamically linking shared libc probably a good idea although you then need to include ld.so as well, bur I guess it pays off if you need to add more programs

    • @amogusenjoyer
      @amogusenjoyer 7 годин тому +2

      I think it's to show the size of the minimal install without static linking libc, before adding it and Lua.

    • @XenHat
      @XenHat Годину тому

      I agree on most of this.
      This seems like a wasted opportunity to give Musl more exposure. I can't use it because I use many glibc-dependent programs, but in this case, it would be the superior choice.
      On the other hand, the issue with making regular programs the init process is that init needs to have the ability to reap dead processes. If, for some reason, the application-as-init ever ends up spawning subprocesses, I suspect the OS won't have a very long runtime.

  • @athenian2011
    @athenian2011 9 годин тому +1

    You are a genius man. Learning so much from your videos!

  • @gearboxworks
    @gearboxworks 7 годин тому

    The entire time watching this, all I could think was "I am not worthy! 😢"
    Amazing stuff.

  • @yoavgvili
    @yoavgvili 3 години тому

    Excelolent explanation.
    Thank you for this, you made the description very clear,

  • @anonymouscommentator
    @anonymouscommentator 13 годин тому

    woww this is an amazing video. really interesting to see how everything plays into each other!

  • @spfy
    @spfy 10 годин тому

    Awesome video, it's always been hard figuring out how to do some of this stuff, but this explains everything pretty clearly. If you're ever in the mood, I have been struggling to find clear explanation how to boot something "bare-metal," with no kernel. Like using qemu to run a program that writes to the serial address of an esp32 to print something.

  • @johanngambolputty5351
    @johanngambolputty5351 16 годин тому +7

    I love this. Is bash that big? Maybe just use lua with a run/exec command?
    Add a few drivers, some basic service support (a dir of shell scripts that run on startup?), busybox, something like mingetty for a basic login, a basic wayland window manager (to not worry about a separate x server) networkmanager and flatpak and then you should be able to run stuff like firefox and steam. That's like 5 core packages + kernel that you'd recompile when you want a system update, that would surely make for a fairly minimal but also fully featured distro to rival tinycore.

    • @tiffcz3863
      @tiffcz3863 8 годин тому

      Yes Bash is big compared to shells in Busybox. Flatpak is humongous in comparison to downloading shared objects from the right git repo to the right /lib directory, or taking configuration from your server's /etc to your system's /etc. Having a server system to compile the software any way you like is way more efficient, but would take effort.

    • @johanngambolputty5351
      @johanngambolputty5351 49 хвилин тому

      @@tiffcz3863 Yeah, I can see it defeating the point if size on disk was the one goal, but I'm kind of just looking at going from zero to fully featured in a minimum number of moving parts if that makes any sense.

  • @ANT-jm4qx
    @ANT-jm4qx 16 годин тому +3

    Holy shit, I didn't know an ISO could be so small

  • @TuxikCE
    @TuxikCE 17 годин тому +5

    You don't need initramfs support if all your modules are built into the kernel.

    • @nirlichtman
      @nirlichtman  17 годин тому +12

      initramfs support is required since I use it to load up the init cpio which holds the userspace. it is true that initramfs is useful for dynamically loading drivers before the main root fs is loaded from disk, but here I use it for the whole system (and there is no root fs that comes from disk)

  • @EWARS_2
    @EWARS_2 8 годин тому +1

    Best I've seen is ~2kb with GeckOS, although that's more another Unix-like targeting the 6502. IIRC, older Linux versions could handle as low as 4MB of RAM too. Maybe update the title as "Modern Linux" to avoid confusion! :D I kid, of course. Great vid, I'm saving for later.

  • @yesitsmaxwell
    @yesitsmaxwell 2 години тому

    The fact that this could fit on a floppy is amazing

  • @Alex-kj9rc
    @Alex-kj9rc 4 години тому

    Thank you for sharing your genius! Amazing video! Bravo!

  • @cyberbiosecurity
    @cyberbiosecurity 15 годин тому

    Wow, thank you!
    Very interesting and nicely filmed!

  • @pantium98
    @pantium98 14 годин тому

    wow, really impressive stuff. Although most of the stuff on this video won't help me directly, I still learned so many things.

  • @oschonrock
    @oschonrock 11 годин тому

    really nice... I have not done that on linux... done similar stuff on BSD, where it is much more common to compile your own kernel.

  • @jan_harald
    @jan_harald 5 годин тому +1

    1) surprised you didn't start with adding some gcc flags to make it smaller, and jumped straight to assembly, like just add -Oz -ffunction-sections -fdata-sections -Wl,--gc-sections and maybe also -flto and you'll see it can get a LOT smaller
    2) zig is irrelevant here, zig's using LLVM behind the scenes, so it's same as clang basically, all the magic is in using musl, you can use "mussel" project to easily make a gcc toolchain that uses musl (gcc also makes sliiiightly smaller binaries), there's also even smaller libc variants, but with those it gets farther and farther from "just write code" and more into "write code for this specific libc"
    there's a loot of fiddling that can be done for "smallest" stuff, including the fact you can use UPX to "pack" most elf executables smaller, with a tradeoff that you basically end up 2x the size of the binary, in ram (it has to unpack it and execute it, but the physical file is also in ram), which is neglegible in this case

  • @muhammadmahad
    @muhammadmahad 14 годин тому

    One of the best video and explanation related to distro :)

  • @fusca14tube
    @fusca14tube 17 годин тому

    Wow!!! Your videos are the best!!! Awesome!!!! By the way, you could use strip utility to get a smaller lua executable. Thank you and keep making this kind of work!!!!

  • @amorsmor8528
    @amorsmor8528 3 години тому

    Thanks for that amazing video

  • @mohamedbelafdal6362
    @mohamedbelafdal6362 8 годин тому

    I feel like most of the video is about writing a minimalist shell in asm from scratch...
    still entertaining to watch

    • @JamesAwokeKnowing
      @JamesAwokeKnowing 6 годин тому

      because obviously kernel is given so need shell and lang.

  • @countingsheep5483
    @countingsheep5483 8 годин тому +5

    Using windows wsl to write a linux distro in vim is crazy work. My kinda crazy.

  • @atabac
    @atabac 5 годин тому +1

    can you cross compile to arm microcontrollers? or riscv?

  • @velho6298
    @velho6298 10 годин тому +2

    Somehow i wouldn't have expected you running Windows ...

    • @JamesAwokeKnowing
      @JamesAwokeKnowing 6 годин тому

      he's probably trying to make linux apps as .exe by making each it's own WSL distro

  • @TrustJesusToday
    @TrustJesusToday 8 годин тому

    Watching this makes me long for bloated distros. Fun video!

  • @vaclav_mach
    @vaclav_mach 12 годин тому

    That’s great! Especially for embedded HW with limited resources/running a single task. I need to dust off the Milk-V Duo board for this… (not x64, but at least some challenge in figuring out the assembly)

  • @n-uv7vg
    @n-uv7vg 15 годин тому +1

    What a legend he didnt make a linux distro bro this is a whole os that is just based on the linux kernel and its from scratch

  • @dj.yacine
    @dj.yacine 12 годин тому +1

    Always high quality content

  • @maloycastillo3473
    @maloycastillo3473 18 годин тому +1

    Great information, great work!

  • @oolong4700
    @oolong4700 2 години тому

    I learned a lot. Thank you.

  • @ronp6108
    @ronp6108 7 годин тому

    Great info thanks for sharing

  • @youssefsamir9119
    @youssefsamir9119 18 годин тому +5

    I didn’t even watch the video yet, but I’m saying it’s one of the best ever made!

  • @DimDima09
    @DimDima09 18 годин тому +1

    Damn looks cool. Thank you!

  • @JPs-q1o
    @JPs-q1o 5 годин тому

    It's too bad gcc doesn't have a "-minimal" flag or similar to complement the -static flag which would build using only using the necessary functions and symbols as opposed to embedding the included libraries whole.

  • @ABCABC-sw8mh
    @ABCABC-sw8mh 31 секунда тому +1

    Finally new vid 🎉🎉🎉

  • @robbieconnor9992
    @robbieconnor9992 Годину тому

    This was a great watch!!

  • @l4ppland
    @l4ppland 55 хвилин тому

    Thanks a lot, nice video

  • @amogusenjoyer
    @amogusenjoyer 8 годин тому +1

    Okay, ignorant question here but: doesnt the kernel have a minimal libc nowadays? Could you link against that, or is it just not usable for something like this?

  • @m4rt_
    @m4rt_ 8 годин тому

    You can do this:
    gcc -o shell shell.c sys.S --entry main -z noexecstack -static
    (gcc can compile C, and GNU Assembly, and then link it together.)
    you can also use -Os to optimize for size.
    Also, to remove all libc, you can use the -nostdlib argument
    You can also remove unnecessary information using the strip command.
    Also, here is an implementation of your basic shell in only 435 bytes (I wrote it in fasm as I am more familiar with that one.)
    format ELF64 executable
    ; I/O
    STDOUT = 1
    STDIN = 0
    ; Wait
    P_ALL = 0
    WEXITED = 4
    ; Syscalls
    SYS_read = 0
    SYS_write = 1
    SYS_fork = 57
    SYS_execve = 59
    SYS_exit = 60
    SYS_waitid = 247
    ; Syscall helpers
    macro syscall0 number {
    mov rax, number
    syscall
    }
    macro syscall1 number, arg1 {
    mov rax, number
    mov rdi, arg1
    syscall
    }
    macro syscall3 number, arg1, arg2, arg3 {
    mov rax, number
    mov rdi, arg1
    mov rsi, arg2
    mov rdx, arg3
    syscall
    }
    macro syscall5 number, arg1, arg2, arg3, arg4, arg5 {
    mov rax, number
    mov rdi, arg1
    mov rsi, arg2
    mov rdx, arg3
    mov r10, arg4
    mov r8, arg5
    syscall
    }
    segment readable executable
    entry main
    main:
    ; Write the "# " thing
    syscall3 SYS_write, STDOUT, write_text, 2
    cmp rax, 0
    jl .write_error
    ; Get the command
    syscall3 SYS_read, STDIN, command, 255
    cmp rax, 0
    je .read_error
    ; Replace the newline
    add rax, command
    sub rax, 1
    mov byte [rax], 0
    ; Fork it
    syscall0 SYS_fork
    cmp rax, 0
    je .execute
    ; Wait for it to finish
    syscall5 SYS_waitid, P_ALL, 0, siginfo, WEXITED, 0
    jmp main
    .execute:
    ; Run the command
    syscall3 SYS_execve, command, 0, 0
    cmp rax, 0
    jl .execve_error
    syscall1 SYS_exit, 0
    .write_error:
    syscall1 SYS_exit, 1
    .read_error:
    syscall1 SYS_exit, 2
    .execve_error:
    syscall1 SYS_exit, 3
    segment readable writable
    write_text: db "# "
    ; don't care about the content, but it's 128 bytes
    siginfo: rb 128
    command: rb 255

    • @mossaiby
      @mossaiby 6 годин тому

      I did this; guess the final size with -Os! 767KB!

  • @JoeBurnett
    @JoeBurnett 11 годин тому

    This was SO good!

  • @rickyoswald
    @rickyoswald 8 годин тому

    Very interesting video, but there seems to be an error. I've tried on Debian and Arch and both segfault at main() in the 2nd shell created around 20:30. I've downloaded the code directly from your git repo. Turning on -Wall there is a warning that argument 2 of execve should not be null, as specified in unistd.h. Tested with GCC 14.2.1 on Arch, 13.3.0 on Debian. I'm not sure if this is the source of the error.

    • @rickyoswald
      @rickyoswald 8 годин тому

      It works perfectly with the zig command in the pinned comment.

  • @JohnneyleeRollins
    @JohnneyleeRollins 11 годин тому

    you did your kernel compiling inside wsl thats pretty cool, was it ws1 or ws2?

  • @stevefan8283
    @stevefan8283 45 хвилин тому

    11:37 or just use musl and call it a day?

  • @terraria9934
    @terraria9934 8 годин тому

    i was expecting a busybox based thing not an entirely custom shell

    • @mossaiby
      @mossaiby 6 годин тому

      He already has such a video: ua-cam.com/video/QlzoegSuIzg/v-deo.html

  • @eitantal726
    @eitantal726 11 годин тому

    Makes me appreciate how small is a dos boot disk. 90KB or so, if I remember correctly

  • @bap9394
    @bap9394 5 годин тому

    You could have used inline asm with gcc btw

  • @Muttisuri
    @Muttisuri 11 годин тому

    Question wouldn't using compiler options like -Os on both the kernel and shell/init files result in smaller binary files?

  • @ChandrashekarCN
    @ChandrashekarCN 4 години тому

    💖💖💖💖

  • @davidDN2318
    @davidDN2318 10 годин тому

    Next create minimal text file creator and include luac to be able to improve the distro from the distro itself

  • @JoeBurnett
    @JoeBurnett 11 годин тому

    Do you have any interest in doing things like this for ARM64, especially some of the corresponding projects listed in your GitHub hello page?

  • @VSteam81
    @VSteam81 7 годин тому

    this almost makes me want to try and learn C

  • @rz2374
    @rz2374 10 годин тому

    Why do you need an initramfs/initrd? Wouldn't it be simpler and smaller to put init and lua directly on the ISO?

  • @ElbahethAmrSrour
    @ElbahethAmrSrour 16 годин тому

    when i try to install any linux distro it give me Kernal Panic similer to the error that you got in this Video
    can you Helo me With This

  • @3dfactor
    @3dfactor 12 годин тому

    What's the boot time after minification?

  • @mrpix3011
    @mrpix3011 11 годин тому

    wow nice. So what about a 32b version?

  • @alejandroalzatesanchez
    @alejandroalzatesanchez 11 годин тому

    why do you use wsl?

  • @matan-h
    @matan-h Годину тому

    thats very very cool

  • @Elia90570
    @Elia90570 18 годин тому

    lets gooo, also lua from scratch btw

  • @mossaiby
    @mossaiby 14 годин тому

    I love your contents! BTW, you could pass -Os or -O3 to gcc to save some space; also why not `strip' the executable? Also, it would be much more interesting if your userland could create new executable files (which Lua cannot). Thank you!

    • @__kvik
      @__kvik 11 годин тому +1

      Yep. I built the C version of his shell with musl libc and -Os and it turned out to 4.7k, so beating his ASM version by not even trying. Also built Lua with the same config and it's 905K or 311K stripped.

    • @mossaiby
      @mossaiby 11 годин тому

      @@__kvik Thanks for confirmation!

    • @nirlichtman
      @nirlichtman  11 годин тому

      @__kvik Interesting, I'll try that out with musl and verify this, if so I will add a pinned comment with this information, thanks for bringing it up

    • @nirlichtman
      @nirlichtman  11 годин тому +1

      @__kvik I am getting 26K with musl libc, so still more than twice as big compared to my ASM version with GCC. I ran "musl-gcc -static -Os shell.c", what command have you used to build?

    • @mossaiby
      @mossaiby 10 годин тому

      @nirlichtman Is the code available somewhere, so I can try it as well? Thanks!

  • @tenox7
    @tenox7 26 хвилин тому

    why do you need initrd? just boot from uefi

  • @mattsadventureswithart5764
    @mattsadventureswithart5764 11 годин тому

    How small this is.
    Reminiscing to the Amiga with a whole OS including a GUI allowing games/etc to run in under half a MB.

  • @JPs-q1o
    @JPs-q1o 5 годин тому +1

    It's called Linux From Scratch™
    by Gerard Beekmans.
    You're welcome.

  • @0xO2
    @0xO2 Годину тому

    "64-bits Intel" is Itanium, not really supported already. X86-64 or AMD64 :-)

  • @guilherme5094
    @guilherme5094 16 годин тому

    👍Yes!

  • @widescreen8964
    @widescreen8964 Годину тому

    Shame it won't fit on a floppy

  • @GiacomoPerin
    @GiacomoPerin 17 годин тому +1

    it can stay on 1 floppy disk, rename it 1 floppy disk linux!

  • @TheElias258
    @TheElias258 16 годин тому +2

    WOW!!!

  • @wahidislamlinad
    @wahidislamlinad 12 годин тому

    i was waiting for thiss

  • @railwaysmodelselectronics7636
    @railwaysmodelselectronics7636 10 годин тому

    Fascinating. I understood almost nothing.

  • @eitantal726
    @eitantal726 9 годин тому

    Tiniest Linux possible, yet orders of magnitude larger executable than MSDOS, while appearing to have even less functionality. How come?

    • @RGD2k
      @RGD2k 14 хвилин тому

      Probably something to do with it being all done by hand showing (or mentioning) every keystroke.
      And to do with linux being quite a large monolithic kernel, quite famously, by design. (So, actually about the worst choice if you're aiming for 'smallest possible', at least so far as kernels go).
      Actually there are ways to make a system become a node of a supercomputer with not a lot more than this: mostly just building in support for a network card, and providing some way to spin-off tasks to it.
      IIRC There used to be a way to do this such that you could open a specific port and bake-in an IP address, then the kernel would run essentially as a co-processor for another network-connected machine, despite being paniced at not being able to run INIT. This was an early workaround for crosscompiling stupid C++ dependencies early on with arm on linux, because C++ libraries like gtkmm incorrectly assumed that the configure script would of course always be able to build and run local executables to automatically determine what were essentially makefile settings, at configure time. Unix-style cross compilation is quite interesting, and this 'trick' could be used so that the crosscompiling system could have a way to 'farm out' executables matching the target architecture to actual hardware. Ie, with the very minimal kernel crashed on it without INIT, but with the patch needed for it to be usable this way, and with the dev system's root fs nfs mounted via kernel option setting. It would of course crash because it would find the host's x86 INIT executable, and not an ARM one. But fortunately it would indeed find and execute any little 'test' executable the overly smartelec configure script would run, and even write the output where expected as well. The library would thus end up crosscompiling successfully anyway, not having any idea it was doing so.
      In actual fact, having a complete system such as LUA running like this is probably much more useful than MSDOS, considering that it supports current hardware in 64bit mode, and can immediately be used as a 'LUA computation node' as part of a larger system, potentially dealing with quite large datasets.
      And he didn't really scratch the surface of what Linux can do if you build in additional options, just really focused quite nicely on the absolute minimum in what I thought was quite a well thought out demonstration / tutorial guide of basic bare-metal Linux setup.
      If you really want extreme small, then you'd probably not choose linux: Yet running 'bare metal' Linux like this is a very valid choice: particularly where it already has kernel support for the hardware you are targetting. Saves you from 'reinventing the wheel' in implementing drivers and many other OS level services, whilst still giving you the freedom to just include *really* only what you want. A few MB is more than small enough, given how big EEPROM chips are nowadays.
      He does mention that he could have got it smaller, obviously by performing much the same minimal assembly to remove the C library depedancy as he already demonstrated. (or by using a substitute C libary specifically aimed at such, which he does mention is a good option).
      This approach demonstrated could be applied to any self-contained system, eg, SQLite would work really well, and potentially be very useful here. You would run this as one node of a cluster system, using something like a FreeBSD cluster elsewhere running a big ZFS array for the NAS.
      So, actually useful as compared to MSDOS.

  • @ottergauze
    @ottergauze 13 годин тому

    I don't know why *anyone* would use the AT&T syntax. It has no reason to exist and it's a pain.

    • @toby9999
      @toby9999 12 годин тому

      What's wrong with it?

    • @ottergauze
      @ottergauze 10 годин тому

      @ It introduces pointless idiosyncrasies that make code hard to read, pointlessly muddying things in ways that can easily be mistaken, such as swapping from operation destination source to operation source destination. It introduces extra confusing syntax for little to no benefit over its Intel counterpart

  • @DarkKnight32768
    @DarkKnight32768 11 годин тому

    Nice bait for newcomers, even if it doesn't explain much, it shows that the basic system is quite simple.
    Of course, step 0 would be stating that there is no abstract smallest distribution, the limit only makes sense if you have a defined set of tasks to perform. If you have no requirements, distribution of zero size suits you.
    If your task is to run an up-to-date web browser (which is almost an operating system in side your operating system today), you need quite a lot of stuff. That's the place for TinyCore and other “construction kit” distributions. You can choose smaller size and software fallback for everything (including graphical server), or bigger package with extra dependencies for intended use of modern hardware. Given that you may need a gigabyte of memory just to open a random web page in a browser (not to mention UA-cam), the former option makes little sense. The difference simply doesn't matter for most use cases. Even if you want to make a horrible extra cheap mobile device, you can stuff it with enough flash memory for a full-featured system.
    Also, you displayed system call numbers for 32-bit x86 kernel. For simplicity, legacy set matches in 64-bit systems.

    • @nirlichtman
      @nirlichtman  11 годин тому

      nope, those are x86 64-bit syscall numbers, notice the file is syscalls_64.h

    • @DarkKnight32768
      @DarkKnight32768 11 годин тому

      @@nirlichtman My bad, brain fogged.

  • @VarasinaFarmadaniTugas
    @VarasinaFarmadaniTugas 16 годин тому

    Cool

  • @GokEnsar
    @GokEnsar 17 годин тому

    liked before watching