考虑到 /boot 几乎已满,我该如何删除它或者从中删除什么?

考虑到 /boot 几乎已满,我该如何删除它或者从中删除什么?

我该如何清理 /boot 或者删除哪些内容,因为它几乎已满,而且我一直收到一条消息,说只剩下 5.1 MB。因为如果我转到磁盘使用情况分析器,就像它说的那样,没有可以清理的空间。

分区内容如下:

username@hostname:~$ ls -l /boot/
total 423041
-rw-r--r-- 1 root root  1443719 Aug  9 07:08 abi-4.10.0-32-generic
-rw-r--r-- 1 root root  1443962 Aug 11 13:59 abi-4.10.0-33-generic
-rw-r--r-- 1 root root  1443962 Sep 13 07:16 abi-4.10.0-35-generic
-rw-r--r-- 1 root root  1407843 Feb  5  2017 abi-4.8.0-36-generic
-rw-r--r-- 1 root root  1408375 Mar 31 14:01 abi-4.8.0-46-generic
-rw-r--r-- 1 root root  1408671 Apr 20 09:07 abi-4.8.0-49-generic
-rw-r--r-- 1 root root  1408813 Jun 14 11:17 abi-4.8.0-56-generic
-rw-r--r-- 1 root root  1408813 Jun 26 17:31 abi-4.8.0-58-generic
-rw-r--r-- 1 root root   204970 Aug  9 07:08 config-4.10.0-32-generic
-rw-r--r-- 1 root root   204970 Aug 11 13:59 config-4.10.0-33-generic
-rw-r--r-- 1 root root   204970 Sep 13 07:16 config-4.10.0-35-generic
-rw-r--r-- 1 root root   199575 Feb  5  2017 config-4.8.0-36-generic
-rw-r--r-- 1 root root   199564 Mar 31 14:01 config-4.8.0-46-generic
-rw-r--r-- 1 root root   199588 Apr 20 09:07 config-4.8.0-49-generic
-rw-r--r-- 1 root root   199564 Jun 14 11:17 config-4.8.0-56-generic
-rw-r--r-- 1 root root   199564 Jun 26 17:31 config-4.8.0-58-generic
drwxr-xr-x 3 root root     1024 Apr  9 12:00 efi
drwxr-xr-x 5 root root     1024 Sep 20 05:03 grub
-rw-r--r-- 1 root root 42058341 Aug 28 10:57 initrd.img-4.10.0-32-generic
-rw-r--r-- 1 root root 42056847 Aug 29 02:58 initrd.img-4.10.0-33-generic
-rw-r--r-- 1 root root 42056820 Sep 20 05:03 initrd.img-4.10.0-35-generic
-rw-r--r-- 1 root root 40647942 Aug 28 10:56 initrd.img-4.8.0-36-generic
-rw-r--r-- 1 root root 40638652 Aug 28 10:55 initrd.img-4.8.0-46-generic
-rw-r--r-- 1 root root 40637975 Aug 28 10:55 initrd.img-4.8.0-49-generic
-rw-r--r-- 1 root root 40644972 Aug 28 10:55 initrd.img-4.8.0-56-generic
-rw-r--r-- 1 root root 40643997 Aug 28 10:55 initrd.img-4.8.0-58-generic
drwx------ 2 root root    12288 Apr  9 12:00 lost+found
-rw-r--r-- 1 root root   182704 Jan 28  2016 memtest86+.bin
-rw-r--r-- 1 root root   184380 Jan 28  2016 memtest86+.elf
-rw-r--r-- 1 root root   184840 Jan 28  2016 memtest86+_multiboot.bin
-rw------- 1 root root  3718993 Aug  9 07:08 System.map-4.10.0-32-generic
-rw------- 1 root root  3721812 Aug 11 13:59 System.map-4.10.0-33-generic
-rw------- 1 root root  3721891 Sep 13 07:16 System.map-4.10.0-35-generic
-rw------- 1 root root  4060748 Feb  5  2017 System.map-4.8.0-36-generic
-rw------- 1 root root  4066103 Mar 31 14:01 System.map-4.8.0-46-generic
-rw------- 1 root root  4066773 Apr 20 09:07 System.map-4.8.0-49-generic
-rw------- 1 root root  4068016 Jun 14 11:17 System.map-4.8.0-56-generic
-rw------- 1 root root  4068043 Jun 26 17:32 System.map-4.8.0-58-generic
-rw------- 1 root root  7398816 Aug  9 07:08 vmlinuz-4.10.0-32-generic
-rw------- 1 root root  7404416 Aug 11 13:59 vmlinuz-4.10.0-33-generic
-rw------- 1 root root  7405152 Sep 13 07:16 vmlinuz-4.10.0-35-generic
-rw-r--r-- 1 root root  7297312 Apr  9 12:08 vmlinuz-4.8.0-36-generic
-rw------- 1 root root  7305856 Mar 31 14:01 vmlinuz-4.8.0-46-generic
-rw------- 1 root root  7305856 Apr 20 09:07 vmlinuz-4.8.0-49-generic
-rw------- 1 root root  7309536 Jun 14 11:17 vmlinuz-4.8.0-56-generic
-rw------- 1 root root  7310848 Jun 26 17:31 vmlinuz-4.8.0-58-generic
username@hostname:~$ 

