April 2014
M T W T F S S
« Mar    
 123456
78910111213
14151617181920
21222324252627
282930  
156

Refs

Categories

Archives

profile for slm on Stack Exchange, a network of free, community-driven Q&A sites

[one-liner]: What options were used to boot my Linux Kernel?

Background

In newer versions of Linux distros the GRUB2 configuration file is often times locked down so that you need sudo rights to see what options the Linux Kernel was booted with. Using the following tip you can see these options as just a regular “joe” user.

Solution

This tip is pretty straightforward, since now the options are reflected under the /proc filesystem so that anyone can see them. Here’s an example from my Fedora 19 laptop:

1
2
$ cat /proc/cmdline 
BOOT_IMAGE=/vmlinuz-3.13.6-100.fc19.x86_64 root=/dev/mapper/fedora_greeneggs-root ro rd.md=0 rd.dm=0 vconsole.keymap=us rd.lvm.lv=fedora_greeneggs/swap rd.lvm.lv=fedora_greeneggs/root rd.luks=0 vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_US.UTF-8

You can also get them using the more convention method via sudo:

1
2
3
4
5
$ sudo grep -E "\s+linux" /boot/grub2/grub.cfg 
	linux	/vmlinuz-3.13.6-100.fc19.x86_64 root=/dev/mapper/fedora_greeneggs-root ro rd.md=0 rd.dm=0 vconsole.keymap=us rd.lvm.lv=fedora_greeneggs/swap  rd.lvm.lv=fedora_greeneggs/root rd.luks=0 vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_US.UTF-8
	linux	/vmlinuz-3.13.5-103.fc19.x86_64 root=/dev/mapper/fedora_greeneggs-root ro rd.md=0 rd.dm=0 vconsole.keymap=us rd.lvm.lv=fedora_greeneggs/swap  rd.lvm.lv=fedora_greeneggs/root rd.luks=0 vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_US.UTF-8
	linux	/vmlinuz-3.12.11-201.fc19.x86_64 root=/dev/mapper/fedora_greeneggs-root ro rd.md=0 rd.dm=0 vconsole.keymap=us rd.lvm.lv=fedora_greeneggs/swap  rd.lvm.lv=fedora_greeneggs/root rd.luks=0 vconsole.font=latarcyrheb-sun16 rhgb quiet LANG=en_US.UTF-8
	linux	/vmlinuz-0-rescue-0ee868f8b7da40f48013a281826b1b84 root=/dev/mapper/fedora_greeneggs-root ro rd.md=0 rd.dm=0 vconsole.keymap=us rd.lvm.lv=fedora_greeneggs/swap  rd.lvm.lv=fedora_greeneggs/root rd.luks=0 vconsole.font=latarcyrheb-sun16 rhgb quiet

References

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

[one-liner]: Linux Runlevels

Background

Determining a systems runlevel can be useful when setting up a headless server or determining if a system is being used as a server or as a workstation. Thankfully it’s pretty easy, using a number of commands. But before we get started, a little background.

Runlevels are a concept from UNIX System V used by the init(8) daemon or other system initialization system to define modes of system operation. Eight runlevels are permitted, the first seven are numbered 0-6 and the eighth is named S or s (both are permitted). Services and other system components are said to exist in one or more runlevels. When switching from one runlevel to another, the services that should not exist in the new runlevel are stopped and the services that only exist in the new runlevel are started.

NOTE: Runlevels 0, 1 and 6 are reserved. Runlevel 0 is used to halt the system and 6 to reboot the system. Run level 1 is used to bring the system back down into single-user mode, after which the runlevel will be S.

Solution

To determine a system’s runlevel you can use one of the following methods.

#1 – who

The 1st one I’ll cover, and the least obvious – at least to me, is the command who. This is the reason that I’m writing this post!

1
2
$ who -r
         run-level 3  2013-12-02 21:45
#2 – runlevel

The much more direct method is to use the command, runlevel.

1
2
$ runlevel
N 3
Changing runlevels

To do this you can use one of 2 commands, init or telinit. Both take a number as an argument or a character such as “S” for single user mode aka. runlevel 1.

1
2
3
4
5
6
7
8
9
10
# Examples
$ init 1     # single user mode
$ telinit S  # single user mode
 
$ telinit 3
 
$ telinit 0  # halt
$ telinit 6  # reboot
 
$ telinit Q  # re-read /etc/inittab file
Rebooting & Halting

You can also use the shutdown command to perform a reboot and/or a halt, as well as the commands reboot, halt, & poweroff.

1
2
3
4
5
6
7
8
# Examples
$ shutdown -h now    # halt 
 
$ shutdown -r now    # reboot
 
$ reboot
$ halt
$ poweroff
Changing permanently

All the changing we’ve been doing above are temporary. To change a system’s runlevel permanently so that instead of say 5 it’s now 3, you’ll need to edit init‘s configuration file, /etc/inittab. A change like this to the file:

1
id:3:initdefault:

Save it and either tell init to re-read it using the command telinit Q or reboot the system.

References

links

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

[one-liner]: Improving the performance of SSH Tunnels using Alternative Ciphers; when displaying X11 Apps

Background

Have you ever used an ssh tunnel to try and remotely display an X windowed application and then wished you hadn’t, because the performance was so bad you’d be waiting till next week for the window to come up?

Read on because here’s how you can make this much more tolerable & usable.

Solution

There are 2 configuration changes you can make when connecting 2 systems via an ssh tunnel which make it completely usable. The settings can be applied either via command line switches to ssh or as permanent configuration changes within your $HOME/.ssh/config file.

Method #1: command line switches

1
% ssh -c arcfour,blowfish-cbc -XC <server>

Method #2: config file changes

1
2
3
4
5
Host remotey
  User userX
  Ciphers arcfour,blowfish-cbc
  Compression yes
  ProxyCommand ssh user1@ext-dom.com nc host1.int-dom.com %p

References

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

[one-liner]: Securing your Subversion Password using GPG Agent

Background

If you’ve ever dealt with subversion on Unix, one of the annoyances is that it essentially stores it’s password in clear text under your $HOME/.subversion/auth/svn.simple directory in text files. Not a huge deal to a single developer or user but if you work in a large company or even a small one this is a pretty bad implementation. Well here’s a method which at least get’s the password out of these clear text files.

Solution

The solution came up while I was research something else, as is usually the case. I found this paper titled: GPG-agent based secure password cache for Subversion Version Control System. The paper covers work that was done on behalf of Collabnet (the original owners of the subversion project).

Image of GNOME Keyring

Image of GNOME Keyring

I haven’t had a chance to try this out but this point is meant as a reminder to me and also to others that this is a reality (finally) with the stock Subversion software. It looks to be built in with the 1.8 release. This commit to the Subversion trunk highlights this new auth capability and how it works along with several security considerations if you plan on using it.

References

local copies

NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.

How to programmatically determine the highest version kernel RPM installed?

Background

Recently on the StackExchange site Unix & Linux the following question came up which seemed easy enough to answer.

This turned out to be trickier than I originally thought. What follows is my ultimate answer along with several failed attempts. I leave them so that others can learn from my mistakes.

Solution

TL;DR

The 3rd attempt is what ultimately worked! I’m leaving the first 2 attempts so that others that may come across this post in the future will hopefully gain some insight into how non-trivial a problem it is to parse RPM version information and determine the lineage of which came first, second, etc.

Attempt #1 (didn’t work)

This command will sort the output and give you them in version order:

1
2
3
4
5
$ rpm -q kernel --queryformat "%{VERSION} %{RELEASE}\n"|sort -n
2.6.18 238.12.1.el5
2.6.18 238.19.1.el5
2.6.18 274.12.1.el5
2.6.18 308.8.2.el5

WHY IT DIDN’T WORK: A naive person would think that you can use some variant of the sort command to perform this task, but there is enough variability and inconsistency in the formatting of the actual version information for a given RPM that it just isn’t up to the task.

Attempt #2 (didn’t work)
1
2
$ rpm -q --last kernel | head -n 1 | cut -d' ' -f1
kernel-2.6.35.14-106.fc14

WHY IT DIDN’T WORK: I had high hopes that this approach would yield the results, but the issue with this one as was pointed out to me afterwards, is that the --last switch is merely returning the results sorted by the date the RPMs were installed.

Attempt #3

This one will definitely do the job. I found a suite of tools called RPM Development Tools. There are 2 tools in this suite that will give you the capability to determine whether one version of a RPM is newer or older than another.

If the RPM isn’t already installed you can do so as follows:


…. Continue reading → How to programmatically determine the highest version kernel RPM installed? »»

Why are executables such as reboot, shutdown, and vgscan symlinks in the /sbin directory?

Background

If you’ve ever gone poking around in your Linux system’s /sbin directory the site of files like this might make you scratch your head.

1
2
3
4
5
6
7
8
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgmerge -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgmknodes -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgreduce -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgremove -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgrename -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgs -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgscan -> lvm
lrwxrwxrwx  1 root root       3 Jun  7  2011 vgsplit -> lvm

We’ll read on and I’ll explain how all these seemingly regular tools are actually just one.

So What’s going on?

Many programs make use of this technique where there is a single executable that changes it’s behavior based on how it was executed.

There’s typically a structure inside the program called a case/switch statement that determines the name the executable was called with and then will call the appropriate functionality for that executable name. That name is usually the first argument the program receives. For example, in the C programming language when you write:

1
int main(char** argv, int argc)

argv[0] contains the name of the called executable. At least, this is the standard behavior for all shells, and all executables that use arguments should be aware of it.

Example in Perl

Here’s a contrived example I put together in Perl which shows the technique as well.


…. Continue reading → Why are “executables” such as reboot, shutdown, and vgscan symlinks in the /sbin directory? »»

Page 1 of 3412345...102030...Last »