Tag: system administration

How to increase the size of the partition and file system after increasing the physical size of the disk

Disk partition size and file system size

In Linux, a disk can be used entirely by one partition or be divided into several partitions (similar to volumes in Windows).

Usually, at the stage of installing the operating system, disk partitioning is done: disk partitions are created, and then these partitions are formatted into one or another file system. In this case, the size of the file system corresponds to the size of the partition (or the entire disk, if there is only one partition). That is, the sizes of file systems are equal to the sizes of partitions.

But there may be situations when the size of the file system no longer matches the size of the partition on which it is located. Examples of such situations:

  • you increased the disk size of your virtual private server (VPS)
  • you replaced your computer's hard drive and transferred the root file system using the dd utility (or other utilities that support creating and writing clones of entire disks and partitions) to a new disk

In both cases described, the Linux operating system will only be able to use the size that the file system originally had.

For clarity, let's understand the terms:

Disk size – the entire size of a physical or virtual disk. It can be used by the operating system in whole or in part within the created partitions and file systems.

Partition size – the space that a particular partition occupies. When cloning partitions with dd to a disk of a larger partition, the layout of the previous disk is preserved. That is, the operating system can even use a new disk only within the limits of the old disk layout.

Filesystem size – similar to partition size, the OS can only use a partition up to the size of the filesystem, even if the filesystem is moved to a new disk of a larger partition.

If you still do not fully understand the difference between “partition size” and “file system size”, then you need to know that, from a practical point of view, when increasing the disk size, you need to run two commands:

  • partition increase command
  • file system increase command

Note: For some hosting providers, the file system size increases automatically after switching to a plan with a larger disk size. For example, with Digitalocean, it is enough to select a larger disk and wait for the changes to be applied. And with Ihor hosting, after increasing the size of the server disk (can be done only through the support service), you need to increase the size of the partitions and the file system yourself.

How to increase the partition size and file system size on the server

This article will show you how to increase the partition and file system size on a computer without a graphical user interface, without rebooting the computer, without unmounting the file system, and without having to boot into Live OS. That is, you can use the shown method on servers. But nothing prevents you from using the commands from this article also on your home computer, for example, when cloning the OS to a new disk.

In this article, I am expanding the ext4 file system. The described commands should definitely work for ext2/ext3/ext4 filesystems.

I'm following the steps on Arch Linux, but the commands shown should work for any OS. Only the file system type matters. That is, if you want to increase the size of ext2 / ext3 / ext4, then this instruction should work regardless of the Linux distribution.

Utilities for increasing the size of partitions and the file system.

We need the resize2fs utility. This utility is included in the e2fsprogs package and is most likely installed in your distribution by default, since it usually refers to core packages, that is, programs necessary for the normal functioning of the Linux OS.

We also need the growpart utility, which is included in the cloud-utils package.

  • On Debian and Ubuntu derivatives, to install this package, run the commands:
sudo apt update
sudo apt install cloud-utils
  • On Arch Linux and derivatives of this distribution, to install the cloud-utils package, run the command:
pacman -S cloud-utils

Backing up the partition table

Just in case something goes wrong, back up your drive's partition table:

sfdisk -d /dev/vdX > partition_bak.dmp

Save the partition_bak.dmp file to a safe location other than the drive you backed up the partition table, because if data loss occurs, this file will also become inaccessible.

How to check partition size and file system size

Let's look at the size of the file system with the following command

df -h

Sample output:

Filesystem      Size  Used Avail Use% Mounted on
dev             2.0G     0  2.0G   0% /dev
run             2.0G  552K  2.0G   1% /run
/dev/vda2        30G   28G     0 100% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   27M  1.9G   2% /tmp
/dev/vda1       193M  103M   80M  57% /boot
tmpfs           393M     0  393M   0% /run/user/0

From this output it follows that the size of the file system on the /dev/vda2 partition is 30G and there is no free space on it.

