tags:OS2020Spring

Compile your kernel!

Ok, let's start!

I put all commands in the zone.

  1. Choose your Linux distro.:

    • Recommand you should split over 40 GB disk space to contain your linux distro.
    • Ubuntu is the easiest! I assume you are using Ubuntu below.
    • Fedora, Gentoo, Arch are also common distro.
      • What is distro.?
        • A Linux distribution (often abbreviated as distro).
    • Ubuntu is a branch of Debian, Fedora is a branch of Red Hat.
  2. Open the Terminal and type:

    • sudo apt update; sudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev liblz4-tool vim libelf-dev -y
    • To install some essential tools
      • If you are using non-debian OS, change the apt to your package manager.
  3. Choose your kernel version:

    • Take the newest for example.
    • Go to kernel.org to download the newest stable version with [tarball]
    • Dowload to ~/Download
      • The '~/' means your home directory (a.k.a. /home/<YOUR NAME>)
  4. Unzip the kernel which you downloaded:

    • tar -xvf ~/Download/linux-*.tar
  5. cd in to the folder you unziped:

    • cd ~/Download/linux-*
  6. Edit the version info:

    • Makefile
      • vim Makefile
      • Find the EXTRAVERSION = and add -<YOUR STUDENT ID>
        • Example: EXTRAVERSION = -B073040047
      • Press the Esc key to command mode, and type :wq to save and quit

    25077667 Murmur: Edit the Makefile is much more easier and needless to search keywords in lots of lists.

    Actually, Linus torvalds also uses 'Makefile' method. 💕 Valentine's Day Edition 💕

  7. Set old default config as .config:

    • make olddefconfig
  8. Make!

    • make -j $(nproc)
      • The $(nproc) command can get the number of CPUs in your computer, that is, compile kernel in full speed!
      • Make until it says:
      ​​​​​​​​Kernel: arch/x86/boot/bzImage is ready  (#3)
      
  9. Make module install

    • sudo make modules_install
  10. Install it to /boot

    • sudo make install
  11. Update Grub2

    • sudo update-initramfs -c -k <THE VERSION YOU COMPILED>
      • Of course, it contains your "stuID" in the end. That you append on.
    • sudo update-grub
  12. Reboot!

    • reboot

Done.


More Tools:

Supply packages

It will help you very much if you read this.
GNU Linux dev

Vim

What is Vim?

Vim Wiki

A picture to realize vim: picture

What is sudo?

A meme:

Imgur
source

wiki

About the /boot partition

  • What is disk partitions?

    • Disks can be parted to many partition, each partitions are independent, for example, you can install different OS in different partition.
    • Partition table type
      There are two different type of partirion table.
      MBR and GPT
      • MBR
        • Master Boot Record , it's an old type method with old bios machine
        • Limit
          • Max size of partition is 2.1TB
          • It can only part 4 Primary Partition, if you need more partition, you have to part 3P1E, which P means Primary Partition and E means Extension Partition, then part many Logic Partition as you want in Extension Partition.
          • Max partition number : 4
            • p.s. : P+E must
              4 and E has to
              1.
      • GPT
        • GUID Partition Table , it's a newer method with in UEFI machine.
        • Limit
          • Max size of partition is 18EB
          • Max partition number : 128
  • What is partitions' format and flag?

    • Partition format is the rule of how files be stored and fetched.
      • NTFS
        • New Technology File System, This is the most used format in Windows NT OS(>= Windows NT 3.1).
        • Page size : 4KB
        • Max file size : 256TB
        • p.s. : If you want to access NTFS in other OS like Linuxs , you have to via ntfs-3g.
      • ext4
        • Fourth extended file system , this is the newest file system in Unix-like system.
        • Page size : 4KB
        • Max file size : 16TB
        • Max partition cabability : 1EB
      • fat32
        • File Allocation Table
        • Max file size : 4GB
        • Max partition cabability : 8TB
        • p.s. : efi partition should be format to fat32
    • Flag
      • In MBR format needs a Boot flag to mention boot loader it is bootable.
  • How to split your partitions by yourself?

    • There are may in linux tools like fdisk, gparted, lsblk, cfdisk, this examples is using fdisk
    • fdisk -l
      • It will print all yout storage devices , sata devices will be list like /dev/sdX , M.2 pcie devices will be list like /dev/nvme.
    • fdisk /dev/sdX
      • select disk sdX which you want to modify.
    • In fdisk press p to list partition
    • In fdisk press o to create new dos partition table(MBR) , press g to create gpt partition(UEFI)

    MBR

    • part at least one partition which mount as /(root)
    • In fdisk press n to create a new partition
    • In fdisk press t to modify partition type(linux file system)

    GPT

    • recommend to part at least two partitions , one that mount as /(root) , the other mount as /boot
    • In fdisk press n to create a new partition
    • In fdisk press t to modify partition type(/ : linux file system , /boot : efi)
    • formatting you partition
      • mkfs.ext4 /dev/sdXY
        • format partition Y on disk X to ext4
      • mkfs.vfat /dev/sdXY
        • format partition Y on disk X to fat32
  • Concluding:

    • You can only split fewer space to finish this homework in older version of linux.

FAQ

  1. What should I do if I have the GTX 10xx GPU?

Please follow these tutorials:

  1. error: /boot/vmlinuz-??? has invalid signature.

There are two methods to solved this:

  • Resign your kernel and install.
  • Disable the secure boot.
  1. How to sign a custom kernel for Secure Boot?
  1. [Kernel panic] not syncing: System is deadlock on memory


That is your memory is not enough to boot.
Please give your machine more memory.

  1. Ping 140.117.11.1 is not working.

Well, you can ping 8.8.8.8 first.
If ping 8.8.8.8 is working, that might be NSYSU's issue.(Please tell teacher)
else please check your network state.

  1. make *** Error

Please check if you were following these steps without any error.
And make sure some dependency packages are installed.
If you have any error here, don't keep going down!!

Eg:

There is an error!! Please check your "debian/canonical-certs.pem" first.
Don't make install
If you don't know what happends. Please Google it first, you can ask me if you can't not find useful answers.

  1. Compile kernel takes many time?

Wait for it.

  1. How to find the WSL's root directory to insert files?

Eg:

There are 2 problems here.

  1. The root directory is '/', which is called "root"(The root of your file system). And your "home" directory is symboled as "~/", the '~' is an alias for '/home/<YOUR_NAME>'.

  2. You shouldn't have any Linux root file system on Windows (excepat some hacking skills). You cannot use the WSL to compelete this part of homework 1.
    Because the WSL's kernel is not a normal Linux kernel, there are many encapsulation of Hyper-V or NT-Core, which simulate the behavior of Linux kernel. Therefore, you cannot recompile it from the "origional" Linux source code.