Craig Sanders: grub-list-kernels.pl
Due to boredom and needing something to do to keep my brain from atrophying, I ve decided to polish some of the rough edges off some of my scripts so that they re suitable for publication.
here s the first of them, a perl script to list kernels and other grub menu entries, with numeric indexing suitable for use with
grub-set-default and grub-reboot
output looks like this:
# grub-list-kernels.pl 0 Debian GNU/Linux 1 Advanced options for Debian GNU/Linux 1>0 Debian GNU/Linux, with Linux 3.9-1-amd64 1>1 Debian GNU/Linux, with Linux 3.9-1-amd64 (recovery mode) 1>2 Debian GNU/Linux, with Linux 3.8-2-amd64 1>3 Debian GNU/Linux, with Linux 3.8-2-amd64 (recovery mode) 1>4 Debian GNU/Linux, with Linux 3.8-1-amd64 1>5 Debian GNU/Linux, with Linux 3.8-1-amd64 (recovery mode) 1>6 Debian GNU/Linux, with Linux 3.7-trunk-amd64 1>7 Debian GNU/Linux, with Linux 3.7-trunk-amd64 (recovery mode) 1>8 Debian GNU/Linux, with Linux 3.2.0-4-amd64 1>9 Debian GNU/Linux, with Linux 3.2.0-4-amd64 (recovery mode) 2 Network boot (iPXE) 3 Bootable floppy: LSI 4 Bootable floppy: freedos-bare Default: 0 "Debian GNU/Linux"(this example tells me i need to uninstall some old kernels) and here s the script:
#! /usr/bin/perl
# parse and list the boot entries in the grub boot menu (grub.cfg)
#
# $Id: grub-list-kernels.pl,v 1.8 2013/06/20 10:36:47 cas Exp $
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Craig Sanders <cas@taz.net.au>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# Partial Revision History:
# 2013-06-20 - better handling of non-numeric default saved entries, code still uglyish but better commented.
# 2013-05-13 - first stab at support for submenus...works but uglified the code
# 2010-11-03 - rewrote for grub2 (grub.cfg rather than menu.lst)
use strict;
my $cfg = shift '/boot/grub/grub.cfg';
my $grubenv='/boot/grub/grubenv';
# hash of kernels (menu entry index -> menu entry description)
# e.g. '4' => 'Debian GNU/Linux, with Linux 3.8-1-amd64'
my %K = ();
# hash of menuentry_id_option -> menuindex
# e.g. 'gnulinux-3.8-1-amd64-advanced-6bb6d228-0581-49ae-9d49-dd148c273ecc' => 4
my %M = ();
# read in the menu entries.
open(MENU,"<$cfg") die "couldn't open $cfg for read: $!\n" ;
my $insubmenu = 0;
my $menuitem=0;
my $submenuitem=0;
my $prefix='';
my $menuindex='';
my $kernel='';
my $menuidoption='';
while (<MENU>)
#next unless /^\s*menuentry\s/io;
chomp;
if ($insubmenu ne 0)
next unless /^\s*(menuentry submenu)\s ^ $/io;
if (m/^ $/) $insubmenu = 0 ; $prefix='' ; next ;
$menuindex = $prefix . $submenuitem++;
else
next unless /^\s*(menuentry submenu)\s/io;
if (m/submenu/)
$insubmenu=1;
$prefix = $menuitem . '>';
$submenuitem = 0;
$menuindex = $submenuitem;
;
$menuindex = $menuitem++;
# sometimes the default entry saved in grubenv is the menu_id_option
# rather than numeric. The %M hash links menu_id_option to menuindex
# numbers.
# e.g. 'gnulinux-3.8-1-amd64-advanced-6bb6d228-0581-49ae-9d49-dd148c273ecc' => 4
$menuidoption='';
my $line = $_;
if ($line =~ m/menuentry_id_option/)
$line =~ s/.*menuentry_id_option '//;
$line =~ s/'.*//;
$menuidoption=$line;
$M $menuidoption = $menuindex;
;
s/[^'"]*["']([^'"]*)['"].*/$1/;
$kernel = $_;
$K $menuindex = $kernel;
#printf "%4s\t%s\t%s\n", $menuindex, $_, $menuidoption;
printf "%4s\t%s\t\n", $menuindex, $_;
;
# now get the default kernel and boot-once kernel if any
my $saved_entry='';
my $prev_saved_entry='';
my $defk = 0;
my $once = 0;
open(GRUBENV, "<$grubenv") die "couldn't open $grubenv for read: $!\n" ;
while (<GRUBENV>)
chomp;
next unless /saved_entry/;
if (/^saved_entry/)
(undef,$saved_entry) = split /=/;
elsif (/^prev_saved_entry/)
(undef,$prev_saved_entry) = split /=/;
close(GRUBENV);
$saved_entry = 0 if ($saved_entry eq '');
if ($prev_saved_entry ne '')
$defk = $prev_saved_entry;
$once = $saved_entry;
else
$defk = $saved_entry;
# if $defk is non-numeric, look up index in %M
if ($defk !~ /^[0-9]+$/)
$defk = $M $defk ;
# if $once is non-numeric, look up index in %M
if ($once !~ /^[0-9]+$/)
$once = $M $once ;
print "\n Default: $defk";
print " \"", $K $defk , "\"\n";
if ($prev_saved_entry ne '')
print "Boot Once: $once";
print " \"", $K $once , "\"\n";
grub-list-kernels.pl is a post from: Errata

One of
Mir is Canonical's equivalent to Wayland - a display server, responsible for getting application pixmaps onto a screen. It's intended to scale from mobile devices to the desktop, and as such is expected to turn up in Ubuntu Phone before too long[1]. There's already plenty of discussion about whether the technical differences between Wayland and Mir are sufficient to justify Canonical going their own way, so I'm not planning on talking about that.

Last year, I applied for academic,

Today, she's introduced
A Queensland pensioner made
The scariest thing is that if Australians see through this racist charade and refuse to vote for it, we could end up with something equally obnoxious: the
Recently, there's been discussions on IRC and the debian-devel mailing
list about how to notify users, typically from a cron script or a
system daemon needing to tell the user their hard drive is about to
expire. The current way is generally "send email to root" and for
some bits "pop up a notification bubble, hoping the user will see
it". Emailing me means I get far too many notifications. They're
often not actionable (
When the
Sorry
The purpose of a backup is to allow you to recover from a disaster with
reasonable cost and effort. If you delete a file you shouldn't have,
or make changes that you shouldn't have, backups are meant to save you
from having to re-create the file, or undo a large amount of steps.
Speaking very broadly, any copy of your live data is a backup, but this
is a uselessly broad definition. For example, if you use an automatic
synchronisation system such as Dropbox or git-annex, to keep your live
data in sync between two computers, you could pretend they're backups
of each other. However, unless the synchronisation also allows you to
keep a history of file versions, it's not a very good backup. If you
delete your precious file on one computer, and it gets then deleted on
the other computer as well, automatically, perhaps in seconds, then the
backup is not of much use.
Another common assumption is that a RAID array works as a backup. RAID
is an excellent technology that allows you to combine several hard disks
so that they protect you against loss of data in case of disk failure.
If one disk fails, the others have enough data to re-create the data on
the failed disk, using either full copies (RAID-1) or error correction
codes (RAID-5, RAID-6). This is not a backup. It doesn't protect you
against accidental file deletions. There is also no backup history.
A version control system is very much like a backup. It stores copies
of many of the versions of your project. However, in most version
control systems it's fairly easy to make changes that lose history. Ask
anyone who has used
With the PRISM scandal, there has been some talk about encrypted
communication systems. For instance,
In light of the recent leaks about the NSA's illegal spying, I've decided to go back to using