Let's see the sizes of disks and partitions:

fdisk -l

Sample output:

Disk /dev/vda: 35 GiB, 37580963840 bytes, 73400320 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4b23ea92

Device     Boot  Start      End  Sectors  Size Id Type
/dev/vda1  *      2048   411647   409600  200M 83 Linux
/dev/vda2       411648 62914559 62502912 29.8G 83 Linux

It follows from these information that the size of the /dev/vda disk is 35 GB, and the size of the partitions present on it is 30 GB. The fact is that I hosting provider increased the size of the disk at my request. But the OS can still only use the old disk size.

How to increase the size of a Linux partition on the command line without Live System and unmounting the file system

To increase the partition to the maximum (taking into account free disk space), use the following command:

growpart /dev/DISK NUMBER

In this command:

  • /dev/DISK – disk device name
  • NUMBER – the number of the partition you want to enlarge

I want to enlarge the /dev/vda2 partition, so in my case:

  • /dev/DISK is “/dev/vda
  • NUMBER is “2

The command itself takes the following form:

growpart /dev/vda 2

But before executing it, it is recommended to run your command with the -N option. This option will cause the command to show what changes it will make, but the changes themselves will not be performed.

So let's run the command:

growpart -N /dev/vda 2

Sample output:

CHANGE: partition=2 start=411648 old: size=62502912 end=62914559 new: size=72988639 end=73400286
# === old sfdisk -d ===
label: dos
label-id: 0x4b23ea92
device: /dev/vda
unit: sectors
sector-size: 512

/dev/vda1 : start=        2048, size=      409600, type=83, bootable
/dev/vda2 : start=      411648, size=    62502912, type=83
# === new sfdisk -d ===
label: dos
label-id: 0x4b23ea92
device: /dev/vda
unit: sectors
sector-size: 512

/dev/vda1 : start=        2048, size=      409600, type=83, bootable
/dev/vda2 : start=      411648, size=    72988639, type=83

“# === old sfdisk -d ===” shows that the /dev/vda2 partition has 62502912 sectors (to get the disk size, multiply the number of sectors by the size of one sector, for example, 62502912*512/1024/1024/1024 = 29.80 GB).

# === new sfdisk -d ===” shows the size of the /dev/vda2 partition after running the command. This size is 72988639 sectors (i.e. 72988639*512/1024/1024/1024 = 34.80 GB).

Since in my case the disk is 100% used, and the partition resizing operation is very serious, before actually moving on to the changes, I freed up some disk space. How to do this, see the articles:

If everything is correct, now we run a command that will actually resize the selected partition, increasing it to the maximum possible in accordance with the available free space on the disk (remember to substitute your disk value and partition number):

growpart /dev/vda 2

Sample output:

CHANGED: partition=2 start=411648 old: size=62502912 end=62914559 new: size=72988639 end=73400286

Check the partition and file system sizes:

df -h

fdisk -l

Pay attention to the line:

/dev/vda2        30G   28G  285M  99% /

The file system size is still around 30 gigabytes. Its usage dropped from 100% to 99% just because I freed up disk space.

Also note the following line:

/dev/vda2       411648 73400286 72988639 34.8G 83 Linux

That is, the size of the /dev/vda2 partition has really increased.

How to increase the size of a Linux filesystem on the command line without Live System and unmounting the filesystem

The command to increase the file system to the maximum size in accordance with the free space on the partition is as follows:

resize2fs /dev/DEVICE

In this command, /dev/DEVICE is the name of the disk device.

In my case, the name of the partition I want to enlarge is /dev/vda2, then the command is:

resize2fs /dev/vda2

Sample output:

resize2fs 1.47.0 (5-Feb-2023)
Filesystem at /dev/vda2 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/vda2 is now 9123579 (4k) blocks long.

The output says that the filesystem on /dev/vda2 is mounted on / (the root filesystem), so “on-line resizing” is required. The command completed successfully.

