scripts - How do you find out when a specific kernel version was last booted? - Ask Ubuntu


find out when specific kernel version last booted

for manually install kernel versions /boot can grow large on time. i'd find kernel versions haven't been booted in long time candidates removal.

file last accessed time

to facilitate project need know when each kernel last booted. saw q&a finding files older date using atime. q&a went searching files older x days. i'm looking files , wanting know last access time.

via bash script how 1 determine given file's last access time?

edit 1 - must set kernel version's last access time during boot

when grub mounts kernel in ro (read-only) mode , last access time not updated.

if run update-initramfs -u -k all file initrd.img last access time updated kernels though haven't been booted today.

when installing new kernel previous kernel version files system.map-w.x.yy-zzz last access time updated though haven't been booted today.

to correctly record when kernel version booted need touch file vmlinuz-w.x.yy-zzz. using sudo powers create file in /etc/cron.d/:

shell=/bin/sh path=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin @reboot   root    touch "/boot/vmlinuz-"`uname -r` 

now when listing files in /boot using muru's answer:

find /boot/vm* -printf "%ac %p\n"

thu 21 jul 2016 05:02:48 mdt /boot/vmlinuz-3.13.0-92-generic wed 26 oct 2016 05:10:08 pm mdt /boot/vmlinuz-3.2.0-113-generic sat 15 oct 2016 10:45:41 mdt /boot/vmlinuz-4.4.0-43-generic thu 20 oct 2016 06:09:00 pm mdt /boot/vmlinuz-4.4.0-45-generic sat 06 aug 2016 09:32:02 pm mdt /boot/vmlinuz-4.6.3-040603-generic sun 21 aug 2016 12:59:04 pm mdt /boot/vmlinuz-4.7.1-040701-generic fri 26 aug 2016 04:51:04 mdt /boot/vmlinuz-4.7.2-040702-generic thu 08 sep 2016 06:46:52 pm mdt /boot/vmlinuz-4.7.3-040703-generic sun 25 sep 2016 07:25:46 pm mdt /boot/vmlinuz-4.7.5-040705-generic sat 08 oct 2016 03:08:45 pm mdt /boot/vmlinuz-4.8.1-040801-generic sat 22 oct 2016 08:16:44 mdt /boot/vmlinuz-4.8.4-040804-generic sun 30 oct 2016 12:56:12 pm mdt /boot/vmlinuz-4.8.5-040805-generic 

check free space before installing new kernel version

before installing new kernel it's idea check how space available in /boot and/or how being used these commands:

rick@dell:~$ df /boot filesystem     1k-blocks     used available use% mounted on /dev/sdc3       30106300 20449376   8104556  72% / ──────────────────────────────────────────────────────────────── rick@dell:~$ du /boot --max-depth 0 -h 565m    /boot 

to see how space saved deleting specific previous kernel use command:

rick@dell:~$ du /boot/*4.8.1* -h 1.4m    /boot/abi-4.8.1-040801-generic 204k    /boot/config-4.8.1-040801-generic 44m /boot/initrd.img-4.8.1-040801-generic 3.6m    /boot/system.map-4.8.1-040801-generic 4.8m    /boot/vmlinuz-4.8.1-040801-generic 

use stat command:

   %x     time of last access, human-readable    %x     time of last access, seconds since epoch 

so:

stat -c %x /some/file 

or find:

find /some/path -printf "%a@ %p\n" 

since find's -printf:

  %a     file's  last  access time in format returned c          `ctime' function.    %ak    file's last access time in  format  specified   k,            either `@' or directive c `strftime'          function.  possible values k   listed  below;           of  them might not available on systems, due          differences in `strftime' between systems.           @      seconds  since  jan.  1,  1970,  00:00  gmt,                  fractional part. 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User