分页: 2 / 2

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2011-04-05 9:59
yuzh652800
kubuntu下ubuntu-tweak好像不怎么好使,只能用老办法了。

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2011-04-12 20:21
糖衣炮弹
o哦拉,问题解决,谢谢楼主。
真操作过程中貌似grub.cfg不用修改,运行完卸载命令就没有了。

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2011-04-12 20:24
eexpress

代码: 全选

sudo aptitude purge ~ilinux-.*\(\!`uname -r|cut -d- -f1-2`\)~i[0-9]

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2011-04-12 20:27
tenzu
又见神码 :em70

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2014-01-19 22:06
nmimi
eexpress 写了:

代码: 全选

sudo aptitude purge ~ilinux-.*\(\!`uname -r|cut -d- -f1-2`\)~i[0-9]
这段命令写不出来。

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2014-05-27 17:58
xyq164288
eexpress 写了:

代码: 全选

sudo aptitude purge ~ilinux-.*\(\!`uname -r|cut -d- -f1-2`\)~i[0-9]

已试用!确实神码!!!

Re: 删除Ubuntu Linux旧内核的方法

发表于 : 2014-05-27 18:50
youzhiyili
呵呵,对比老外的方法,E神的的确最短 :em11

方法一:

代码: 全选

sudo apt-get -y purge $(dpkg --get-selections | awk '((/^linux-/) && (/[0-9]\./) && (!/'"`uname -r | sed "s/-generic//g"`"'/)) {print $1}')
方法二:

代码: 全选

sudo dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
方法三:

代码: 全选

#/bin/bash
ls /boot/ | grep vmlinuz | sed 's@vmlinuz-@linux-image-@g' | grep -v `uname -r` > /tmp/kernelList
for I in `cat /tmp/kernelList`
do
aptitude remove $I
done
rm -f /tmp/kernelList
update-grub
方法四:(国产交互式的)

代码: 全选

#!/bin/bash
#Program:
# Let user uninstall unused kernels which installed as debian package form.
#Author:
# mtyy110
#ubuntu删除旧内核
dialog=whiptail
if [ "`whoami`" != 'root' ]; then
echo '需要root权限'
exit 1
fi

dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-"

while [ 1 ]
do

total=`dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-" | wc -l`
read -p "要删除哪个版本?(0 退出)" version
if [ $version = "0" ]; then
break
fi 


tmp=`echo $version | grep "^[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-\{0,1\}[0-9]\{0,2\}$" | wc -l`
if [ $tmp -eq 0 ]; then
echo "格式不对,请输入正确的版本格式"
continue
fi 


sum=`dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-" | grep "$version" | wc -l`
if [ $sum -eq 0 ]; then
echo "没发现这个版本:$version"
continue
fi 


tmp=`uname -r | grep "$version" | wc -l`
if [ $tmp -eq 1 ]; then
read -p "`uname -r` 是当前正在使用的内核,确定要删除?(y/N)" choice
if [ "$choice" != 'y' -a "$choice" != 'Y' ]; then
continue
fi 
fi 


if [ $total -le $sum ]; then
read -p "确定要卸载所有内核?(y/N)" choice
if [ "$choice" -o 'y' -a "$choice" -o 'Y' ]; then
continue
fi 
fi 


apt-get remove `dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-$version" | cut -f 1`
read -p "是否继续删除其他的内核?(Y/n)" choice
if [ "$choice" = 'n' -o "$choice" = 'N' ]; then
break
fi


dpkg --get-selections | grep 'linux-' | grep -v 'deinstall' | grep "\-[0-9]\.[0-9]\{1,2\}\.[0-9]\{1,2\}\-"


done
exit 0