Check the partition and file system sizes:

df -h

fdisk -l

Pay attention to the line:

/dev/vda2        35G   28G  5.0G  85% /

The filesystem on /dev/vda2 is now 35G in size and only 28G is occupied. That is the file system is really increased.

Regarding the partition size we increased in the previous step

/dev/vda2       411648 73400286 72988639 34.8G 83 Linux

nothing has changed for it.

Updating packages: whether to update the config file

Consider a situation when the package manager of your Linux distribution (Debian, Linux Mint, Ubuntu, Kali Linux) asks about updating the configuration file – what to do and how to get the latest version of the configuration file? Let’s figure it out.

With some updates of some packages, the structure of the configuration file changes. As a rule, the new file contains directives and settings that are necessary for the new version of the program, without which it cannot work.

Setting up a services is almost always changing configuration files. The end file can be the result of lengthy configuration work and many tests. This can take hours or even days.

Therefore, if it is necessary to update the configuration, a dilemma arises:

  • do not update the config, as a result of which the new version of a package will not work normally
  • update config and erase service configuration results

It is for this reason that the system asks you every time what needs to be done if the configuration file is updated with the program update?

An example of a message in which the package manager asks what to do with the new config file:

Configuration file '/etc/squid/squid.conf'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
   What would you like to do about it ?  Your options are:
    Y or I  : install the package maintainer's version
    N or O  : keep your currently-installed version
      D     : show the differences between the versions
      Z     : start a shell to examine the situation
 The default action is to keep your current version.
*** squid.conf (Y/I/N/O/D/Z) [default=N] ? 

The options are:

  • Y or I – install a new config file
  • N or O – save the currently used config file
  • D – show differences between versions
  • Z – open the shell to examine the situation

The default option is to save the current config file (N).

If in reality you have not used this program, or the settings made are of no value to you, then always agree to update the configuration file. If the settings made are important to you, then:

  • refuse to update the config file
  • make a backup copy of your config, update the config file to the new version, and then make the necessary settings in it

