How to Grow a Linux Partition with growpart

Resizing Linux Virtual Machine Disks

This article will show how to grow a partition on your Linux partition to fill the entire disk using growpart. This is useful if you have resized a virtual machine disk, or moved to a larger disk on your desktop or laptop Linux system.

Step 1: Listing and Identifying Storage Devices

To expand the filesystem on your resized disk, you’ll need to first locate the disk using the lsblk command, execute it by running:

lsblk

And you will see output similar to the following listing storage devices and the partitions on them:

Above, you can see that disk sda has a size of 50 gigabytes, but that the volume containing the root partition (sda3) is only 29.5 gigabytes – there is unused space on the storage device.

There may be multiple entries in the output from lsblk – you’ll need to identify the disk you have resized by the size and utilization – it should be apparent which disk has unused space. Usually on single-disk machines, the first and only storage device will be named sda.

You will also need to know the name of the partition your wish to grow – in this case sda3 – usually identified by it having the root mount point of /.

Step 2: Installing growpart

growpart is a utility that makes it super easy to grow a partition. It’s part of the cloud-guest-utils package. Note that while this package is intended to work on cloud-hosted virtual machines, the growpart utility also works just fine on physical machines.

On Debian and Ubuntu, run:

sudo apt install cloud-guest-utils

On Arch, run:

pacman install cloud-guest-utils

On RedHat, run:

yum install cloud-utils-growpart -y

Step 3: Grow your Partition

Once growpart is available, growing a partition to use the entire remaining disk space is as simple as running:

sudo growpart /dev/sda 3

You’ll need to specify the correct partition name above, replaceing sda 3 (note the space! the device and partition number are separated when using growpart) if necessary. growpart is executed with no additional parameters – if the size parameter is not specified, it will default to the available size of the partition.

Now that the partition has been expanded, the file system must be also using resize2fs:

sudo resize2fs /dev/sda3

Note that the space has disappeared in the device path again.

You will see output similar to:

Confirming the change. Once this final step is done, reboot:

sudo reboot

How to flush the DNS cache in Debian GNU/Linux?

If using systemd-resolved as your DNS resolver (i.e. the hosts line of your /etc/nsswitch.conf file includes the word resolve and/or /etc/resolv.conf contains the line nameserver 127.0.0.53), then this command will flush its cache:

sudo systemd-resolve --flush-caches

A newer version of this command seems to be:

sudo resolvectl flush-caches

How to convert WMV to MP4

You can use FFmpeg (a free command-line tool for Mac, Linux and Windows) to encode WMV to MP4. Here is an example syntax:

ffmpeg -i input.wmv -c:v libx264 -crf 23 -c:a aac -q:a 100 output.mp4

This will encode the video to H.264 video and AAC audio, using the default quality. To change the quality for the video, use a different CRF value, where lower means better, e.g. 20 or 18. For audio, 100% is the default quality. Increase the value for better quality.

For the AppleTV specifically, this is what Apple says it supports:

H.264 video up to 1080p, 30 frames per second, High or Main Profile level 4.0 or lower, Baseline profile level 3.0 or lower with AAC-LC audio up to 160 kbit/s per channel, 48 kHz, stereo audio in .m4v, .mp4, and .mov file formats

So, you could use the following command to force the 30 Hz frame rate and High profile:

ffmpeg -i input.wmv -c:v libx264 -crf 23 -profile:v high -r 30 -c:a aac -q:a 100 -ar 48000 output.mp4

How to install SSH2 extension for PHP 7.4

If You have an error like: Call to undefined function ssh2_connect() that’s mean that in your PHP not installed ssh2 extension.

Install this extension is very simple, in Ubuntu Linux or other Debian based distribution just use the command:

sudo apt install php7.4-ssh2

This command will install ssh2 extension to Your PHP 7.4. If you use other PHP version, just change number in this command to Your version.

Install LAMP server on Ubuntu

All the components of the LAMP server are available to install using the default system repository of Ubuntu. Hence, we can configure the environment without adding an extra repository. However, before moving forward, just run the system update command to ensure the system rebuilds the APT package index cache.

sudo apt update

Install Lamp server

