How to check an hard drive health in Linux using smartctl

The smartmontools package is generally available in the default repositories of all the major Linux distributions. It contains two utilities useful to check the status of storage with S.M.A.R.T support (Self Monitoring Analysis and Reporting Technology): smartcl and smartd.

The former is the utility we use directly to check S.M.A.R.T attributes, run tests, or perform other actions; the latter is the daemon which can be used to schedule operations in the background.

Tu install smartmontools use command:

sudo apt install smartmontools

Checking if SMART is enabled

Let’s become familiar with the smartctl utility. The first thing we want to check is if S.M.A.R.T support is active on the device. To perform this operation we can run the smartctl utility with the -i option (short for –info):

sudo smartctl -i /dev/sda

If SMART support is disabled we need to enable it:

sudo smartctl -s on /dev/sda

Getting S.M.A.R.T information with smartctl

To get information about hard drive /dev/sda use command:

sudo smartctl -a /dev/sda

Very important parameters to check are, among the others, “Reallocated_Sector_Ct” and “Current_Pending_Sector”. In both cases if the RAW_VALUE is something other than 0, we should be very careful and start to backup data on the hard drive. The Reallocated_Sector_Ct is the count of sectors on the block device which cannot be used correctly.

When such a sector is found it is remapped to one of the available spare sectors of the storage device, and data contained in it is relocated. The Current_Pending_Sector attribute, instead, is the count of bad sectors that are still waiting to be remapped. If you want to know more about the S.M.A.R.T attributes and their meaning, you can begin to take a look at the Wikipedia S.M.A.R.T page.

Change VGA resolution in Linux

1.First create modeline with your resolution

cvt 1680 1050

This will create modeline for resolution of 1600×900 which will look something like this:

1680x1050 59.95 Hz (CVT 1.76MA) hsync: 65.29 kHz; pclk: 146.25 MHz
Modeline "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync

2. To add this resolution to monitor settings, type the following command:

xrandr --newmode "1680x1050_60.00" 146.25 1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync

3. Next show your monitors list and find name of your monitor (VGA-1)

xrandr --listmonitors

3. And next write this command:

xrandr --addmode VGA-1 "1680x1050_60.00"

4. In Linux Mint, xorg.conf is not present by default and has to be created. This can be created only when x server is not working ie.  in console mode otherwise system will give error. Type these highlighted commands one by one in console mode:

Alt+Ctrl+F1 (switch to console mode)

sudo service lightdm stop (For Mint 12 Lisa users)

or

sudo service mdm stop (For Mint 13 Maya users)
sudo X -configure (generates new xorg.conf file)

5. To switch back to graphical mode, type:

sudo start lightdm (Mint 12 Lisa users)
sudo service mdm start (Mint 13 Maya users)

If above commands fail to bring back graphical mode, just restart your computer.

How to install zsh on Debian, Ubuntu or Linux Mint

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

To install Zsh on Debian, Ubuntu or Linux Mint use command:

sudo apt install zsh

Next install “Oh My Zsh” – delightful, open source, community-driven framework for managing your Zsh configuration. Use command:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

If you want to change zsh theme go to: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes

In order to enable a theme, set ZSH_THEME to the name of the theme in your ~/.zshrc

nano ~/.zshrc

Some themes need custom fonts, install it from git: https://github.com/powerline/fonts

git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
./install.sh

KDE change application launcher

1. Download new application launcher from site: https://store.kde.org/browse?cat=398&ord=latest

2. Run command:

plasmapkg2 --install LauncherName.tar.gz

If you want to upgrade launcher to new version use command:

plasmapkg2 --upgrade LauncherName.tar.gz

3. Right click on Start Menu icon > Show alternatives > Select LauncherName

If you want to uninstall launcher use command:

plasmapkg2 --remove LauncherName.tar.gz

Setup Proxmox cluster

1. First download official ISO image from Proxmox website: https://www.proxmox.com/