For some packages, like Tor, the config file is just a set of comments with no setting active – for such files (if you haven't changed them), the update is more of a formality.

Package configuration

Another option for reporting a new version of the configuration file:

Package configuration

  ┌──────────────────────────────────┤ Configuring privoxy ├──────────────────────────────────┐
  │ A new version (/etc/privoxy/config.ucftmp) of configuration file /etc/privoxy/config is   │ 
  │ available, but the version installed currently has been locally modified.                 │ 
  │                                                                                           │ 
  │ What do you want to do about modified configuration file config?                          │ 
  │                                                                                           │ 
  │                   install the package maintainer's version                                │ 
  │                   keep the local version currently installed                              │ 
  │                   show the differences between the versions                               │ 
  │                   show a side-by-side difference between the versions                     │ 
  │                   show a 3-way difference between available versions                      │ 
  │                   do a 3-way merge between available versions                             │ 
  │                   start a new shell to examine the situation                              │ 
  │                                                                                           │ 
  │                                                                                           │ 
  │                                          <Ok>                                             │ 
  │                                                                                           │

By default, the option “keep the local version currently installed” is selected. This is the best option if you want to keep your previous settings. To continue updating packages, press the “Tab” key, as a result you will switch to the “<Ok>” button.

And press the “Enter” key.

If you do not want to save the settings you made earlier, but want to get a new version of the configuration file, then use the cursor keys to select the “install the package maintainer's version” option. Then press “Tab” and “Enter” again.

Should I update configuration files in the /etc/default/ directory

A special case, in my opinion, is the /etc/default/ directory.

For example, the following screenshot shows that a request is being made to update the /etc/default/grub file.

As the name of the directory itself implies, it contains default configuration files, which, most likely, do not change even if you configured a particular service or program.

Therefore, by default, these configuration files can be updated, except in special cases when you specifically make changes to them.

How to view the new config file

Typically, system administrators and users save the current configuration file. But how do you view the new file? After all, it is quite possible that there are important changes in it.

One way to do this is to download the latest version of a package and see the configuration file for the latest version in that package.

Download the package with a command like:

apt download PACKAGE

For example, to download the squid package

apt download squid

Unpack the downloaded installation file with a command like:

ar x FILE.deb

For example:

ar x squid_5.1-2_amd64.deb

Now we need to unpack a file called data.tar.gz or data.tar.xz.

Look at the contents of the folder to find out the name of the file:

ls -l

If the file has a .tar.gz extension, then the command is as follows:

tar xzf data.tar.gz

If the file has the extension .tar.xz, then the command is as follows:

tar xf data.tar.xz

Let's check the contents of the current directory again in search of unpacked folders and files:

ls -l

Configuration files on the system are usually placed in the /etc/ directory, when you unpack the package, you will find this folder under the path ./etc/ (that is, in the current folder).

For example, the command to view the configuration file of the latest version of the squid package I am interested in:

gedit ./etc/squid/squid.conf

What is the difference between Suspend and Hibernate in Linux. Why is the Hibernation button missing?

When shutting down Linux, instead of completely shutting down the computer, you can select Suspend or Hibernate. These modes are also offered when configuring the behavior of the computer during inactivity (to save power), when the laptop battery is low, and when configuring the behavior after closing the lid of the laptop.

Suspend means stopping all applications and puts the computer into low power mode. When you turn on the computer, it returns to the same state that it was before Suspend. The difference from Hibernate is that the computer turns on faster, although it continues to consume energy. That is, the data remains in RAM, but the computer goes into a low power mode, similar to shutting down. In this state, the battery is consumed very slowly. When turned on, the computer wakes up very quickly. But if the battery is completely discharged before turning on, then the current data from the RAM will be lost)

Hibernate means writing the current state of the computer and RAM to the hard disk and turning off the computer. When you turn on the computer, it returns to the same state that it was before Hibernate. The difference from Suspend is that the computer completely stops consuming power and cannot lose data due to the fact that the battery is dead. But in Hibernate mode, the computer takes a little longer to turn on than when exiting the Suspend state. That is, the Hibernate mode means saving all data from RAM to disk and turning off the computer. The next time you turn on the data from the disk will be loaded into RAM and the computer will be able to continue from the same point that it stopped before sleep

That is, if the computer is often idle and you need to turn it on very quickly, then select the Suspend mode for this. If you expect the computer to be turned off for a long time, then select Hibernate.

Why is there no Hibernate mode in Linux?

In the following screenshot, you can see that when you turn off the computer, there is no option to select Hibernate. This is due to the fact that there is no Swap partition (Swap file) on the specified system, or it is of insufficient size.

In order for the Hibernate option to appear, you need to create a Swap file or increase its size, making it equal to or larger than the computer's RAM.

The created swap partition can be used not only to store some information from RAM while the computer is running, it can also be used in Hibernate mode. When adding this mode, an additional option will appear in the shutdown menu – Hibernate. If you select it, then the current state of the RAM will be written to the swap partition. The next time you turn on the computer, it reads the information from the swap file and restores the state of the computer. That is, those programs that were opened will be reopened and their result will be saved.

In modern Linux, hibernation (sleep) should be enabled automatically when a partition or swap file is added to the system.

For information on how to create a swap file in various distributions, see the articles:

Where NetworkManager stores settings (SOLVED)

NetworkManager Configuration Files

NetworkManager supports various plug-ins that can define new locations for storing configuration information.

The main configuration file for NetworkManager, which is usually changed, is /etc/NetworkManager/NetworkManager.conf. You can view its contents with the following command:

cat /etc/NetworkManager/NetworkManager.conf

In addition to this file, NetworkManager settings can be saved in the /etc/NetworkManager/conf.d and /usr/lib/NetworkManager/conf.d directories.

