看了《奔跑吧 Linux 内核》的书,感觉内存管理这一部分后面的例子不错,
就想手敲一遍体验一下例子(自己对这方面感觉一直云里雾里)
nasri@ubuntu:/usr/local$ apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.13.0 - Linux kernel source for version 3.13.0 with Ubuntu patches
nasri@ubuntu:/usr/local$ apt-get install linux-source-3.13.0
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
nasri@ubuntu:/usr/local$ sudo apt-get install linux-source-3.13.0
[sudo] password for nasri:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
kernel-package libqt3-dev
The following NEW packages will be installed:
linux-source-3.13.0
0 upgraded, 1 newly installed, 0 to remove and 51 not upgraded.
Need to get 97.5 MB of archives.
After this operation, 113 MB of additional disk space will be used.
.....
apt-cache search linux-source//获取当前内核源码版本
sudo apt-get install linux-source-3.13.0//获取内核源码
实际上在/user/src下面就有内核源码
我这里是ubuntu系统
在/user/src下面有2份源码
nasri@ubuntu:/$ ls /usr/src/
linux-headers-4.4.0-142 linux-source-3.13.0
linux-headers-4.4.0-142-generic linux-source-3.13.0.tar.bz2
nasri@ubuntu:/$
linux-headers-4.4.0-142和linux-headers-4.4.0-142-generic
到底目前用的是哪个呢,用uname -a命令可以看下用的是generic的这个
nasri@ubuntu:/usr/src/linux-headers-4.4.0-142$ uname -a
Linux ubuntu 4.4.0-142-generic #168~14.04.1-Ubuntu SMP Sat Jan 19 11:26:28 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
nasri@ubuntu:/usr/src/linux-headers-4.4.0-142$
但是我们发现我们在下载的这个是linux-source-3.13.0,这个和linux-headers这个有什么关系呢?
不知道啊。。。我现在在论坛问问
我把/user/src下的压缩包copy到我本地的work目录下
cp /usr/src/linux-source-3.13.0_nasri/linux-source-3.13.0.tar.bz2 .
解压:
tar -xjvf linux-source-3.13.0.tar.bz2
切换到这个目录下:
nasri@ubuntu:~/Work/linux-source-3.13.0$
等下编译内核,安装必要的软件:
sudo apt-get install libncurses5-dev libssl-dev
sudo apt-get install build-essential openssl
sudo apt-get install zlibc minizip
sudo apt-get install libidn11-dev libidn11
这是我再网上找的编译4.16的内核需要的软件,这里我试了下,找不到minizip,所以暂时不装
等编译的是时候出问题再解决
依次执行以下三条命令:
sudo make mrproper
sudo make clean
sudo make menuconfig
其中mrproper为清除编译过程中产生的所有中间文件,clean为清除上一次产生的编译中间文件,在menuconfig中出现选择的图形化界面后,直接按右方向键选择到exit退出,退出提示中选择保存,实现内核的默认配置。
执行命令:
sudo make –j8
编译内核开始,慢慢等待吧。
sudo make zImage
这个应该没什么用
make modules
make modules_install
make install
还要修改启动的文件
nasri@ubuntu:~$ sudo vim /etc/default/grub
[sudo] password for nasri:
nasri@ubuntu:~$
nasri@ubuntu:~$
nasri@ubuntu:~$ sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.4.0-142-generic
Found initrd image: /boot/initrd.img-4.4.0-142-generic
Found linux image: /boot/vmlinuz-3.13.11-ckt39
Found initrd image: /boot/initrd.img-3.13.11-ckt39
Found linux image: /boot/vmlinuz-3.13.11-ckt39.old
Found initrd image: /boot/initrd.img-3.13.11-ckt39
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin
done
nasri@ubuntu:~$ sudo reboot
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'
GRUB_DEFAULT=1
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="find_preseed=/preseed.cfg auto noprompt priority=critical locale=en_US"
这里把第二行去掉,重启之后就选第二个之后可以选择需要用的内核版本
这里的1 是1级菜单,3是二级菜单,“1(空格) > (空格) 3“
GRUB_DEFAULT="1 > 3"
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="find_preseed=/preseed.cfg auto noprompt priority=critical locale=en_US"
这里有讲解这个 1 > 2二级菜单的介绍 https://www.cnblogs.com/open-skill/p/8295234.html
重启试试看
重启之后成功替换了原有的内核
用unmae -a看内核已经是3.13的内核了
然后再把GRUB_TIMEOUT换为0
或者把GRUB_HIDDEN_TIMEOUT=0注释取消掉
好了,自己编译的内核就把原有的内核替换掉了。