VMware中Ubuntu编译和升级内核

来源:互联网 发布:唐山餐饮软件代理 编辑:程序博客网 时间:2024/06/15 14:25
1、VMware中创建一个Ubuntu的虚拟内存机,注意在设置内存和硬盘时要设置大一些(内存2G,硬盘180G)。
最初配置的时候内存是1G,硬盘是20G,在编译的时候提示空间不够,用命令 df -h 查看,发现根目录文件系统/dev/sda1 的使用率为100%。
因此重新创建了一个虚拟机,分配内存为1G,硬盘为80G,可以正常编译,reboot之后启动新版本kernel的时候显示
"end Kernel panic - not syncing: Out of memory and no killable processes..."
重新配置虚拟机的内存和硬盘,把内存增加到2G,硬盘增加到180G,此时重新启动虚拟机,可以用新版本的kernel正常启动。

为了后续配置的方便,我们进入到root用户进行操作
2、配置网络
虚拟机安装好之后,NAT方式配置好网络。
用浏览器Firefox可以正常上网,但是在更新的时候总是会失败(sudo apt-get update ),也没法安装软件。
把source.list更换成如下源,同时对系统网络和软件更新进行设置。再次测试,可以更新和安装软件。
System Settings -> Network -> 设置 HTTP/HTTPS Proxy
System Settings -> Software & Updates -> Download from -> Main server
root@ubuntu:/# cp /etc/apt/sources.list /etc/apt/sources.list.backuproot@ubuntu:/# gedit /etc/apt/sources.list# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricteddeb http://archive.ubuntu.com/ubuntu xenial main restricteddeb http://archive.ubuntu.com/ubuntu xenial-updates main restricteddeb http://archive.ubuntu.com/ubuntu xenial universedeb http://archive.ubuntu.com/ubuntu xenial-updates universedeb http://archive.ubuntu.com/ubuntu xenial multiversedeb http://archive.ubuntu.com/ubuntu xenial-updates multiversedeb http://archive.ubuntu.com/ubuntu xenial-backports main restricted universe multiversedeb http://archive.ubuntu.com/ubuntu xenial-security main restricteddeb http://archive.ubuntu.com/ubuntu xenial-security universedeb http://archive.ubuntu.com/ubuntu xenial-security multiverse

3、更新
xl@ubuntu:~$ apt-get updatexl@ubuntu:~$ apt-get upgrade
4、开启虚拟机和主机的文件共享,拷贝linux kernel源文件到自己目录下,并解压
xl@ubuntu:~$ mv /mnt/hgfs/shareVMware02/linux-4.4.19.tar.xz ./compileKernel/xl@ubuntu:~/compileKernel$ xz -d linux-4.4.19.tar.xzxl@ubuntu:~/compileKernel$ tar xvf linux-4.4.19.tar
在编译之前安装下列软件
root@ubuntu:/home/xl/compileKernel/linux-4.4.19# apt-get install libncurses5-devroot@ubuntu:/home/xl/compileKernel/linux-4.4.19# apt-get install libssl-dev
将原来的配置拷贝过来,这样在用新的kernel启动的时候依然使用原来的配置
root@ubuntu:/boot# cp /boot/config-`uname -r` ./.config
每次编译前使用下列命令清理源代码树,第一次解压的源代码不需要
root@ubuntu:/boot# make mrproper
5、配置内核选项,这里面我使用了默认配置,后续会研究不同的内核选项配置
root@ubuntu:/boot# make menuconfig
6、编译,生成内核模块和压缩的内核文件。其中数字n是任务数,建议设置为CPU核心数的2倍。
root@ubuntu:/home/xl/compileKernel/linux-4.4.19# make -j n
安装内核动态加载模块文件到/lib/modules中相应的内核版本目录中
root@ubuntu:/home/xl/compileKernel/linux-4.4.19# make modules_installroot@ubuntu:/lib/modules/4.4.19# lsbuild          modules.alias.bin    modules.dep      modules.order    modules.symbols.binkernel         modules.builtin      modules.dep.bin  modules.softdep  sourcemodules.alias  modules.builtin.bin  modules.devname  modules.symbols
安装压缩文件到/boot分区
root@ubuntu:/home/xl/compileKernel/linux-4.4.19# make installroot@ubuntu:/boot# lsgrub                     vmlinuz-4.4.19               initrd.img-4.4.19 config-4.4.19            memtest86+.bin               System.map-4.4.19... ...
7、重启
root@ubuntu:/home/xl/compileKernel/linux-4.4.19# reboot
8、启动之后查看kernel版本,已经更新到新的kernel版本
root@ubuntu:/# cat /proc/versionLinux version 4.4.19 (root@ubuntu) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #1 SMP Thu Jul 6 11:43:38 PDT 2017

参考:
http://blog.csdn.net/xumin330774233/article/details/40371603
http://blog.csdn.net/cupidove/article/details/53671781
http://blog.csdn.net/jiejnan/article/details/6240976