For a list of all NetworkManager settings, taking into account all configuration files, run the command:

NetworkManager --print-config

Where NetworkManager stores network connection settings

NetworkManager stores the settings for each connection in separate text files with the .nmconnection extension. A typical storage location for configuration files is /var/run/NetworkManager/system-connections. In addition to it, files with connections can be located in other places defined by NetworkManager plugins, for example, settings for network connections via Bluetooth can be stored in the /etc/NetworkManager/NetworkManager.conf folder. The NetworkManager configuration file is /etc/NetworkManager/NetworkManager.conf. Besides these main locations, there may be other paths that are specific to Linux distributions.

To list all network connections and the location of their configuration files, run the command:

nmcli -f NAME,DEVICE,FILENAME connection show

All NetworkManager configuration files

So, the configuration files for NetworkManager are as follows:

  • /etc/NetworkManager/NetworkManager.conf – main configuration file
  • /etc/NetworkManager/conf.d – directory with configuration files
  • /usr/lib/NetworkManager/conf.d – system directory with configuration files (for example, file /usr/lib/NetworkManager/conf.d/20-connectivity.conf)
  • /var/lib/NetworkManager/NetworkManager-intern.conf – internal configuration file. This file is written and read by NetworkManager, and its configuration values are merged with the configuration from NetworkManager.conf. Changes made to this file will be overwritten
  • /var/lib/NetworkManager/NetworkManager.state – file with a set of states
  • /etc/NetworkManager/system-connections/ – directory where wired and wireless connections are stored
  • /var/run/NetworkManager/system-connections/ – directory with some types of connections, for example, Internet via Bluetooth modem
  • /var/lib/NetworkManager/
  • /etc/NetworkManager/dispatcher.d/
  • /etc/NetworkManager/dnsmasq.d/
  • /etc/NetworkManager/dnsmasq-shared.d/

See also: How to remove Mobile broadband and Bluetooth connection in NetworkManager

How to simulate package installation on Linux (How to create and install a dummy package)

Sometimes, when installing packages from source code, you may encounter the problem that the required dependency is missing from the system. Usually you need to solve this problem by installing the necessary dependencies from the standard repository, or by compiling them from source.

Sometimes the required package is present, but its version is not suitable, a similar example and solution is described in the article “How to install a package for which there is no dependency of the required version”.

But I ran into a situation where the required dependency is:

a) does not exist at all (the package was removed from the package repository)

b) functionality has been moved to another package that can be installed

Take a look at the following message:

Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 detectiteasy : Depends: qt5-default but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

The program installed from source requires the qt5-default package. This package contains one single configuration file. The package itself was removed as unnecessary or due to the fact that its functionality was transferred to the qtchooser package that I installed. That is, from a practical point of view, the dependency is not needed, but I cannot update the system, because, as the package manager thinks, the dependencies are broken.

The way out of this situation is to install a dummy package.

How to create and install a dummy package on Linux (Debian, Linux Mint, Kali Linux, Ubuntu)

There is a Debian package called equivs that can create fake packages. Install it by running

sudo apt install -y equivs

Due to unresolved dependencies, I was unable to install the equivs package on the problematic OS – I used another computer to help.

After installation, you create a “control” template file using the following command:

equivs-control FILE_NAME

For example:

equivs-control qt5-default

Alternative package name can be used like postfix-custom for postfix or something else.

Let's open the generated file for editing:

gedit qt5-default

An example of the content in my case:

### Commented entries have reasonable defaults.
### Uncomment to edit them.
# Source: <source package name; defaults to package name>
Section: misc
Priority: optional
# Homepage: <enter URL here; no default>
Standards-Version: 3.9.2

