因为工具的需求,因此需要在Ubuntu 16.04下安装指定版本的内核,因此需要将新版本的内核删除掉,然后重新安装,这里记录下操作过程
查看当前使用的内核版本:
root@ubuntu:~# uname -aLinux ubuntu 4.4.0-142-generic #168-Ubuntu SMP Wed Jan 16 21:00:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
安装需要使用的对应版本的Ubuntu linux内核:
root@ubuntu:~# apt-get install linux-image-4.4.0-97-generic
然后查看系统中已经安装的所有内核
root@ubuntu:~# dpkg --get-selections |grep linux-imagelinux-image-4.4.0-142-generic installlinux-image-4.4.0-62-generic installlinux-image-extra-4.4.0-142-generic installlinux-image-extra-4.4.0-62-generic installlinux-image-generic install
卸载不需要的内核。
root@ubuntu:~# apt-get remove linux-image-4.4.0-62-genericroot@ubuntu:~# apt-get remove linux-image-4.4.0-142-generic
需要注意的是,这里的linux-image-4.4.0-142-generic是当前正在使用的内核,卸载之后Ubuntu16.04会提示用户升级升级grub
root@ubuntu:~# apt-get remove linux-image-4.4.0-142-genericReading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required: amd64-microcode crda intel-microcode iucode-tool iw libnl-3-200 libnl-genl-3-200 wireless-regdbUse 'apt autoremove' to remove them.The following packages will be REMOVED: linux-generic linux-image-4.4.0-142-generic linux-image-extra-4.4.0-142-generic linux-image-generic0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.After this operation, 224 MB disk space will be freed.Do you want to continue? [Y/n] y(Reading database ... 87633 files and directories currently installed.)Removing linux-generic (4.4.0.142.148) ...Removing linux-image-generic (4.4.0.142.148) ...Removing linux-image-extra-4.4.0-142-generic (4.4.0-142.168) ...run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericrun-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericupdate-initramfs: Generating /boot/initrd.img-4.4.0-142-genericW: mdadm: /etc/mdadm/mdadm.conf defines no arrays.run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericrun-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericrun-parts: executing /etc/kernel/postinst.d/x-grub-legacy-ec2 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericSearching for GRUB installation directory ... found: /boot/grubSearching for default file ... found: /boot/grub/defaultTesting for an existing GRUB menu.lst file ... found: /boot/grub/menu.lstSearching for splash image ... none found, skipping ...Found kernel: /vmlinuz-4.4.0-142-genericFound kernel: /vmlinuz-4.4.0-97-genericFound kernel: /vmlinuz-4.4.0-142-genericFound kernel: /vmlinuz-4.4.0-97-genericUpdating /boot/grub/menu.lst ... donerun-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericGenerating grub configuration file ...Found linux image: /boot/vmlinuz-4.4.0-142-genericFound initrd image: /boot/initrd.img-4.4.0-142-genericFound linux image: /boot/vmlinuz-4.4.0-97-genericFound initrd image: /boot/initrd.img-4.4.0-97-genericdoneRemoving linux-image-4.4.0-142-generic (4.4.0-142.168) ...WARN: Proceeding with removing running kernel image.Examining /etc/kernel/postrm.d .run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericupdate-initramfs: Deleting /boot/initrd.img-4.4.0-142-genericrun-parts: executing /etc/kernel/postrm.d/x-grub-legacy-ec2 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericSearching for GRUB installation directory ... found: /boot/grubSearching for default file ... found: /boot/grub/defaultTesting for an existing GRUB menu.lst file ... found: /boot/grub/menu.lstSearching for splash image ... none found, skipping ...Found kernel: /vmlinuz-4.4.0-142-genericFound kernel: /vmlinuz-4.4.0-97-genericReplacing config file /run/grub/menu.lst with new versionFound kernel: /vmlinuz-4.4.0-97-genericReplacing config file /run/grub/menu.lst with new versionUpdating /boot/grub/menu.lst ... donerun-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-142-generic /boot/vmlinuz-4.4.0-142-genericGenerating grub configuration file ...Found linux image: /boot/vmlinuz-4.4.0-97-genericFound initrd image: /boot/initrd.img-4.4.0-97-genericdoneThe link /vmlinuz.old is a damaged linkRemoving symbolic link vmlinuz.old you may need to re-run your boot loader[grub]The link /initrd.img.old is a damaged linkRemoving symbolic link initrd.img.old you may need to re-run your boot loader[grub]
因此我们需要更新下grub
root@ubuntu:~# update-grubGenerating grub configuration file ...Found linux image: /boot/vmlinuz-4.4.0-97-genericFound initrd image: /boot/initrd.img-4.4.0-97-genericdone
搞定之后重启系统,然后确定系统使用了我们制定版本的内核
root@ubuntu:~# rebootroot@ubuntu:~# uname -aLinux ubuntu 4.4.0-97-generic #120-Ubuntu SMP Tue Sep 19 17:28:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
下一步,我们锁定当前内核版本使之在apt dist-upgrade时也不会被升级
root@ubuntu:~# apt-mark hold linux-image-4.4.0-97-genericlinux-image-4.4.0-97-generic set on hold.
测试下,果然不会被升级了。至此,可以安心的去安装软件了