We can install LAMP server components one by one on our Ubuntu system. However, it is a time-consuming process, hence to make it short here we are using a single command. That will not only install the LAMP server but also enable and start all the required services.

sudo apt install lamp-server^ php

The above command will select all the required packages to set up Apache, MySQL, and PHP on your system.

Uninstall the LAMP Server

Well, when it comes to uninstalling the LAMP server completely from your Ubuntu system, we can use the given command:

sudo apt autoremove --purge apache2* mysql-server* php*

How to Convert PNG, JPEG to WebP in Linux?

Webp is an open-source image format in Linux which supports lossless and lossy compression for images on the web.

One of the best practices to optimize the website performance is using compressed images.

This article will cover how to use webp image format for creating compressed and quality images for the website.

Installation

The webp package is already available in the official ubuntu repositories. Run the command below to update the Ubuntu repository to the latest index and install webp package.

sudo apt install webp

Converting image to webp format

Using the cwebp tool, an image can be converted into webp format. Run the cwebp command with option -q to define the quality of image and -o to define the output file.

In this example, I have used image file linux.png and linux.jpeg file to convert in webp format. You can choose your image name accordingly.

cwebp -q 60 linux.png -o linux.webp
cwebp -q 60 linux.jpeg -o linux1.webp

Converting webp image to png and jpeg format

In the previous step, we converted jpeg and png images to webp using cwebp utility tool. Now we will use the dwebp tool to convert webp images into png and jpeg format.

Use the dwep command with the option -o to create png and jpeg image format from webp. In the example, image.webp is used for the conversion.

dwep image.webp -o image.png
dwep image.webp -o image.jpeg

How to enable remote connections to MySQL server

Enabling remote connections to a MySQL server involves a few steps:

1. Configure MySQL Server

By default, MySQL server is configured to listen to the loopback IP address 127.0.0.1, which means it only accepts connections from the local machine. To allow remote connections, you need to modify the MySQL configuration file (my.cnf or my.ini or 50-server.cnf), typically located in /etc/mysql/ or /usr/local/mysql/etc/ or /etc/mysql/mariadb.conf.d.

Look for the following line in the configuration file:

bind-address = 127.0.0.1

And change it to:

bind-address = 0.0.0.0

This allows the MySQL server to listen on all available network interfaces.

2. Grant remote access to MySQL user

By default, MySQL server creates a user root with full administrative privileges, but it only allows access from the local machine. To enable remote access for this user, you need to grant it permission to connect from a remote IP address.

Log in to the MySQL server as root user and execute the following command:

GRANT ALL ON . TO 'root'@'%' IDENTIFIED BY 'yourpassword';

This grants the user root access to all databases and tables from any IP address (%). Replace ‘yourpassword‘ with a secure password of your choice.

3. Restart MySQL server

After modifying the configuration file and granting remote access to the user, you need to restart the MySQL server to apply the changes.

On Ubuntu or Debian, use the following command:

sudo service mysql restart

On CentOS or Fedora, use:

sudo systemctl restart mysqld

4. Open MySQL port on firewall

If you have a firewall running on the MySQL server, you need to open the port that MySQL server is listening on (usually port 3306) to allow incoming connections.

On Ubuntu or Debian, use the following command to open the port:

sudo ufw allow 3306/tcp

On CentOS or Fedora, use:

sudo firewall-cmd --add-port=3306/tcp --permanent
sudo firewall-cmd --reload

Once you have completed these steps, you should be able to connect to the MySQL server remotely using the root user and the password you set in step 2.

However, note that allowing remote access to the MySQL server can pose a security risk if not properly secured.

Therefore, it is recommended to only allow connections from trusted IP addresses and to use a secure password.

Install Wireguard on Debian 11

First update package list and upgrade your operating system:

sudo apt update && sudo apt upgrade

To install Wireguard use command:

sudo apt install wireguard

Now check if Wireguard installed correct:

sudo modprobe wireguard

If this command dose not show anything, Wireguard installed correct. If You get error like this: modprobe: FATAL: Module wireguard not found in directory /lib/modules/4.19.0-12-686, install this package:

sudo apt install linux-headers-$(uname --kernel-release)