Package: <package name; defaults to equivs-dummy>
# Version: <enter version here; defaults to 1.0>
# Maintainer: Your Name <yourname@example.com>
# Pre-Depends: <comma-separated list of packages>
# Depends: <comma-separated list of packages>
# Recommends: <comma-separated list of packages>
# Suggests: <comma-separated list of packages>
# Provides: <comma-separated list of packages>
# Replaces: <comma-separated list of packages>
# Architecture: all
# Multi-Arch: <one of: foreign|same|allowed>
# Copyright: <copyright file; defaults to GPL2>
# Changelog: <changelog file; defaults to a generic changelog>
# Readme: <README.Debian file; defaults to a generic one>
# Extra-Files: <comma-separated list of additional files for the doc directory>
# Links: <pair of space-separated paths; First is path symlink points at, second is filename of link>
# Files: <pair of space-separated paths; First is file to include, second is destination>
#  <more pairs, if there's more than one file to include. Notice the starting space>
Description: <short description; defaults to some wise words> 
 long description and info
 .
 second paragraph

The lines with comments indicate which defaults will be applied when creating the package – you can delete these lines or uncomment and specify your own value.

Also in the line “Package” enter the name of the package, I got it like this:

Section: misc
Priority: optional
Standards-Version: 5.15.2+dfsg-7
Version: 5.15.2
Package: qt5-default

The “Provides” line indicates that my package provides the capabilities offered by another package that one is trying to spoof.

Finally, after generating the template control file, use the equivs-build command to create a fake package like

equivs-build /PATH/TO/GENERATED/CONTROL/FILE

In my case, this is:

equivs-build qt5-default

It will take a few seconds to build the package and then you can run

sudo dpkg -i PACKAGE_NAME*.deb

For example, in my case, after transferring the package to the problem system, the command is as follows:

sudo dpkg -i qt5-default_5.15.2_all.deb

After installing the package, the work of the package manager returned to normal – it is again possible to install and remove packages, update the system.

For advanced users, if your template control file has the “Requires” line, you can create metapackages to install a group of programs.

See also:

Linux PowerShell Basics (Beginner’s Guide)

PowerShell for Linux

In recent years, there has been a trend at Microsoft to cross-platform some of its products and open their source. Also Linux itself became part of Windows in the form of a subsystem. PowerShell, which was originally a Windows-only component, was released as open source and became cross-platform on August 18, 2016, available for Linux and Mac OS.

PowerShell is a task automation and configuration management system developed by Microsoft. It consists of a command interpreter (shell) and a scripting language built on the .NET Framework.

It offers full access to COM (Component Object Model) and WMI (Windows Management Instrumentation), thereby allowing system administrators to perform administrative tasks on both local and remote Windows systems, as well as WS-Management and CIM (Common Information Model), allowing you to administer remote Linux systems plus network devices.

Within this framework, administrative tasks are mostly performed by specific .NET classes called cmdlets (pronounced command-let). Similar to shell scripts in Linux, users can create scripts or executables by storing groups of cmdlets in files following specific rules. These scripts can be used as standalone utilities or command line tools.

How to install PowerShell on Linux

Installation on various Linux distributions is described in the official documentation “Installing PowerShell on Linux”.

But in the official documentation there is a lack of information about some distributions, to fill this gap, separate instructions were written:

Features of PowerShell on Linux

1. Command case is not important in PowerShell

In Windows, the case of commands and names of files and folders is not important – this is a big difference from Linux, where the case of both commands and files matters.

PowerShell inherits a feature from Windows – case is not important. Although this tutorial shows commands written in different case (for example, Get-Date), this is actually for better readability and it doesn't matter if you enter Get-Date, GET-DATE, get-date, or gET- dATE.

2. Some commands are missing

The set of commands in PowerShell depends on the available modules, that is, even on a Windows computer, if you install, for example, Active Directory, then new commands will appear in PowerShell.

The Linux version of PowerShell lacks some of the commands found in the standard Windows PowerShell, primarily when it comes to Windows-specific things.

3. Many aliases and abbreviations