答案1

这是一个可以自动执行此操作的脚本。

清理 /boot 空间的最简单方法是删除旧的和未使用的内核。删除内核时,切勿删除当前正在使用的内核(使用 uname -r 检查),也不要删除最新内核,否则下次升级时您将再次下载它。

每个内核及其相关的磁盘资源占用大约 50MB 的空间。您还想仅使用 apt purge 删除内核,因为它会在最后删除依赖项并更新 grub。您可以使用 dpkg -l | grep linux-image 查看已安装内核的列表。

自动删除并不总是能获取所有旧内核。

#!/bin/bash

# create the clean-boot command line utility, if it doesn't exist
if [ ! -f /usr/sbin/clean-boot ]; then
    cp "$0" /usr/sbin/clean-boot
    chown root.root /usr/sbin/clean-boot
    chmod 0770 /usr/sbin/clean-boot
fi

# add clean-boot cron job to root's crontab, if it doesn't exist
if [[  `crontab -l | grep "/usr/sbin/clean-boot" | wc -l` -eq 0 ]]; then    
    (crontab -l 2>/dev/null; echo "0 10 * * 3,4 /usr/sbin/clean-boot") | crontab -
fi


# array of kernels installed on the system
kernels=($(dpkg --list | grep 'linux-image-[0-9]' | awk '{ print $2 }'))

# kernel currently being used by the system 
current_kernel=linux-image-`uname -r`

# newest kernel installed (currently being initialized to current_kernel)
newest_kernel=$current_kernel


# for loop below used to find the newest insitalled kernel
for i in "${kernels[@]}"
do

    # since newest is initialized to current, there is no need to parse through kernels same version as the one currently loaded
    if [[ $i != $current_kernel*  ]]; then

        # each iteration of the for loop is for each version number (kernel version, major, minor, incidental numbers) example 4.8.0-56-generic
        for counter in 1 2 3 4
        do

            # if statement extracts the version numbers
            if [[ $counter -lt 3 ]]; then

                compare_number=$(echo ${i#"linux-image-"} | cut -d'.' -f$counter)
                newest_number=$(echo  ${newest_kernel#"linux-image-"} | cut -d'.' -f$counter)

            elif [[ $counter -eq 3 ]]; then

                compare_number=$(echo ${i#"linux-image-"} | cut -d'.' -f$counter)
                newest_number=$(echo  ${newest_kernel#"linux-image-"} | cut -d'.' -f$counter)

                compare_number=$(echo ${compare_number} | cut -d'-' -f1)
                newest_number=$(echo  ${newest_number} | cut -d'-' -f1)             

            else

                compare_number=$(echo ${i#"linux-image-"} | cut -d'-' -f2)
                newest_number=$(echo  ${newest_kernel#"linux-image-"} | cut -d'-' -f2)

            fi

            # this if statement does the comparison
            if [[ $compare_number -eq $newest_number ]]; then
                continue
            elif [[ $compare_number -lt $newest_number ]]; then
                break
            else
                newest_kernel=$i
                break
            fi

        done

    fi

done


# for every kernel
for i in "${kernels[@]}"
do

    # delete the kernel if the kernel is not the one in use and is not the newest one installed
    if [[ $i != $current_kernel* && $i != $newest_kernel* ]]; then

        apt-get purge "$i" -y

    fi 

done

相关内容