linux内核源码树构建

来源:互联网 发布:loadrunner java 编辑:程序博客网 时间:2024/05/17 04:02

目录(?)[+]

获取源码包的方式


为什么要活取源码包?


在笔者到官网下载源码时,源码下面有如下说明:

<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">If you are simply trying <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">to</span> build <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">third</span>-party modules <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> your kernel, you <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">do</span> <span class="hljs-operator" style="box-sizing: border-box;">not</span> want this package. Install <span class="hljs-operator" style="box-sizing: border-box;">the</span> appropriate linux-headers package instead. 意思是,如果你只是想为内核编译第三方的模块,那么,你不需下载此源码包。安装内核头文件包或许会更适合你。</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

如果你的ubuntu是保持更新的(比如您经常执行sudo apt-get update和dist-upgrade), 
那么您的系统是安装有内核头文件包的,不信您到/usr/src目录下查看,是不是有linux-headers-[版本号]-generic的文件夹呢,呵呵。我现在可以说,你可以在此开发你的驱动程序了。

但是为什么我们还要活取源码呢? 
前面已经提到如果你只是想为内核编译第三方的模块,那么,你不需下载此源码包。安装内核头文件包或许会更适合你。 
但是很多时候我们做嵌入式开发或者驱动开发,一个基本的Linux设备驱动开发环境由宿主机目标机组成,宿主机就是用来做驱动开发工作的主机,目标机就是用来运行和测试设备驱动的主机,在宿 主机上需要有开发工具(gcc,gdb,make等)和linux源码(版本要对应目标机上的linux内核),而目标机上只要运行linux即可。由于 步骤有所不同,下面分为普通Linux设备驱动开发嵌入式Linux设备驱动开发两种情况来讲述环境的搭建和驱动程序的编译:

普通Linux设备驱动开发


普通Linux主要是区别于于嵌入式Linux(一般指uClinux),在这种开发中宿主机和目标机可以是一台主机, 
即在本机上开发编译然后在本机 上加载运行(Linux设备驱动也可以直接编译进内核,但为了开发工作方便,一般采用动态加载的方式), 
当然也可以是两台主机, 
如果是两台主机的话,要保证宿主机上的linux源码的版本号与目标机中的linux内核版本一致。 
普通Linux设备驱动开发的步骤如下: 
①在宿主机上安装开发工具和下载linux源码(要求版本号和目标机上的linux内核版本一致)。开发工具主要有gcc、gdb、make等, 
②编写Linux驱动程序 
是需要修改内核源代码的。那么这就需要我们在本地主机上安装一份源码,在编译成库后,在进行驱动开发。 
③编写Makefile文件 
④编译出驱动文件 
加载并测试以及卸载:加载使用insmod或modprobe命令来实现,使用rmmod命令卸载驱动模块

嵌入式Linux设备驱动开发


这种开发中一般目标机为带有嵌入式处理器的开发板,而宿主机为PC,开发环境需要在宿主机上搭建,嵌入式Linux设备驱动开发的步骤如下: 
①在宿主机上下载嵌入式Linux的源码,并安装嵌入式Linux开发工具(针对于不同的嵌入式处理器,工具也有所不同,如对应于Arm的arm-gcc系列,针对nios2处理器的nios2-cc系列) 
②编写Linux设备驱动驱动程序,将该文件复制到(linux 源码目录)/drivers/(目标文件夹)/中 
③配置以及修改内核源码的信息以及makefile文件,在此步配置中可以选择将我们编写的驱动编译进内核还是不选择编译,但是不能选择编译成模块 
④配置并且编译内核 
⑤将内核烧写在开发版上进行测试:将生成的zImage文件下载到开发板,开发板上的嵌入式Linux启动后可以用insmod或modprobe加载驱动模块,测试完毕后可以通过rmmod命令卸载驱动模块

总结


因此在开发驱动的时候如果你只是想为内核编译第三方的模块,那么,你不需下载此源码包。安装内核头文件包或许会更适合我们,但是多数情况下,我们可能时需要修改内核源代码信息的,这就需要我们在宿主机维护一份与目标机上相同的内核信息,否则我们怎么保证我们编写的驱动可以在目标机器上运行呢。。。。

源码包活取的方法


linux源码可以通过以下几种途径获得: 
直接去www.kernel.org下载

通过包管理工具下载源码,在debian和Ubuntu中可以通过下面这个命令下载,apt-get install linux-source-(版本号) ,下载后的文件在/usr/src目录中,解压到该目录即可

获取源码包


注意: 
如果您只是为了简单的学习下驱动的开发,而不期望深层次的探究Linux内核的机制,那么您完全可以跳过此步骤,单使用头文件您是完全可以进行简单的第三方驱动开发的。

直接从内核官网上下载


使用发行版自带的源码包


Ubunto14.04


安装编译内核所需要的软件build-essential、autoconf、automake、cvs、subversion

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> install build<span class="hljs-attribute" style="box-sizing: border-box;">-essential</span> kernel<span class="hljs-attribute" style="box-sizing: border-box;">-package</span> libncurses5<span class="hljs-attribute" style="box-sizing: border-box;">-dev</span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

注意:libncurses5这个软件包在使用menuconfig配置内核的时候会用到。

ls一下/usr/src首先看下我们的系统中有没有源码包,仅仅有内核头文件包 

