How to Save Command Output to a File in Linux

There are many things you can do with the output of a command in Linux. You can assign the output of a command to a variable, send it to another command/program for processing through a pipe or redirect it to a file for further analysis.

Suggested Read: Learn The Basics of How Linux I/O (Input/Output) Redirection Works

In this short article, I will show you a simple but useful command-line trick: how to view output of a command on the screen and also write to a file in Linux.

Viewing Output On Screen and also Writing to a File

Assuming you want to get a full summary of available and used disk space of a file system on a Linux system, you can employ the df command; it also helps you determine the file system type on a partition.

$ $df
Check Filesystem Disk Space

Check Filesystem Disk Space

With the -h flag, you can show the file system disk space statistics in a “human readable” format (displays statistics details in bytes, mega bytes and gigabyte).

$ df -h
Disk Space in Human Readable Format

Disk Space in Human Readable Format


Now to display the above information on the screen and also write it to a file, say for later analysis and/or send to a system administrator via email, run the command below.

$ df -h | tee df.log
$ cat df.log
Linux Command Output to File

Linux Command Output to File

Here, the magic is done by the tee command, it reads from standard input and writes to standard output as well as files.

If a file(s) already exists, you can append it using the -a or --append option like this.

$ df -h | tee -a df.log 

Note: You can also use pydf an alternative “df” command to check disk usage in different colors.

For more information, read through the df and tee man pages.

$ man df
$ man tee

You may also like to read similar articles.

  1. 5 Interesting Command Line Tips and Tricks in Linux
  2. 10 Useful Linux Command Line Tricks for Newbies
  3. 10 Interesting Linux Command Line Tricks and Tips Worth Knowing
  4. How to Run or Repeat a Linux Command Every X Seconds Forever
  5. Set Date and Time for Each Command You Execute in Bash History

In this short article, I showed you how to view output of a command on the screen and also write to a file in Linux. If you have any questions or additional ideas to share, do that via the comment section below.

How to Install Nginx on CentOS 7

NGINX (short for Engine X) is a free, open-source and powerful HTTP web server and reverse proxy with an event-driven (asynchronous) architecture. It is written using C programming language and runs on Unix-like operating systems as well as Windows OS.

It also works as a reverse proxy, standard mail and TCP/UDP proxy server, and can additionally be configured as a load balancer. It is powering many sites on the web; well known for its high-performance, stability and feature-rich set.

Read Also: How to Install Apache on CentOS 7

In this article, we will explain how to install, configure and manage Nginx HTTP web server on a CentOS 7 or RHEL 7 server using command line.

Prerequisites:

  1. A CentOS 7 Server Minimal Install
  2. A RHEL 7 Server Minimal Install
  3. A CentOS/RHEL 7 system with static IP address

Install Nginx Web Server


1. First update the system software packages to the latest version.

# yum -y update

2. Next, install Nginx HTTP server from the EPEL repository using the YUM package manager as follows.

# yum install epel-release
# yum install nginx 
Install Nginx on CentOS 7

Install Nginx on CentOS 7

Manage Nginx HTTP Server on CentOS 7

3. Once Nginx web server installed, you can start it first time and enable it to start automatically at system boot.

# systemctl start nginx
# systemctl enable nginx
# systemctl status nginx
Start and Enable Nginx at Boot

Start and Enable Nginx at Boot

Configure firewalld to Allow Nginx Traffic

4. By default, CentOS 7 built-in firewall is set to block Nginx traffic. To allow web traffic on Nginx, update the system firewall rules to permit inbound packets on HTTP and HTTPS using the commands below.

# firewall-cmd --zone=public --permanent --add-service=http
# firewall-cmd --zone=public --permanent --add-service=https
# firewall-cmd --reload
Allow Nginx on Firewalld

Allow Nginx on Firewalld

Test Nginx Server on CentOS 7

5. Now you can verify Nginx server by going to the following URL, a default nginx page will be shown.

http://SERVER_DOMAIN_NAME_OR_IP 
Test Nginx Installation

Test Nginx Installation

Nginx Important Files and Directories

  • The default server root directory (top level directory containing configuration files): /etc/nginx.
  • The main Nginx configuration file: /etc/nginx/nginx.conf.
  • Server block (virtual hosts) configurations can be added in: /etc/nginx/conf.d.
  • The default server document root directory (contains web files): /usr/share/nginx/html.

You may also like to read these following Nginx web server related articles.

  1. How to Setup Name-based and IP-based Virtual Hosts (Server Blocks) with NGINX
  2. The Ultimate Guide to Secure, Harden and Improve Performance of Nginx Web Server
  3. How to Install Varnish Cache 5.1 for Nginx on CentOS 7
  4. Install Latest Nginx 1.10.1, MariaDB 10 and PHP 5.5/5.6 on CentOS 7

In this article, we showed how to install and manage Nginx HTTP server from the command line on CentOS 7. You can ask questions or give us any feedback via the comment form below.

28 Things to Do After Fresh Installation of Fedora 26 Workstation

If you are a Fedora fan, I’m sure that you know that Fedora 26 has been released and we are closely following it ever since, Fedora 26 came with many new changes that you can view in their official release announcement page.

In this guide, we will show you some useful tips on what to do after installing Fedora 26 Workstation to make it even better.

1. Update Fedora 26 Packages

Even though you might have just installed/upgraded Fedora, there will most probably be packages available for update. After all Fedora is the one to always use the latest releases of each software it has and package updates are released quite often.

To run the update, use the following command:

# dnf update
Fedora 26 Update

Fedora 26 Update

2. Set Hostname in Fedora 26


We will use hostnamectl command, which is used to query and set system hostname and related settings. This tool is used to manage three different hostnames classes and they are: static, pretty, and transient.

The static host name is the universal hostname, which can be selected by the system user, and is saved in the /etc/hostname file.

Here, we will not going to discuss much about pretty, and transient hostnames classes, our main motive is to set system hostname, so here we go…

First list the current hostname using the following command:

# hostnamectl status
Sample Output
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 458842014b6c41f9b4aadcc8db4a2f4f
Boot ID: 7ac08b56d02a4cb4a5c5b3fdd30a12e0
Virtualization: oracle
Operating System: Fedora 26 (Twenty Six)
CPE OS Name: cpe:/o:fedoraproject:fedora:26
Kernel: Linux 4.11.8-300.fc26.x86_64
Architecture: x86-64

Now change Hostname as:

# hostnamectl set-hostname --static “tecmint.com”

Important: It is necessary to reboot your system for the changes to be taken into effect. After reboot, make sure to check the host name similarly as we did above.

Set Hostname in Fedora

Set Hostname in Fedora

3. Set Static IP Address in Fedora 26

To set system static IP address, you need to open and edit your network configuration file called enp0s3 or eth0 under /etc/sysconfig/network-scripts/ directory.

Open this file with the choice of your editor.

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
Sample Output
HWADDR=08:00:27:33:01:2D
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=1930cdde-4ff4-4543-baef-036e25d021ef
ONBOOT=yes

Now make the changes as suggested below and save the file..

BOOTPROTO="static"
ONBOOT="yes"
IPADDR=192.168.0.102
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=202.88.131.90
DNS2=202.88.131.89

Important: Make sure to replace network configuration in the above file with your own network settings.

After making above changes, make sure to restart the network service to take new changes into effect and verify the IP address and network settings with the help of following commands.

# service network restart
# ifconfig
Set IP Address in Fedora

Set IP Address in Fedora

4. Install Gnome Tweak Tool

Fedora 26 uses Gnome 3.24 which is the latest version of the gnome-shell desktop environment. To change some of it’s settings, you can install the Gnome Tweak Tool.

This tool allows you to change the Gnome-shell settings like:

  • Appearance
  • Desktop decoration
  • Easily install extensions
  • Top bar
  • Workspaces
  • Windows

To install Gnome Tweak Tool click on “Activities” menu on the top left and search for “Software“. In the software manager, search for “Gnome Tweak Tool” and in the list of results click on the “Install” button or install from the commandline.

# dnf install gnome-tweak-tool
Gnome Tweak Tool

Gnome Tweak Tool

5. Install Gnome Shell extensions

The Gnome Shell desktop environment can be modified even further and you can tweak it to your needs, by installing Gnome Shell Extensions. This can be easily done from the official website for Gnome Shell Extensions at gnome.org:

  1. https://extensions.gnome.org/

Installation of new modules is simple. Simply open the page for the extension you wish to have installed and use the on/off switch to activate/deactivate a Gnome Shell extension on your system:

Gnome Shell Extensions

Gnome Shell Extensions

6. Install Google Chrome

Google Chrome is a web browser, developed by Google. It’s a lightweight, modern browser designed to improve browsing experience. You can also install Google Chrome extensions to make Chrome even better.

To download the latest version of Google Chrome go to:

  1. https://www.google.com/chrome/browser/desktop/

From that page, download the “rpm” package that’s designed for your OS architecture (32/64 bit). Once the download is complete, double click the downloaded file and click “install” button to complete the installation.

Install Google Chrome

Install Google Chrome

7. Activate RPMFusion repo

The RPMFusion provides some free and non-free software for Fedora. The repo can be used via the command line. The repository is meant to provide stable and tested packages for Fedora so it is highly recommended to activate it on your system with:

# rpm -ivh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-26.noarch.rpm
Install RPM Fusion on Fedora

Install RPM Fusion on Fedora

8. Install VLC Media Player

VLC is a multi-platform media player that supports nearly every video format available. It’s one of the best in it’s category and if you like watching movies or listening to music we encourage you to install it.

The VLC package is included in the RPMFusion repository that was enabled in point 7. To complete the installation of VLC open new terminal and submit the following command:

# dnf install vlc

9. Install DropBox

DropBox is a famous Cloud storage service that can be used on multiple platforms. It can be used to store or backup your files on the cloud and access them from everywhere.

You can install Dropbox on your PC, tablet or smartphone and have your files accessed. To install a DropBox desktop client in Fedora 26 go to Dropbox’s website and download the Fedora package in accordance to your OS architecture (32/64 bit):

  1. Download DropBox package

When the download completes, find the downloaded file and click on “Install” button to complete the installation.

10. Install Mozilla Thunderbird

Fedora comes with pre-installed “Evolution” mail client. It’s good for reading mails, but if you need to have a more organized to read and keep your emails, Mozilla Thunderbird is the right choice for you.

To install Mozilla Thunderbird, open the Fedora software manager and search for “Thunderbird“. After that click the “Install” button next to the package.

11. Enable Google Repository

Google provides its own repository from where you can install Google software such as Google Earth, Google Music manager and others. To add Google’s repo to your Fedora installation, use the following commands:

# gedit /etc/yum.repos.d/google-chrome.repo

Now copy/paste the following code and save the file:

[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

12. Install Docky

Docky is a simple, attractive and productive dock used on many different Linux distribution. Docky doesn’t use much system resources and yet it improves your productivity while looking good on your screen. If you want to have a good looking dock such as Docky, use the following commands:

# dnf install docky

13. Install other Desktop Environments

If you are not big fan of Gnome shell, we have some good news for you. You can install different desktop environments on your Fedora workstation. To complete the install, you will need to run the commands below in a terminal. Only run the command that is related to the desktop environment that you wish to use:

Install Mate Desktop

# dnf install @mate-desktop

Install KDE Desktop

# dnf install @kde-desktop

Install XFCE Desktop

# dnf install @xfce-desktop

LXDE Desktop

# dnf install @lxde-desktop

Install Cinnamon Desktop

# dnf install @cinnamon-desktop

14. Install rar and zip utilities

Often we use archives in our daily routines. Extracting some of the archives require proper tools to be installed. To deal with .rar and .zip type of compressed files, you can install the required utilities with this command:

# dnf install unzip 

15. Install Java Plugins for web

Java is a programming language which many websites use to display different type of data. To be able to load such type of websites, you will need the JAVA plugins for web. They can be easily installed by running the following command in a terminal:

# dnf install icedtea-web java-openjdk

16. Install GIMP

GIMP is a small, yet powerful image manipulation software. You can use GIMP to edit your images or in a paint like style. Either way this is a useful tool, that you will want in your collection of programs.

To install GIMP simply run:

# dnf install gimp

17. Install Pidgin

Pidgin is a chat client that supports multiple social accounts. You can use it to easily interact with your friends, family or co-workers. The installation of Pidgin in Fedora is fairly easy and can be completed with the following command:

# dnf install pidgin

18. Install qbittorrent

Torrent trackers are gaining more and more popularity in the last few years. Thanks to torrents, you can download important files with a very good speed as long as there are enough seeders.

To download such files, you will need a torrent client software. This is why we recommend qBittorrent. It’s an advanced torrent client with friendly interface.

You can install it by launching the “Software” manager from your Gnome dashboard. Within the software manager, search for “qbittorrent“. Once you have found the package, click the “Install” button next to that package:

Alternatively, you can install qbittorrent with the following command executed in a terminal:

# dnf install qbittorrent

Here is how the qBittorent interface looks like:

Qbittorent Preview

Qbittorent Preview

19. Install VirtualBox

Virtualbox is a software through which you can test different operating systems on your computer, without having to re-install your OS itself.

To install VirtualBox on your Fedora you must have the RPMFusion repository enabled (see point 7). Then you can install VirtualBox with the following command:

# dnf install VirtualBox

20. Install Steam

If you like playing games on your Fedora then Steam is for you! It has many different games included in it that can be ran on different platforms including Linux.

In a simple words it’s a game store where you can download games for your Fedora system and play them after that. To install Steam on your Fedora installation run the following commands:

# dnf config-manager --add-repo=http://negativo17.org/repos/fedora-steam.repo
# dnf -y install steam

After that you can launch steam from the Gnome-shell dash.

Read Also: Best Linux Games of 2015

21. Install Spotify

I think you all know what Spotify is. It’s currently the best service for music streaming on all your devices. The official client for Spotify on Linux boxes is meant for Debian/Ubuntu derivatives.

The fedora package reassembles the Ubuntu package and moves all the files in the required places. So to install Spotify client on your Fedora installation, you will need to use the following commands:

# dnf config-manager --add-repo=http://negativo17.org/repos/fedora-spotify.repo
# dnf install spotify-client

22. Install Wine

Wine is a software meant to help you run Windows applications under Linux. While not all applications may run is expected, this is a useful tool if you need to run a Windows program under Fedora.

To complete the install of Wine, run the following command in your terminal:

# dnf install wine

23. Install Youtube-DL

Youttube-DL is a python based tool that allows you to download videos from sites such as YouTube.com Dailymotion, Google Video, Photobucket, Facebook, Yahoo, Metacafe, Depositfiles.

If you are interested in such tool and like to have some videos for offline watching, then you can install this tool by running:

# dnf install youtube-dl

For complete guide how to use this tool, please check our guide:

  1. How to Install and Use Youtube-DL in Linux

24. Install Simple Scan

Simple scan enables to easily capture scanned documents, it is simple and easy to use as the name states. It is useful especially for those using Fedora 24 and Fedora 25 workstation in an small home office. You can find it in Software manager application.

# dnf install simple-scan

25. Install Fedora Media Writer

Fedora Media Writer is the default application provided by Fedora for creating live USB or bootable images. Unlike most image writers, Fedora Media Writer can download images (Fedora Workstation and Fedora Server), but it limited to Fedora only, but also can able to write ISO for any distributions.

# dnf install mediawriter

26. Install GNOME Music Player

GNOME music is a relatively new music player that offers some of the best music player features and functionalities, more importantly, it is simple and easy to use.

# dnf install gnome-music

27. Add Online Accounts

Fedora enables you to access your online accounts directly on the system, you add them when you first login after fresh installation or go to Settings, under the Personal category, click on Online Accounts.

Online Accounts

Online Accounts

28 Learn DNF

Since Fedora 22 the default package manager has been replaced with “DNF” which stands for Dandified yum (yum was the old package manager). If you haven’t got familiar with that package manager yet, then now is the time to read our extensive guide here:

  1. 27 DNF Commands to Manage Packages in Fedora

Conclusion

The above points should be enough to add some flavour to your Fedora Workstation without having too much bloatware. If you think we have missed something or would like us to add further explanation, please use the comment section below.

How to Migrate Windows 10 from HDD to SSD Using Clonezilla

This tutorial represents a practical excerpt on how to migrate (also known as cloning) a Windows 10 Operating System from a large HDD with multiple partitions, such as C:, D:, to a smaller SSD using a Linux distribution which includes Clonezilla utility.

Clonezilla utility can run from PartedMagic Linux distribution CD ISO image or directly from Clonezilla Linux distribution CD ISO image.

This guide assumes that both disks (old HDD and SSD) are physically plugged-in into your machine simultaneously and Windows OS is installed on a disk with MBR partition scheme table. Fdisk command line utility should display the disklabel type as DOS.

Read Also: 8 Open Source Disk Cloning and Backup Solutions for Linux


If disk in partitioned in MBR layout from UEFI, you should clone all partitions, such as Windows RE partition, EFI System partition, Microsoft Reserved partition and Microsoft basic data partition which holds the Windows OS partition, typically the C: drive. In this case Fdisk command line utility should report the disklabel type as GPT.

On the below screenshots you can review the initial Windows partitioning scheme in case of a MBR layout style and GPT partition layout performed from UEFI.

MBR Partition Layout from Disk Management

Check MBR Partition Layout

Check MBR Partition Layout

GPT Partition Layout from Disk Management

Check MBR Partition Layout

Check MBR Partition Layout

Step 1: Shrink C: Partition of Windows System

Be aware that in the case your windows C: partition from the HDD is larger than the total size of your SSD you will need reduce its size to fit on the SSD.

The calculations for this step are simple:

System Reserved + Recovery + EFI partition + Windows C: partitions must be smaller or equal than the total size of the SSD reported by a utility such as fdisk.

1. To shrink C: partition from Windows, first open a Command Prompt window and execute the diskmgmt.msc to open Windows Disk Management utility which will be used to Shrink the volume (assuming that windows is installed at the beginning of the disk on the second partition, after the System Reserved partition and has C: letter assigned) in order to reduce its size to minimal.

Shrink C Partition

Shrink C Partition

Feel free to use other partitioning tools for this step, such as Gparted run from a live Linux ISO, to reduce C: drive size to minimal.

2. After you’ve reduced the size of C: partition, plug the SSD drive to your machine motherboard and reboot the machine into Clonezilla utility (use Clonezilla ISO image or <arel=”nofollow” href=”https://partedmagic.com/downloads/” target=”_blank”>Parted Magic ISO), enter to Bash shell interface and check both disks partition table and size using the below commands.

# fdisk -l /dev/sda
# fdisk -l /dev/sdb
Check Partition Table Size

Check Partition Table Size

Be aware that your drives names would be sda for the first disk, sdb for the second and so on. Choose the disk with maximum attention so you won’t end-up cloning the wrong device and destroy all data.

To match the correct disk source (HDD in this case) and disk destination target (SSD) use the size and the partition table reported by fdisk command. Fdisk output will show that the SSD should be smaller in size than your HDD disk and should have no partition table created by default.

In case of a GPT disk, the HDD partition table should look as illustrated on the below screenshot.

$ su -
# fdisk -l /dev/sda
# fdisk -l /dev/sdb
Check Partition Disk Label

Check Partition Disk Label

Step 2: Clone Disks Using Clonezilla

3. Next , clone only the MBR (stage one bootloader + partition table) from the HDD to the SSD target disk using one of the below commands (assuming that sda represents the drive where Windows OS is installed and sdb the SSD disk).

# dd if=/dev/sda of=/dev/sdb bs=512 count=1
or
# sfdisk -d /dev/sda | sfdisk -f /dev/sdb
Clone Disks Using Clonezilla

Clone Disks Using Clonezilla

In case of a GPT partition style you should clone the first 2048 bytes:

# dd if=/dev/sda of=/dev/sdb bs=2048 count=1

Or use sgdisk utility. Be aware that if you copy partition table from sda to sdb you should inverse the order of disks when using sgdisk.

# sgdisk -R /dev/sdb /dev/sda

After cloning the MBR/GPT, run fdisk command again with the -l flag to verify if the partition table matches on both disks.

# fdisk -l /dev/sda
# fdisk -l /dev/sdb
Verify Partition Table

Verify Partition Table

4. By now both drives should have the exact partition table. On the target disk now delete all the partitions that follow after the Windows partition in order to start with a clean partition table with the entries necessaries only for system reserved and windows.

You won’t clone data from D: (or other partitions that follow Windows) from the old drive. You’re basically cloning only the first two partitions from the old HDD. Later you will use this unallocated space left behind to extend the C: partition by incorporating all the unused space from SSD.

Use fdisk utility as described below to delete partitions. First run the command against your SSD target drive (/dev/sdb this case), print partition table with p key, press d key to start delete partitions and choose the last partition number from the prompt (in this case the third partition) as illustrated in the below screenshots.

# fdisk /dev/sdb
Delete Partition Table

Delete Partition Table

In case your drive has more than one partition following after the Windows partition, make sure you delete all of them. After you’ve finished removing all unneeded partitions, press p key again to print partition table and if, by now, only the two required Windows partitions are listed, you are safe to hit on w key in order to apply all changes.

Confirm Partition Changes

Confirm Partition Changes

The same procedure for deleting last partitions applies for GPT disks also, with the mention that you should use cgdisk utility which is intuitive to work with in manipulation a disk layout.

Don’t worry about destroying backed-up partition table at the end of the GPT disk, cgdisk will make the appropriate changes on both partition tables and will save the new disk layout table at the end of the disk automatically.

# cgdisk /dev/sdb
Delete GPT Partition

Delete GPT Partition

And the final GPT disk report with the last 4,9 GB partition deleted.

Verify GPT Partition Table

Verify GPT Partition Table

5. Now, if everything is in place, start Clonezilla utility, select device-device mode, run from beginner wizard and select part-to-local_part cloning option.

Use the below screenshots for guide.

Select Clonezilla Device Mode

Select Clonezilla Device Mode

Select Clonezilla Beginner Mode

Select Clonezilla Beginner Mode

Select Clonezilla Local Partition Clone

Select Clonezilla Local Partition Clone

6. Choose the first local partition from the list (sda1 – System Reserved ) as source and press Enter key to continue.

Select Partition to Clone

Select Partition to Clone

7. Next, choose the local target partition, which will be the first partition from the second disk, (/dev/sdb1) and press Enter key to continue.

Select Local Target Partition

Select Local Target Partition

8. On the next screen choose to Skip check/repair file system and press Enter key again to continue.

Skip Check Repair Filesystem

Skip Check Repair Filesystem

9. Finally, press Enter key again to Continue and answer with yes (y) twice to accept the warnings and start the cloning process.

Confirm Partition Changes

Confirm Partition Changes

Start Cloning Partition

Start Cloning Partition

10. After the cloning process of the first partition finishes select to enter command line prompt, run clonezilla and repeat the same steps for next partitions (source sda2 – target sdb2, etc).

Clone Second Partition

Clone Second Partition

11. After all windows partitions are cloned, reboot the system and physically unplug the HDD drive or, better, tamper BIOS settings in order to set SSD as primary boot drive instead of old HDD.

Step 3: Resize Windows Partition

12. You can run Gparted utility to check partitions sanity and extend windows partition from Linux or you can just boot into Windows and use Disk Management utility to do this job. The below screenshots illustrate how to use both utilities.

Extend Partition using Gparted Live CD

Resize Partition Using GParted

Resize Partition Using GParted

Resize Partition Size

Resize Partition Size

Extend Partition using Windows Disk Management utility directly from Windows.

Extend Windows Partition

Extend Windows Partition

Select Disk to Extend

Select Disk to Extend

That’s all! The C: partition is now expanded to the maximum size of your SSD and Windows can now run at its maximum speed on a brand new SSD. The old HDD has all data intact.

Connect the hard-disk again in order to use it in case you’ve physically removed it from the motherboard. You can delete system reserved partition and windows partition from the old HDD and create a new partition instead of these two. The other old partitions (D:, E: etc) will remain intact.

Conclusion

With Clonezilla you can also choose to image the partitions and save them to an external HDD or a network location. In this case you must also backup HDD MBR/GPT with one of the following commands and save the MBR image to the same directory where your clonezilla images are kept.

MBR backup to file:

# dd if=/dev/sda of=/path/to/MBR.img bs=512 count=1
or
# sfdisk -d /dev/sda > =/path/to/sda.MBR.txt

GPT Backup to file:

# dd if=/dev/sda of=/path/to/GPT.img bs=2048 count=1
or
# sgdisk --backup=/path/to/sda.MBR.txt /dev/sda

For a future restoration of your Windows system from a network location, first restore the MBR sector from the saved imaged above using one of the below commands, then proceed with restoring each clonezilla partition image one by one.

MBR image restore from file:

# dd if=/path/to/MBR.img of=/dev/sda bs=512 count=1
or
# sfdisk /dev/sda < =/path/to/sda.MBR.txt

GPT image restore from file:

# dd if=/path/to/GPT.img of=/dev/sda bs=2048 count=1
# sgdisk - -load-backup=/path/to/sda.MBR.txt /dev/sda

Read Also: How to Clone or Backup Linux Disk Using Clonezilla

This method has been used multiple times on BIOS motherboards and on UEFI machines with Windows installed from Legacy Mode (CSM) or directly from UEFI without any error or data loss.

CloudBerry Backup for Linux: Review and Installation

When it comes to backups, experience says it’s better to be safe than sorry. Better to have much than not enough – you get the point. In this article, we will present CloudBerry Backup for Linux, a cross-platform cloud backup and disaster recovery software.

As a leading solution in the industry, CloudBerry stands out for its flexibility, reliability, and its wide set of out-of-the-box features. You not only get to choose where to store your data (locally or using a cloud storage service), but also can encrypt it using AES-128 or AES-256.

With both a GUI and a command-line interface, optional compression to save up on bandwidth and decrease storage costs, and no hidden fees for data restore, CloudBerry is hard to beat!

And this is just the top of the iceberg. Believe me – creating, managing, and restoring backups has never been easier, not even in the cloud computing era. Keep reading to find out more!

Installing CloudBerry Backup for Linux


Although CloudBerry is a commercial product, it provides a full-featured trial version that you can use to test-drive the solution. Additionally, a freeware version for personal use (which provides most of the functionality of the Pro edition, except for data encryption) is also available.

Regardless of the version, licenses are one-time off (pay once, get a perpetual license) with an optional yearly maintenance fee that includes support and free upgrades during that period of time.

First, go the download section of Linux cloud backup and click Download. In the next page, choose the link that corresponds to your distribution.

In this article, we will be installing the solution on a CentOS 7 machine. The installation on other distributions is almost identical, so you should not run into any issues if you stick to this tutorial.

To begin, let’s click on the link for CentOS 6/7 and wait for the download to complete:

Download CloudBerry Backup for Linux

Download CloudBerry Backup for Linux

Once done, follow these steps to proceed with the installation of CloudBerry Backup for Linux:

1. Browse to the folder where the binary file was downloaded and double click on it. The following window will pop up. Click Install to continue.

Cloudberry Installation

Cloudberry Installation

When the installation is complete, Install will change to Remove, as you can see in the below image:

CloudBerry Installation Complete

CloudBerry Installation Complete

2. Open a terminal and enter the following commands to request the trial version. Note the pair of single quotes surrounding CloudBerry Backup:

# cd /opt/local/'CloudBerry Backup'/bin

Next, do

./cbb activateLicense -e "[email protected] " -t "ultimate"

If the above command returns Success, the trial version is ready to use. To launch it, go to the Internet section in your Applications and click CloudBerry Backup. Next, click Continue Trial and Finish to proceed:

CloudBerry Backup Trial Version

CloudBerry Backup Trial Version

Create a Backup Plan and Choose a Storage Provider

Once we have installed the solution and activated the trial version, we will proceed to set up a backup plan.

3. Here you will be able to select where you will store your data. As you can see, CloudBerry is well integrated with all the major cloud storage service providers.

As a Bring-Your-Own-Storage (BYOS) solution, it allows you to leverage any existing cloud services you may already be using.

Select CloudBerry Backup Storage

Select CloudBerry Backup Storage

Regardless of the chosen backup plan, we are assuming that you have already setup the authentication mechanism. In our case we will go with Azure, and once we have entered a display name of our choosing, one of the access keys to our storage account, the account name, and specified a container name, let’s click OK and Continue:

CloudBerry Backup Storage Account Details

CloudBerry Backup Storage Account Details

Next, choose a name for the current backup plan:

Choose CloudBerry Backup Name

Choose CloudBerry Backup Name

Now choose the files and folders you want to backup:

Select CloudBerry Backup Files

Select CloudBerry Backup Files

You will then be prompted to indicate the kind of files that you want to include or exclude from your backup. You can also enable All files as well, choose whether to use compression, and the kind of encryption that you want to use:

CloudBerry Backup Compression and Encryption

CloudBerry Backup Compression and Encryption

4. Choose a Retention Policy and a backup schedule that suits your needs. This will tell CloudBerry when and how to delete old backup files. If in doubt, go with the defaults:

CloudBerry Backup Retention Policy

CloudBerry Backup Retention Policy

For the backup schedule, you can choose to run it manually, on a specific date and time, or recurrently on a given frequency. The image below shows a schedule backup that will take place every Friday at 1 pm:

Schedule Cloudberry Backup

Schedule Cloudberry Backup

If you wish, you can enable notifications at this point. Note that you can specify a list of recipients separated by semicolons, modify the subject line, and choose to be notified in all cases or only when a backup fails:

Cloudberry Backup Notifications

Cloudberry Backup Notifications

5. Run the plan now to check if it works as expected:

Cloudberry Backup Summary

Cloudberry Backup Summary

The backup plan will then be executed. Depending on the size of the chosen files and folders, it may take a few minutes (or more) to fully synchronize with the remote storage account.

When the process is complete, a green checkmark will appear next to the backup plan in CloudBerry. Now let’s check our Azure container to ensure that our files are already there. And voilá! It’s not magic – it’s CloudBerry Backup for Linux:

Verify Cloudberry Backup Files

Verify Cloudberry Backup Files

Testing the CloudBerry Backup Restore Functionality

So far so good – on to testing we go!

6. Remove a file from the source (thinkcspy3_latest.zip). Click Restore in the CloudBerry Backup interface and choose the plan to restore from.

Since the steps to set up a restore plan are similar to setting up a backup plan, we will not go into detail – only summarize in the following image. Each step is self-explanatory. In #6, enter the password that you chose when you created the backup plan earlier:

Cloudberry Backup Restore

Cloudberry Backup Restore

After the restore plan is completed, you should see the file that you removed back in the source. Simple as that!

Summary

In this article, we have explained how to install CloudBerry Backup for Linux, and how to create a backup plan integrated with Microsoft Azure.

Additionally, we showed how easy it is to restore files from the remote storage account back to our machine. Additionally, if you prefer to use the command line to manage backup and restore plans, you can refer to the page of CloudBerry Backup command line interface for Linux.

Easy to install, and much easier to use – totally worth your time and a few bucks to buy a license, isn’t it?

As always, don’t hesitate to let us know if you have any questions or comments about this article. The feedback of our readers is always highly appreciated.

Install Varnish Cache 5.1 for Nginx on Debian and Ubuntu

Varnish Cache (also called Varnish) is an open source, HTTP accelerator which stores web pages in memory so web servers don’t have to create the same web page over and over again when requested by a client. You can configure Varnish to work in front of a web server to serve pages in a much faster way thus giving the websites a significant speed up.

In our last article, we have explained how to setup a Varnish Cache for Apache on a Debian and Ubuntu system.

In this article, we will explain how to install and configure Varnish Cache 5 as a front-end to Nginx HTTP server on a Debian and Ubuntu systems.

Requirements:

  1. A Ubuntu system installed with LEMP Stack
  2. A Debian system installed with LEMP Stack
  3. A Debian/Ubuntu system with static IP address

Step 1: Install Varnish Cache on Debian and Ubuntu

1. Unfortunately, there are no pre-compiled packages for latest version of Varnish Cache 5 (i.e 5.1.2 at the time of writing), so you need to build it from its source files as shown below.


Start by installing the dependencies for compiling it from source using the apt command like this.

$ sudo apt install python-docutils libedit-dev libpcre3-dev pkg-config automake libtool autoconf libncurses5-dev libncurses5

2. Now download Varnish and compile it from source as follows.

$ wget https://repo.varnish-cache.org/source/varnish-5.1.2.tar.gz
$ tar -zxvf varnish-5.1.2.tar.gz
$ cd varnish-5.1.2
$ sh autogen.sh
$ sh configure
$ make
$ sudo make install
$ sudo ldconfig

3. After compiling Varnish Cache from source, the main executable will be installed as /usr/local/sbin/varnishd. To confirm that the Varnish installation was successful, run the following command to see the its version.

$ /usr/local/sbin/varnishd -V
Verify Varnish Cache Version

Verify Varnish Cache Version

Step 2: Configure Nginx to Work With Varnish Cache

4. Now you need to configure Nginx to work with Varnish Cache. By default Nginx listens on port 80, you need change the default Nginx port to 8080 so it runs behind Varnish caching.

Therefore open the Nginx configuration file /etc/nginx/nginx.conf and find the line listen 80, then change it to listen 8080 as the server block as shown in the screen shot below.

$ sudo vi /etc/nginx/nginx.conf
Change Nginx Port

Change Nginx Port

5. Once port has been changed, you can restart Nginx services as follows.

$ sudo systemctl restart nginx

6. Now start Varnish daemon manually by typing following command instead of calling systemctl start varnish, since certain configurations are not in place when its installed from source:

$ sudo /usr/local/sbin/varnishd -a :80 -b localhost:8080
Start Varnish Cache Daemon

Start Varnish Cache Daemon

Step 3: Test Varnish Cache on Nginx

7. Finally, test if Varnish cache is enabled and working with the Nginx HTTP server using the cURL command below to view the HTTP header.

$ curl -I http://localhost
Test Varnish Cache on Nginx

Test Varnish Cache on Nginx

You can find additional information from the Varnish Cache Github Repository: https://github.com/varnishcache/varnish-cache

In this tutorial, we have showed how to setup Varnish Cache 5.1 for Nginx HTTP server on Debian and Ubuntu systems. You can share any thoughts or queries with us via the feedback from below.

Learn Full-Stack Web Development Course – Beginner to Expert

Full-stack web development is working on both the front-end and back-end parts of a website or web application. It covers building the user interface, server-side programming and database design/development.

This kind of web development is noticeably on the rise, and The Interactive Web Developer Bootcamp is here to guide you towards achieving your dream of becoming a professional full-stack web developer.

Whether you are an absolute beginner or simply want to polish your web development skills, this program has it all at a discount of 94% off on Tecmint Deals.

The training in this bootcamp focuses on full-stack web development using modern as well as popular tools such as HTML, CSS, JavaScript, jQuery, Ruby on Rails and well known frameworks like AngularJS plus so much more.


You will get access to 180+ top-rated HD training videos coupled with an assortment of best online resources to help you master the fundamentals and advanced concepts thus becoming an expert web developer. You will also have access to code exercises and a 20-page downloadable e-book.

You will begin by learning common syntax for web development languages such as HTML5 and CSS3, then practice by developing a simple blogging application. You’ll then advance to work on a complete end-to-end project with all the skills you acquired.

Furthermore, you will learn back-end development with popular languages including Ruby on Rails and Node.js. Under back-end development, you will learn how to implement critical features such as user authentication, email notifications and beyond.

Discover a high-paying, flexible new career path by mastering the ins and outs of full-stack web development with The Interactive Web Developer Bootcamp. This program is designed for absolute beginners or persons who wish to advance their web development skills.

Join it today at 94% off or for as low as $29 on Tecmint Deals.

How to Fix Yum Error: Database Disk Image is Malformed

In this article, we will briefly describe YUM, YumDB, then the cause of Yum Error: database disk image is malformed and how to fix this error.

YUM (Yellowdog Updater, Modified) is the default, high-level tool for Linux package management on RPM (RedHat Package Manager) based Linux distributions such as Red Hat Enterprise Linux (RHEL), CentOS as well as older versions of Fedora Linux, just to mention but a few.

It works just like apt-get command or the relatively new apt command; it can be used to install new packages, remove old packages and query installed and/or available packages. It can also be used to update a system (together with dependency resolution and obsolete processing depending on stored repository metadata).

Note: This guide will assume you are controlling your system as root, otherwise use the sudo command to run all the commands below. Interestingly, you can also run sudo command without entering a password; did you know that, okay, let’s continue.

Brief Understanding of YumDB


Starting from version 3.2.26, yum stores supplementary information concerning installed packages in a location outside of the generic rpmdatabase; in a simple flat file database called yumdb (/var/lib/yum/yumdb/) – not a real database.

# cd /var/lib/yum/yumdb
# ls 
View Yum Database

View Yum Database

You can check out one of the sub-directories to find out more about yumdb as follows.

# cd b
# ls
Check Yum Package Information

Check Yum Package Information

Although this information is not of great significance to yum processes, it is very useful to the system administrators: it clearly describes the context in which a package was installed on the system.

If you tried looking through the files (from_repo, installed_by, releasever etc..) shown in the screen shot above, you would probably see nothing important in them.

To access the information in them, you must install yum-utils which provides a script called yumdb – then use this script as explained below.

# yum install yum-utils 

The following command will get the repo from which httpd was installed.

# yumdb get from_repo httpd
Check Package Installed Repo

Check Package Installed Repo

To define a note on the packages httpd and mariadb, type.

# yumdb set note "installed by aaronkilik to setup LAMP" httpd mariadb
Set Note on Installed Packages

Set Note on Installed Packages

And to vew all yumdb values concerning httpd and mariadb, type.

# yumdb info httpd mariadb
Find Information of Installed Packages

Find Information of Installed Packages

Fix Yum Error: database disk image is malformed

Occasionally while installing a package or updating your system using YUM, you may encounter the error: “database disk image is malformed”. It may result from a corrupted yumdb: possibly caused by an impediment of the “yum update” process or package installation.

To fix this error, you need to clean database cache by running the command below.

# yum clean dbcache 
Yum Clean Database Cache

Yum Clean Database Cache

If the above command fails to work (fix the error), try running the series of commands below.

# yum clean all #delete entries in /var/cache/yum/ directory.
# yum clean metadata #clear XML metadeta # yum clean dbcache #clear the cached files for database
# yum makecache #make cache
Clear All Yum DB Cache and Metadata

Clear All Yum DB Cache and Metadata

Finally, you must rebuild your system’s RPM database for it to work.

# mv /var/lib/rpm/__db* /tmp
# rpm --rebuilddb
Rebuild RPM Database

Rebuild RPM Database

If you have followed the above instructions well, then the error should be resolved by now. Then try to update your system as follows.

# yum update 

You may also check out these important articles concerning yum and other Linux package managers:

  1. How to Use ‘Yum History’ to Find Out Installed or Removed Packages Info
  2. 27 ‘DNF’ (Fork of Yum) Commands for RPM Package Management in Linux
  3. What is APT and Aptitude? and What’s real Difference Between Them?
  4. How to Use ‘apt-fast’ to Speed Up apt-get/apt Package Downloads Using Multiple Mirrors

Do you have any queries or ideas to share concerning this topic, use the comment section below to do that.

Integrate VMware ESXI to Samba4 AD Domain Controller – Part 16

This guide will describe how to integrate a VMware ESXI host into a Samba4 Active Directory Domain Controller in order to authenticate in VMware vSphere Hypervisors across network infrastructure with accounts provided by a single centralized database.

Requirements

  1. Create an Active Directory Infrastructure with Samba4 on Ubuntu

Step 1: Configure VMware ESXI Network for Samba4 AD DC

1. Preliminary steps before joining a VMware ESXI to a Samba4 require that the hypervisor has the proper Samba4 AD IP addresses configured in order to query the domain via DNS service.

To accomplish this step from VMware ESXI direct console, reboot the hypervisor, press F2 to open the direct console (also called DCUI) and authenticate with the root credentials assigned for the host.

Then, using the keyboard arrows navigate to Configure Management Network -> DNS Configuration and add the IP addresses of your Samba4 Domain Controllers in Primary and Alternate DNS Server fields.


Also, configure the hostname for the hypervisor with a descriptive name and press [Enter] to apply changes. Use the below screenshots as a guide.

VMware ESXI Console

VMware ESXI Console

VMware ESXI DNS Configuration

VMware ESXI DNS Configuration

VMware ESXI Set Hostname

VMware ESXI Set Hostname

2. Next, go to Custom DNS Suffixes, add the name of your domain and press [Enter] key to write changes and return to main menu.

Then, go to Restart Management Network and press [Enter] key restart the network service in order to apply all changes made so far.

VMware ESXI Custom DNS Suffix

VMware ESXI Custom DNS Suffix

VMware ESXI Network Management

VMware ESXI Network Management

3. Finally, make sure that gateway and Samba DNS IPs are reachable from the hypervisor and test if the DNS resolution works as expected by selecting Test Management Network from the menu.

VMware ESXI Test Management Network

VMware ESXI Test Management Network

Test Samba DNS IP

Test Samba DNS IP

Confirm Samba DNS IP

Confirm Samba DNS IP

Step 2: Join VMware ESXI to Samba4 AD DC

4. All the steps performed from now on will be made through the VMware vSphere Client. Open VMware vSphere Client and login to your hypervisor IP address with the default root account credentials or with other account with root privileges on the hypervisor if that’s the case.

VMware vSphere Client

VMware vSphere Client

5. Once you’ve entered the vSphere console, before actually joining to the domain, make sure that the hypervisor’s time is in sync with Samba domain controllers.

To accomplish this, navigate to the upper menu and hit on Configuration tab. Then, go to left box Software -> Time Configuration and hit Properties button from upper right plane and the Time Configuration window should open as illustrated below.

VMware vSphere Client Time Configuration

VMware vSphere Client Time Configuration

6. On Time Configuration window hit on Options button, navigate to NTP Settings and add the IP addresses of your domain time providers (usually the IP addresses of your Samba domain controllers).

Then go to General menu and start the NTP daemon and choose to start and stop the NTP service with the hypervisor as illustrated below. Press OK button to apply changes and close both windows.

Add NTP Server IP

Add NTP Server IP

Manage NTP Service

Manage NTP Service

7. Now you can join VMware ESXI hypervisor to Samba domain. Open Directory Services Configuration window by hitting on Configuration -> Authentication Services –> Properties.

From the window prompt select Active Directory as Directory Service Type, write the name of your domain with uppercase click on Join Domain button to perform the domain binding.

On the new prompt you will be asked to add the credentials of a domain account with elevated privileges to perform the joining. Add the username and password of a domain account with administrative privileges and hit Join Domain button to integrate into the realm and OK button to close the window.

Join VMware ESXI Hypervisor to Samba

Join VMware ESXI Hypervisor to Samba

Directory Services Configuration

Directory Services Configuration

8. In order to verify if the ESXI hypervisor has been integrated to Samba4 AD DC, open AD Users and Computers from a Windows machine with RSAT tools installed and navigate to your domain Computers container.

The hostname of VMware ESXI machine should be listed on the right plane as illustrated below.

AD Users and Computers

AD Users and Computers

Step 3: Assign Permissions for Domain Accounts to ESXI Hypervisor

9. In order to manipulate different aspects and services of the VMware hypervisor you might want to assign certain permissions and roles for domain accounts in VMware ESXI host.

To add permissions hit on upper Permissions tab, right-click anywhere in the permissions plane and choose Add Permission from the menu.

Assign Permissions for Domain Accounts

Assign Permissions for Domain Accounts

10. In the Assign Permissions window hit on the below left Add button, select your domain and type the name of a domain account in search filed.

Choose the proper username from the list and hit Add button to add the account. Repeat the step if you want to add other domain users or groups. When you finish adding the domain users hit OK button to close the window and return previous setting.

Assign Permissions

Assign Permissions

Select Users and Groups

Select Users and Groups

11. To assign a role for a domain account, select the desired name from the left plane and choose a predefined role, such as Read-only or Administrator from the right plane.

Check the proper privileges you want to grant for this user and hit OK when you finish in order to reflect changes.

Assign Admin User for Domain

Assign Admin User for Domain

12. That’s all! The authentication process in VMware ESXI hypervisor from VSphere Client with a Samba domain account is pretty straightforward now.

Just add the username and the password of a domain account in the login screen as shown in the below picture. Depending on level of permissions grated for the domain account you should be able to manage the hypervisor completely or just some parts of it.

VMware vSphere Client Login

VMware vSphere Client Login

Although this tutorial mainly included only the steps required to join a VMware ESXI hypervisor into a Samba4 AD DC, the same procedure as described in this tutorial applies for integrating a VMware ESXI host into a Microsoft Windows Server 2012/2016 realm.

Learn Artificial Intelligence with 10-Course Machine Learning Bundle

Machine learning is a kind of Artificial Intelligence (AI) or subfield of computer science that aims at creating computer programs that can change when exposed to new data. Under it, the major focus is to enable machines (computers in this case) learn without being explicitly programmed.

This type of AI has been creeping into our everyday lives for awhile now: for example Facebook’s News Feed uses machine learning to feed users content. Machine learning is now helping to deal with spam in Emails on the Internet.

Additionally, search engine such as Google use machine learning to provide the most relevant matching result to users’ queries – the list is endless.

Master AI and become an expert in this top-rated modern technological advancement with The Complete Machine Learning Bundle at 95% off on Tecmint Deals.


Learn the ins and outs to achieve the impossible with 10 Courses and 63.5 hours of training in machine learning. You will learn many programming languages such as Java, Python, Hadoop, MapReduce for AI and data science.

You will also be introduced to statistics and data science in R, deep learning and computer vision plus so much more.

What’s Included in Course

  • Quant Trading Using Machine Learning
  • Learn By Example: Statistics and Data Science in R
  • Learn By Example: Hadoop & MapReduce for Big Data Problems
  • Byte Size Chunks: Java Object-Oriented Programming & Design
  • An Introduction to Machine Learning & NLP in Python
  • Byte-Sized-Chunks: Twitter Sentiment Analysis (in Python)
  • Byte-Sized-Chunks: Decision Trees and Random Forests
  • An Introduction To Deep Learning & Computer Vision
  • Byte-Sized-Chunks: Recommendation Systems
  • From 0 to 1: Learn Python Programming

Master AI with The Complete Machine Learning Bundle and create computer programs that can change when exposed to new data. Subscribe to this bundle now at 95% or for as low as $39 off on Tecmint Deals.