--- title: Homework 1 Part1 author: B073040047 date: 7/14/2020 --- ###### tags:OS2020Spring This homework in [Hackmd Link](https://hackmd.io/@25077667/os-hw1) --- ## Compile your kernel! Ok, let's start! :::info 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](http://www.ubuntu-tw.org/modules/tinyd0/) 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. * You can get more info. from [Wikipedia](https://en.wikipedia.org/wiki/Linux_distribution). 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](https://www.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` * [How to use vim?](https://hackmd.io/@93i7xo2/HJFCxkVdV) * 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 > [name=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 💕](https://github.com/torvalds/linux/commit/f40ddce88593482919761f74910f42f4b84c004b) 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](https://hackmd.io/@sysprog/gnu-linux-dev/) ### Vim What is Vim? > [Vim Wiki](https://zh.wikipedia.org/zh-tw/Vim) A picture to realize vim: [picture](http://blog.vgod.tw/wp-content/uploads/2009/12/vgod-vim-cheat-sheet-full.pdf) ### What is sudo? A meme: :::spoiler ![Imgur](https://imgur.com/RLHGMWJ.png) [source](https://www.facebook.com/307979116481335/photos/a.316111539001426/572406666705244/?type=3&theater) ::: [wiki](https://zh.wikipedia.org/zh-tw/Sudo) ## 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 $\le$ 4 and **E** has to $\le$ 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 **Linux**s , 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: > * https://itsfoss.com/fix-ubuntu-freezing/ > * https://medium.com/caesars-study-review-on-web-development/acpi-osi-linux-nomodeset%E6%98%AF%E4%BB%80%E9%BA%BC%E6%84%8F%E6%80%9D-%E5%8A%9F%E8%83%BD-42d8e2c444c3 > * https://www.twblogs.net/a/5cc24c53bd9eee3aed78a7ef 2. error: /boot/vmlinuz-??? has invalid signature. > There are two methods to solved this: > * Resign your kernel and install. > * Disable the secure boot. 3. How to sign a custom kernel for Secure Boot? > * https://github.com/jakeday/linux-surface/blob/master/SIGNING.md 4. \[Kernel panic\] not syncing: System is deadlock on memory > ![](https://i.imgur.com/6ssfrsE.jpg) > That is your memory is not enough to boot. > Please give your machine more memory. 5. 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. 6. make *** Error > Please check if you were **following these steps without any error.** > And make sure some dependency packages are installed. > <font color=red>If you have any error here, don't keep going down!!</font> Eg: ![](https://i.imgur.com/gMRV1ED.png) > 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. 7. Compile kernel takes many time? > Wait for it. 8. How to find the WSL's root directory to insert files? Eg: ![](https://i.imgur.com/YO3W1Lv.png) > 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. >