You can see in the scripts and examples of PowerShell commands the unusual writing of commands – in PowerShell, abbreviated notation is allowed, and there are also many aliases, that is, the same action can be performed by commands written in different ways.

4. PowerShell versions

Please note that PowerShell 5 is currently preinstalled on Windows by default, and this shows the installation of the latest version of PowerShell 7. On Windows, you can also install PowerShell 7, but this version will not replace the preinstalled version – there will be 2 versions of PowerShell, moreover, when launched from the “Power user menu” (Win+x) will open PowerShell 5, and when you start Windows Terminal, PowerShell 7 will open.

5. Skipping option names

Some options are positional and when specifying their values, you can skip the option names – at first this may seem confusing.

How to use Powershell on Linux

In this section, we will have a short introduction to Powershell; where we will see how to start PowerShell, run some basic commands, see how to work with files, directories and processes. Later, you will learn how to list all available commands, show command help and aliases.

To start Powershell, enter:

pwsh

You can check the Powershell version with the following command:

$PSVersionTable

If you only need the version number, then use the following construction:

Get-Host | Select-Object Version

Running some basic Powershell commands on Linux.

Show current date:

Get-Date

Show computer uptime:

Get-Uptime

Show current working directory:

Get-Location

Working with files and directories in Powershell

1. Create a new empty file in two ways:

New-Item hackware.stuff

Or:

"">hackware.stuff

Then add content to it and view the content of the file.

Set-Content hackware.stuff -value "Делаем pwsh.ru - это весело!"
Get-Content hackware.stuff

2. Delete the file in PowerShell.

Remove-Item hackware.stuff
Get-Content hackware.stuff

3. Create a new directory.

Take a look at the following set of commands:

mkdir hackware-files
cd hackware-files
"">domains.list
ls

Sound familiar? Yes, as already mentioned, there are many aliases in PowerShell. The same actions can be performed with the following commands:

New-Item hackware-files -ItemType "directory"
Set-Location hackware-files
New-Item domains.list
Get-ChildItem -Name

In fact, the commands don't just do the same thing – they are identical.

4. To display a long list that displays detailed information about files and directories, including mode (file type), last modified time, enter:

dir

Or:

Get-ChildItem

To display the contents of a specific folder (in this case, the root of the file system), run:

Get-ChildItem /

Working with Processes in PowerShell

How to view all running processes in Linux using PowerShell:

Get-Process

To view detailed information about one or a group of running processes with a given name, specify the process name as an argument to the previous command as follows:

Get-Process httpd

The value of the units in the output is above:

  • NPM(K) – amount of non-paged memory that the process is using, in kilobytes.
  • PM(K) – amount of pageable memory that the process is using, in kilobytes.
  • WS(K) – size of the working set of the process, in kilobytes. The working set consists of the pages of memory that were recently referenced by the process.
  • CPU(s) – amount of processor time that the process has used on all processors, in seconds.
  • ID – process ID (PID).
  • ProcessName – name of the process.

To get all possible data about one or more processes use a command of the form (replace httpd with the name of the process you are interested in):

Get-Process httpd | Format-List *

To stop the process with ID 10500 use the command as shown below:

Get-Process -Id 10500 | Stop-Process

Getting Help in PowerShell

To learn more, get a list of all PowerShell commands for various tasks:

Get-Command

It is possible to filter the information displayed by the Get-Command command. Let's say you want to see PowerShell commands containing the word “Alias”, for this you need to run the following command:

Get-Command -Name *Alias

To display help about a command (cmdlet) use the following:

Get-Help CMDLETS

For example, to display help about the Get-Alias cmdlet:

Get-Help Get-Alias

To get the most complete help on Get-Command, do the following:

Get-Help Get-Command -Full

Aliases in PowerShell

To see all available command aliases, enter:

Get-Alias

To get information about a specific alias, enter its name:

Get-Alias -Name pwd

PowerShell Command History