这里写图片描述

进入/usr/src ,在这里构建源码树,我们用下面指令查看可用的源码包

<code class="language-shell hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-cache</span> search linux<span class="hljs-attribute" style="box-sizing: border-box;">-source</span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这里写图片描述 
可以看到得到如下信息

<code class="hljs r has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">linux-<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">source</span> - Linux kernel <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">source</span> with Ubuntu patches linux-<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">source</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span> - Linux kernel <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">source</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> version <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span> with Ubuntu patches</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

那么就让我们来下载3.13.0版的kernel,通过使用命令下载内核

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> install linux<span class="hljs-attribute" style="box-sizing: border-box;">-source</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

下载完成后,会自动的存放在/usr/src下,

在/usr/src/下ls以下 
这里写图片描述

解压缩源码包

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo tar jxvf  linux-source-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.tar</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.bz</span>2</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这样我们就已经获取到了一份完整的源码包,

CentOS构建源码树


构建的之前,最好先

<code class="hljs sql has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">yum <span class="hljs-operator" style="box-sizing: border-box;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">update</span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

把内核升级到最新版本。至于具体安装哪一份源码树,要看你用的哪一种内核,用uname -a可以看到。

先检查看看有哪些源码包

<code class="hljs php has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">yum <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">list</span> | grep kernel</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

如果用的普通内核,就

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">yum install kernel<span class="hljs-attribute" style="box-sizing: border-box;">-headers</span> kernel<span class="hljs-attribute" style="box-sizing: border-box;">-devel</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

如果用的PAE内核,就

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">yum install kernel<span class="hljs-attribute" style="box-sizing: border-box;">-headers</span> kernel<span class="hljs-attribute" style="box-sizing: border-box;">-PAE</span><span class="hljs-attribute" style="box-sizing: border-box;">-devel</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

如果用的xen内核,就

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">yum install kernel<span class="hljs-attribute" style="box-sizing: border-box;">-headers</span> kernel<span class="hljs-attribute" style="box-sizing: border-box;">-xen</span><span class="hljs-attribute" style="box-sizing: border-box;">-devel</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

编译内核


按原来的kernel配置,配置kernel.

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> make oldconfig</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

make(相当耗时),开始编译内核

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> make</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

编译内核镜像

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> make bzImage</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

安装内核模块

<code class="hljs go has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">make</span> modules_install</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

执行结束之后,会在/lib/modules下生成新的目录/lib/modules/3.13.0-48-generic/, 下面的build文件就是编译模块的要用到的文件。至此内核编译完成。 
这里写图片描述

卸载无用的内核相关文件

我们为不同的目标机配置不同的内核模块,这样一段时间后,我们的系统中会有多份内核信息,再加上我们的系统由于自动升级,系统里也会安装了很多内核。这样始终用不到的旧内核或者无用内核有必要清理一下,以节省启动时间和硬盘空间。

这里写图片描述 
然后通过查看本机上所有内核的列表来决定哪些需要删除掉:

运行命令:

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">dpkg --<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">get</span>-selections|grep linux</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

例如我本机显示为: 
显示所有内核的列表

注意: 
不要删除当前使用的版本.后面的install表示已安装,deinstall表示曾经安装过,现在已被删除(已不占空间). 
首先可查看当前用的内核是哪个,可通过命令:uname -a 来获得信息。

其中带有image的就是内核文件,因此可看出我的机器上共五个内核镜像版本。但是其实只安装了2个镜像,这个卸载的时候我们就会发现,我当前使用的是3.13.0-49,所以决定将其它没用的内核删除。 
删除内核镜像的命令

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">删除的命令为:sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> remove linux<span class="hljs-attribute" style="box-sizing: border-box;">-image</span><span class="hljs-attribute" style="box-sizing: border-box;">-XXXX</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

例如我要卸载3.13.0-48的旧内核镜像,那么运行命令

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> purge linux<span class="hljs-attribute" style="box-sizing: border-box;">-image</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">48</span><span class="hljs-attribute" style="box-sizing: border-box;">-generic</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

或者

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> remove linux<span class="hljs-attribute" style="box-sizing: border-box;">-image</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">48</span><span class="hljs-attribute" style="box-sizing: border-box;">-generic</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

这里写图片描述 
我们会发现linux-image-extra-3.13.0-48-generic也会跟着被卸载, 
这时候我们ls /lib/modules/3.13.0-48-generic/会发现,安装的内核镜像文件已经没有了 
这里写图片描述

卸载内核头文件

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> purge linux<span class="hljs-attribute" style="box-sizing: border-box;">-headers</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">48</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

或者

<code class="hljs lasso has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">sudo apt<span class="hljs-attribute" style="box-sizing: border-box;">-get</span> remove linux<span class="hljs-attribute" style="box-sizing: border-box;">-headers</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.13</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.0</span><span class="hljs-subst" style="color: rgb(0, 0, 0); box-sizing: border-box;">-</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">48</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这里写图片描述 
这条命令会自动把linux-headers-3.13.0-48-generic删除,如果未删除我们同样可以使用命令删除即可。 
最后再次运行命令,查看安装的内核文件,查看是否卸载成功

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">dpkg --<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">get</span>-selections|grep linux</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

这里写图片描述

最后最好刷新一个启动菜单

<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">sudo</span> update-grub</code>

0 0
原创粉丝点击