在安裝linux的過程中都喜歡把boot掛單獨掛分區,一般設置500M,可隨著linux升級,往往會攢下好幾個內核,某一天系統會提示你升級失敗,空間不足了。
既然已經知道是boot空間不足了,那首先我們看看裡面都有神馬東西!!
BASICranger@ranger:~$ ls /boot
abi-2.6.35-25-generic memtest86+.bin
abi-2.6.35-27-generic memtest86+_multiboot.bin
abi-2.6.35-28-generic System.map-2.6.35-25-generic
config-2.6.35-25-generic System.map-2.6.35-27-generic
config-2.6.35-27-generic System.map-2.6.35-28-generic
config-2.6.35-28-generic vmcoreinfo-2.6.35-25-generic
grub vmcoreinfo-2.6.35-27-generic
initrd.img-2.6.35-25-generic vmcoreinfo-2.6.35-28-generic
initrd.img-2.6.35-27-generic vmlinuz-2.6.35-25-generic
initrd.img-2.6.35-28-generic vmlinuz-2.6.35-27-generic
lost+found vmlinuz-2.6.35-28-generic
我們可以看到都是一些內核啟動文件,很明顯有些是我們不需要的,其實以上都還是我已經卸載了倆比較老的內核的情況了,沒商量,不需要的就當垃圾處理掉。
首先請用 uname -a 看下自己當前啟動的是哪個內核。
BASICranger@ranger:~$ uname -a
Linux expired 2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:39:03 UTC 2011 x86_64 GNU/Linux
從中可以看到我此刻啟動的是 2.6.35-28-generic,再用 dpkg 命令看下你的機器上都有哪些內核文件。
BASICranger@ranger:~$ dpkg -get-selections |grep linux-image
linux-image-2.6.35-22-generic deinstall
linux-image-2.6.35-24-generic deinstall
linux-image-2.6.35-25-generic install
linux-image-2.6.35-27-generic install
linux-image-2.6.35-28-generic install
linux-image-generic install
不少,理論上除正在用的都可以刪除,但剛升級的東西可能不穩定,為保險起見,保留1-2個之前版本吧。
運行 apt-get remove 命令卸載不需要的內核。
BASICranger@ranger:~$ sudo apt-get remove linux-image-2.6.35-25-generic
The following packages will be REMOVED:
linux-image-2.6.35-25-generic
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 139MB disk space will be freed.
Do you want to continue [Y/n]? y
出現以上提示問是否繼續,按y或者直接回車繼續。完成後會有如下提示:
DKMS: uninstall Completed.
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 2.6.35-25-generic /boot/vmlinuz-2.6.35-25-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 2.6.35-25-generic /boot/vmlinuz-2.6.35-25-generic
Generating grub.cfg …
Found linux image: /boot/vmlinuz-2.6.35-28-generic
Found initrd image: /boot/initrd.img-2.6.35-28-generic
Found linux image: /boot/vmlinuz-2.6.35-27-generic
Found initrd image: /boot/initrd.img-2.6.35-27-generic
Found memtest86+ image: /memtest86+.bin
Found Windows 7 (loader) on /dev/sda1
Found Windows Vista (loader) on /dev/sda4
done
現在的 ubuntu 會自動重建啟動菜單 grub.cfg,所以就一步到位了。卸載完後可以用 df 命令看下 boot 分區的空間使用情況。
BASICranger@ranger:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda9 19223252 9429624 8817144 52% /
/dev/sda7 93207 53279 35116 61% /boot
ok,已經騰出35m空間了,現在可以運行 sudo apt-get upgrade 升級了。
再用 dpkg 看下還剩什麼東西。
BASICranger@ranger:~$ dpkg -get-selections | grep linux-image
linux-image-2.6.35-25-generic deinstall
linux-image-2.6.35-27-generic install
linux-image-2.6.35-28-generic install
linux-image-generic install
linux-image-2.6.35-25-generic 顯示deinstall,表示已經刪除,也許你覺得留著這個也不好看,那就重啟後再運行一次卸載命令就可以了:
BASICranger@ranger:~$apt-get remove linux-image-2.6.35-25-generic