Working with logical volumes (part 2)

In this post I want to cover one of the most commonly used features of lvm, extending a logical volume. If you were following along with the last post, “Working with logical volumes part 1”, then you should already have a volume group with a couple of live volumes attached.

With lvm you can quickly and easily extend a Linux file system on the fly without interrupting any services.

Continue reading “Working with logical volumes (part 2)”

Linux Server won’t restart

Not too long ago I ran into a problem where a server with systemd would not shutdown or reboot through normal means.

When executing  sudo shutdown -r now I would get a weird message back as output:

Failed to start reboot.target: Connection timed out
See system logs and 'systemctl status reboot.target' for details.
Failed to open /dev/initctl: No such device or address
Failed to talk to init daemon.

I’m still not entirely certain what caused the problem and the suggestion of running  systemctl status reboot.target to troubleshoot simply resulted in the same message being displayed.

However, if you run into this problem and you just need to get your services back up and running you can force a reboot like this:

Try this first:

systemctl --force reboot

If that doesn’t work, which it didn’t for me, add another –force but know that this will unceremoniously kill all running process.

systemctl --force --force reboot

This of course assumes that you can still gain access to the terminal via ssh. This operation is essentially the same as holding down the power button on a physical machine or hitting the reset button on a VM.

According to the man page this can dangerous if you have a process running that is trying to save data so be certain that you want to forcibly kill off every process on your server before running this command. Try it with only a single –force first.

sudo bang bang

So a day or two ago a co-worker mentioned that you can do  sudo !! to execute the last command in your history as root. I had never heard of such a thing! My life has been changed forever!

Here I’ve been hitting the back arrow like a peasant just to put  sudo in front of a previous command.

Please use your new found powers responsibly.

Command not found!

So you’re running through some instructions to configure software on your system, or troubleshoot some problem with a service and you see an error at the command line that says “command not found”. Here is how to locate the packages you need to install in order to use commands that are not available on your system.

CentOS/Red Hat – yum provides

Yum is an excellent package manager with lots of great built in functions. Using  yum provides <command> will output a list of packages that provide the command you are trying to run. Here is an example of the output.

sudo yum provides vgscan
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: repo1.sea.innoscale.net
 * epel: mirror.cogentco.com
 * extras: mirror.cisp.com
 * nux-dextop: mirror.li.nux.ro
 * updates: ftp.linux.ncsu.edu
7:lvm2-2.02.166-1.el7.x86_64 : Userland logical volume management tools
Repo        : base
Matched from:
Filename    : /usr/sbin/vgscan



7:lvm2-2.02.166-1.el7_3.1.x86_64 : Userland logical volume management tools
Repo        : updates
Matched from:
Filename    : /usr/sbin/vgscan

Another good thing about  yum provides is that it will also search for files. For example if you have a file on your system that you would like to match to a specific package or service  yum can get that information for you. For example you might not be sure which package installed the file /etc/sysconfig/authconfig  yum provides can get that information for you.

sudo yum provides /etc/sysconfig/authconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: repo1.sea.innoscale.net
 * epel: mirror.cogentco.com
 * extras: mirror.cisp.com
 * nux-dextop: mirror.li.nux.ro
 * updates: ftp.linux.ncsu.edu
authconfig-6.2.8-14.el7.x86_64 : Command line tool for setting up authentication from network
                               : services
Repo        : base
Matched from:
Filename    : /etc/sysconfig/authconfig



authconfig-6.2.8-14.el7.x86_64 : Command line tool for setting up authentication from network
                               : services
Repo        : installed
Matched from:
Filename    : /etc/sysconfig/authconfig



authconfig-6.2.8-10.el7.x86_64 : Command line tool for setting up authentication from network
                               : services
Repo        : @base
Matched from:
Filename    : /etc/sysconfig/authconfig

 


Ubuntu

With Ubuntu 14.04 and up you don’t need to run a special command to find a program. For instance if you try to run the command  sar without having first installed sysstat you will see the following message:

luke@test-srv01:~$ sar
The program 'sar' can be found in the following packages:
 * sysstat
 * atsar
Try: sudo apt-get install <selected package>

It even tells you how to install the packages you need at the end of the message. Assuming you read the error messages you get when something doesn’t work…. Some of us may or may not be guilty of neglecting to pay attention to error messages.

OpenSUSE/Suse Enterprise Linux – cnf

Similar to Ubuntu running a command that doesn’t exist on your system will provide a suggestion to find the command you need.

luke@test-srv02:~> sar
If 'sar' is not a typo you can use command-not-found to lookup the package that contains it, like this:
    cnf sar

OpenSUSE suggests that we run another command (cnf) to find our package.

luke@test-srv02:~> cnf sar
                   
The program 'sar' can be found in the following package:
  * sysstat [ path: /usr/bin/sar, repository: zypp (SMT-http_smt-ec2_susecloud_net:SLES12-SP2-Pool) ]

Try installing with:
    sudo zypper install sysstat

Suse like Ubuntu gives us a suggestion to install sysstat and even provides the full command to get it. A simple copy and paste should be enough to get the package you want and get back to work.