2. Write ISO image to USB flash drive using program Etcher: https://www.balena.io/etcher/

3. Boot PC from USB drive and install Proxmox. If you have two hard drives you can use ZFS file system to create RAID array.

Now log in to Proxmox admin panel using Web-browser: https://server-ip-address:8006

After installation we need to upgrade our system. Proxmox based on Debian GNU Linus and it use Debian repositories but in free version of Proxmox we will have an error when we try to upgrade. We need to disable enterprise Proxmox repositories. Open file /etc/apt/sources.list.d/pve-enterprise.list and comment with symbol # first line with enterprise Proxmox repository.

nano /etc/apt/sources.list.d/pve-enterprise.list

Then we can update packages list and upgrade our system:

apt update
apt upgrade

After installation let’s configure Local storage.

In admin panel go to Datacenter -> Storage, select local-lvm storage and click Remove

After that go to your Node -> Shell and write next commands:

lvremove /dev/pve/data
lvresize -l +100%FREE /dev/pve/root

And the last command to resize our local storage to 100% is:

resize2fs /dev/mapper/pve-root

Done, now we can use 100% of local storage, installed in our server. If you click on local storage you can see entire size of hard drive.

To remove the “You do not have a valid subscription for this server” popup message while logging in, run the command bellow:

sed -Ezi.bak "s/(Ext.Msg.show\(\{\s+title: gettext\('No valid sub)/void\(\{ \/\/\1/g" /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js && systemctl restart pveproxy.service

Restore MySQL database from files

If you have MySQL database files and you want to restore database on new server do next steps:

1. Stop MySQL server:

systemctl stop mysql

2. Copy all files of database to /var/lib/mysql directory;

3. Also copy files:

/var/lib/mysql/ibdata1
/var/lib/mysql/ib_logfile0
/var/lib/mysql/ib_logfile1

4. Change user and group of all files in directory /var/lib/mysql to mysql:mysql:

chown -R mysql:mysql .

5. Change permission of files in directory /var/lib/mysql to 660

find . -type f -print0 | xargs -0 chmod 660

6. Start MySQL server:

systemctl start mysql

To restore database from SQL dump use command:

mysql -u [user] -p [database_name] < [filename].sql

How to add directory to PATH in Linux

The $PATH environment variable is a list of directories that tells the shell which directories to search for executable files.

To check what directories are in your $PATH list use command:

echo $PATH

To add new directory ~/.local/bin/ to $PATH use command:

export PATH="$HOME/.local/bin:$PATH"

But this change is only temporary and valid only in the current shell session.

To make the change permanent, you need to define the $PATH variable in the shell configuration files. In most Linux distributions when you start a new session, environment variables are read from the following files:

  • Global shell specific configuration files such as /etc/environment and /etc/profile. Use this file if you want the new directory to be added to all system users $PATH.
  • Per-user shell specific configuration files. For example, if you are using Bash, you can set the $PATH variable in the ~/.bashrc file. If you are using Zsh the file name is ~/.zshrc.

In this example, we’ll set the variable in the ~/.bashrc file. Open the file with your text editor and add the following line at the end of it:

nano ~/.bashrc

export PATH="$HOME/.local/bin:$PATH"

Save the file and load the new $PATH into the current shell session using the source command:

source ~/.bashrc

To confirm that the directory was successfully added, print the value of your $PATH by typing:

echo $PATH

How to auto start program in Linux with root privilegies

To run some script or program when computer start in linux – copy this program to /etc/init.d directory. Change permissions to 755.

For example let’s create simple bash script “ntpsync“that sync system clock with NTP server in Internet:

service ntp stop
ntpdate time.nist.gov
service ntp start

Copy this sctipt to /etc/init.d, create symbolic link to /etc/rc3.d:

ln -s /etc/init.d/ntpsync /etc/rc3.d/ntpsync

Rc3 level – Мulti-user regime width network support.

That’s all, on next startup Linux will run this script, and automatically sync system clock with NTP server from Internet.