Last but not least, display the command history (a list of the commands you ran earlier) like this:

history

So this was an introduction to PowerShell on Linux. Of course, PowerShell can actually do much more than create files and show running processes.

Warning: apt-key is deprecated (SOLVED)

The apt-key command manages keys that are responsible for verifying the signature of application package repositories.

Now, whenever you use the apt-key command, you will receive the message:

Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).

It means that the apt-key program is now deprecated. Now we should use trusted.gpg.d to manage keyfiles. Translated into human language, now we have to add files ourselves to the /etc/apt/trusted.gpg.d/ folder.

This method will use the /etc/apt/trusted.gpg.d/ directory to store the public GPG key ring files. It has been available since early 2017.

If you look at the recommended man page (man apt-key), it says that this command and all its functions are deprecated.

There are two options for how you can proceed in this situation.

You can continue to use apt-key

Despite the assurances in the documentation, the apt-key program works as usual and performs all its functions.

At the same time, the apt-key command will not be removed for quite a long time, at least several years. It may not be removed at all for compatibility.

Therefore, basically, you can ignore the warning “apt-key is deprecated”.

How to add keys in a new way

The new “modern” version is poorly documented, let's try to fill this gap.

Now the keys need to be added with the following commands.

If a remote key file is added:

curl -s URL | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/NAME.gpg --import

If a local key file is added:

cat URL.pub | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/NAME.gpg --import

In these commands, you need to substitute:

  • URL - address of the .pub file
  • NAME - you can choose any file name
  • FILE - filename of the .pub file

Then be sure to run the following command to set the correct file permissions:

sudo chmod 644 /etc/apt/trusted.gpg.d/NAME.gpg

Example. If you already know the URL of the required public key, use wget or curl to download and import it. Remember to update the file permissions from 600 to 644.

curl -s https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/earth.gpg --import
sudo chmod 644 /etc/apt/trusted.gpg.d/earth.gpg

Alternatively, you can get the key from the keyserver:

sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/rabbit.gpg --keyserver keyserver.ubuntu.com --recv 6B73A36E6026DFCA
sudo chmod 644 /etc/apt/trusted.gpg.d/rabbit.gpg

How to view information about installed keys

To view information about the installed key, run a command of the form:

gpg --list-keys --keyring /etc/apt/trusted.gpg.d/FILE.gpg

For instance:

gpg --list-keys --keyring /etc/apt/trusted.gpg.d/earth.gpg

As said, the old command also works:

apt-key list

How to remove a key added by a new method

If you need a command analogue:

sudo apt-key del 7D8D08F6

Now, to remove the key, simply delete the file with commands like:

cd /etc/apt/trusted.gpg.d/
sudo rm NAME.gpg

But “apt-key del” also works.

How to remove a key added with apt-key add

If you want to delete individual keys, then use a command like this:

sudo apt-key del KEY_ID

To find out the KEY_ID, run the command

apt-key list

find the key you want, for example:

/etc/apt/trusted.gpg
--------------------
pub   rsa4096 2016-04-12 [SC]
      EB4C 1BFD 4F04 2F6D DDCC  EC91 7721 F63B D38B 4796
uid         [ неизвестно ] Google Inc. (Linux Packages Signing Authority) <linux-packages-keymaster@google.com>
sub   rsa4096 2019-07-22 [S] [   годен до: 2022-07-21]

Look at the sequence of numbers and letters in the pub field - this is a hash. In this example, we are interested in the line

      EB4C 1BFD 4F04 2F6D DDCC  EC91 7721 F63B D38B 4796

To delete this key, you need to run the command (note that spaces have been removed from the hash):

sudo apt-key del EB4C1BFD4F042F6DDDCCEC917721F63BD38B4796

How to remove all keys added with apt-key add

Just delete the /etc/apt/trusted.gpg file:

sudo rm /etc/apt/trusted.gpg
Loading...
X