最近在 Ubuntu 上更新套件時,突然遇到了錯誤,

說 /boot 目錄滿了...

嗯~真怪了?我的分割區是系統預設值,用 df 看一下:

testuser@localhost:~$ df -h /boot

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       236M  221M  2.8M  99% /boot

 

居然真的是爆滿的狀態...

看一下 /boot 裡面有很多的 kernel 檔案,哪些可以砍掉呢?

 

參考資料:nixCraft: Safely Remove / Delete Old Linux Kernel from a Linux Server

 

1. 列出現有的 kernel 檔案

執行 dpkg ---list 'linux-image*' 看一下現有的 kernel 檔案,

前面有 ii 的就是已經安裝的:

testuser@localhost:~$ dpkg --list 'linux-image*'

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                              Version               Architecture          Description
+++-=================================-=====================-=====================-========================================================================
un  linux-image                       <none>                <none>                (no description available)
un  linux-image-3.0                   <none>                <none>                (no description available)
rc  linux-image-3.16.0-30-generic     3.16.0-30.40~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-34-generic     3.16.0-34.47~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-36-generic     3.16.0-36.48~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-37-generic     3.16.0-37.51~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-38-generic     3.16.0-38.52~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-41-generic     3.16.0-41.57~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-43-generic     3.16.0-43.58~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-3.16.0-45-generic     3.16.0-45.60~14.04.1  amd64                 Linux kernel image for version 3.16.0 on 64 bit x86 SMP
rc  linux-image-extra-3.16.0-30-gener 3.16.0-30.40~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-extra-3.16.0-34-gener 3.16.0-34.47~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-extra-3.16.0-36-gener 3.16.0-36.48~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-extra-3.16.0-37-gener 3.16.0-37.51~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-extra-3.16.0-38-gener 3.16.0-38.52~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
ii  linux-image-extra-3.16.0-41-gener 3.16.0-41.57~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
iF  linux-image-extra-3.16.0-43-gener 3.16.0-43.58~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
iF  linux-image-extra-3.16.0-45-gener 3.16.0-45.60~14.04.1  amd64                 Linux kernel extra modules for version 3.16.0 on 64 bit x86 SMP
iU  linux-image-generic-lts-utopic    3.16.0.45.36          amd64                 Generic Linux kernel image

 

2. 檢視現在的 kernel 版本

用 uname -a 就可以看到現在的 kernel 版本:

testuser@localhost:~$ uname -a

Linux localhost 3.16.0-41-generic #57~14.04.1-Ubuntu SMP Thu Jun 18 18:01:13 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

 

3. 移除不需要的 kernel 檔案

因為我的 kernel 版本是 3.16.0-41-generic,因此其他的應該都可以刪除,

不過保險起見,我只刪除比 3.16.0-41-generic 舊的 kernel 檔案~

sudo apt-get remove linux-image-3.16.0-30-generic linux-image-3.16.0-34-generic linux-image-3.16.0-36-generic linux-image-3.16.0-37-generic linux-image-3.16.0-38-generic

 

接著再執行一下 apt-get autoremove 移除掉多餘的套件:

sudo apt-get autoremove

 

3. 檢查現在的目錄大小

再用 df 看一次現在的目錄大小...

釋放了將近 120 MB 的大小,真是太好啦~

testuser@localhost:~$ df -h /boot

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       236M  100M  124M  45% /boot

 

文章標籤
創作者介紹

亂打一通的心情日記

ephrain 發表在 痞客邦 PIXNET 留言(0) 人氣()