Olen  Predovic

Olen Predovic

1604280420

How To check LXD container BTRFS disk usage on Linux

Here is a quick and dirty shell script I put to check LXD container size and how much space they are taking on the BTRFS subvolume. Naturally, you must run the script as a root user, and LXD must be configured with BTRFS storage backend on Linux operating systems. See how to set up and install LXD on Ubuntu 20.04 LTS using the apt command

Checking LXD container BTRFS disk usage on Linux

Sample shell script:

#!/usr/bin/env bash
## Usage: 
## Find LXD container disk size and how much space they are using when storage back end set to BTRFS.
## Tested on Ubuntu Linux 20.04 LTS only
## Syntax:
## /path/to/lxd-btrfs-df 
## /path/to/lxd-btrfs-df | more
## /path/to/lxd-btrfs-df | grep "container-name"
## /path/to/lxd-btrfs-df  /dev/sda2
## ----------------------------------------------------------------------------
## Written by Vivek Gite <https://www.cyberciti.biz/>
## (c) 2020 Vivek Gite under GNU GPL v2.0+
## ----------------------------------------------------------------------------
## Last updated: 23/Oct/2020
## ----------------------------------------------------------------------------
set -eu -o pipefail

## Default set to aws /dev/xvdf but override using the cli arg
DEV="${1:-/dev/xvdf}"

## BTRFS mount point 
MNT="/mnt/btrfs"

## Look for btrfs binary
_BTRFS="$(command -v btrfs)"

## Am i root user? if not die.
[ "$(id -u)" -ne "0" ] && { echo "This script must be run as root."; exit 1; }

## Failsafe stuff
[ "$_BTRFS" == "" ] && { echo "btrfs command not found."; exit 2; }
[ ! -d "$MNT" ] && mkdir -p "$MNT"
[ ! -b "$DEV" ] && { echo "$DEV not found. Try '$0 /dev/BTRFS_DEVICE' command."; exit 3; }

## Is $DEV mounted?
if ! mount | grep -q "^${DEV}" 
then
	mount "$DEV" "$MNT" 
else
	MNT="$(mount | grep ^"${DEV}" | awk '{print $3}')"
fi

## My quick df for lxd containers 
echo -e "\n\t* Disk usage for LXD containers with BTRFS fs\n"
for d in "${MNT}"/containers/*
do 
	$_BTRFS filesystem du -s "$d"
done

## Run df on mount fs too to get total disk usage 
echo -e "\n\t* Total (df) for $MNT BTRFS fs\n"
$_BTRFS filesystem df "$MNT"

umount "$MNT"

#linux

What is GEEK

Buddha Community

How To check LXD container BTRFS disk usage on Linux
Olen  Predovic

Olen Predovic

1604280420

How To check LXD container BTRFS disk usage on Linux

Here is a quick and dirty shell script I put to check LXD container size and how much space they are taking on the BTRFS subvolume. Naturally, you must run the script as a root user, and LXD must be configured with BTRFS storage backend on Linux operating systems. See how to set up and install LXD on Ubuntu 20.04 LTS using the apt command

Checking LXD container BTRFS disk usage on Linux

Sample shell script:

#!/usr/bin/env bash
## Usage: 
## Find LXD container disk size and how much space they are using when storage back end set to BTRFS.
## Tested on Ubuntu Linux 20.04 LTS only
## Syntax:
## /path/to/lxd-btrfs-df 
## /path/to/lxd-btrfs-df | more
## /path/to/lxd-btrfs-df | grep "container-name"
## /path/to/lxd-btrfs-df  /dev/sda2
## ----------------------------------------------------------------------------
## Written by Vivek Gite <https://www.cyberciti.biz/>
## (c) 2020 Vivek Gite under GNU GPL v2.0+
## ----------------------------------------------------------------------------
## Last updated: 23/Oct/2020
## ----------------------------------------------------------------------------
set -eu -o pipefail

## Default set to aws /dev/xvdf but override using the cli arg
DEV="${1:-/dev/xvdf}"

## BTRFS mount point 
MNT="/mnt/btrfs"

## Look for btrfs binary
_BTRFS="$(command -v btrfs)"

## Am i root user? if not die.
[ "$(id -u)" -ne "0" ] && { echo "This script must be run as root."; exit 1; }

## Failsafe stuff
[ "$_BTRFS" == "" ] && { echo "btrfs command not found."; exit 2; }
[ ! -d "$MNT" ] && mkdir -p "$MNT"
[ ! -b "$DEV" ] && { echo "$DEV not found. Try '$0 /dev/BTRFS_DEVICE' command."; exit 3; }

## Is $DEV mounted?
if ! mount | grep -q "^${DEV}" 
then
	mount "$DEV" "$MNT" 
else
	MNT="$(mount | grep ^"${DEV}" | awk '{print $3}')"
fi

## My quick df for lxd containers 
echo -e "\n\t* Disk usage for LXD containers with BTRFS fs\n"
for d in "${MNT}"/containers/*
do 
	$_BTRFS filesystem du -s "$d"
done

## Run df on mount fs too to get total disk usage 
echo -e "\n\t* Total (df) for $MNT BTRFS fs\n"
$_BTRFS filesystem df "$MNT"

umount "$MNT"

#linux

Hire Dedicated Linux Developer

Looking to develop real-time applications?

Hire Dedicated Linux Developer from HourlyDeveloper.io, we have dedicated developers who have vast experience in developing applications for Linux and UNIX operating systems and have in-depth knowledge of their processes, kernel tools, internal architectures, and development packages.

Consult with experts:- https://bit.ly/2ZQ5ySP

#hire linux dedicated developer #linux developer #linux development company #linux development services #linux development #linux developer

How I Switched from Windows 10 to Linux Mint

This article is all about my journey on switching from Windows 10 to Linux Mint 20, how I got easily adapted to the Linux environment, and some resources that helped me to set up a perfect Desktop environment.

Uncertainty

Ok, now I have decided to switch to Linux but here comes the first question. Which distro will satisfy my needs both in terms of GUI and other aspects? Linux is not something new to me since I have been working with RHEL based distros in my work for the past 4 years with the command-line.

I know RHEL based distros are good for enterprises but not for personalized desktop environments, at least that’s what I am thinking till now. So I started my research to find the distro that should be easy for me to use and at the same time should have good community support if in case I ran into some problem. Among many Linux distros, I drilled down my list to 4 flavors.

Related ArticleThe Best Linux Distributions for Beginners

Before deciding the Distro it is necessary you formulate the list of tools/programs or packages needed and check if the distro you choose provides all those features.

For me, I use Linux for two main purposes: one is for my professional development work, writing articles, and second for my personal use like Video editing and Movies. Most of the popular software are created to be compatible with Windows, macOS, and Linux like Sublime TextVSCodeVLC Media PlayerFirefox/Chromium browser. Other than these software, cloud-based services make our life easy Like Microsoft Office 365 or G Suite.

#linux distros #linux mint #linux distros #linux mint tips #linux

Lindsey  Koepp

Lindsey Koepp

1603763460

AWS Bottlerocket vs. Google Container-Optimized OS: Which Should You Use and When

What’s the difference between popular Container-Centric OS choices, Google’s Container-Optimized OS, and AWS’s Bottlerocket? The concepts underlying containers have been around for many years. Container technologies like Docker, Kubernetes, and an entire ecosystem of products, as well as best practices, have emerged in the last few years. This has enabled different kinds of applications to be containerized.

Web service providers like Amazon AWS and Google are giving a further boost to container innovation, for enterprises to adopt and use containers at scale. This will help them to reap the benefits containers bring, including increased portability and greater efficiency.

Linux-based OS, AWS Bottlerocket is a new option, designed for running containers on virtual machines (VMs) or bare-metal hosts. In this article, you will learn the core uses and differences between the two open-source OS.

**AWS Bottlerocket **

It is an open-source, stripped-down Linux distribution that’s similar to projects like Google’s Container-Optimized OS. This single-step update process helps reduce management overhead.

_It makes OS updates easy to automate using container orchestration services such as Amazon Elastic Container Service (ECS) and Amazon Elastic Kubernetes Service (EKS). _

**Google Container-Optimized OS **

It’s an OS image for Google Compute Engine VMs that’s optimized for running Docker containers. It allows you to bring up your Docker containers on Google Cloud Platform securely, and quickly. It is based on the open-source Chromium OS project and is maintained by Google.

But before diving into the core differences, let us give you a basic overview of containers, VMs, and container-optimized OS, and its underlying challenges to better understand the differences.

If you are already aware of all the underlying processes of containers, then you can skip to the main differences for AWS Bottlerocket vs Google Container-Optimized OS.

#containers #amazon-aws #google-cloud #container-optimized-os #aws-containers #docker-containers #linux-based-os #orchestration

I am Developer

1620616862

How to Delete Directories and Files in Linux using Command Line

In this remove or delete directories and files linux tutorial guide, you will learn how to remove empty directory and non empty directory linux using command line. And as well as how to remove/file files linux using command line.

If you work with Linux then you will need the following:

  • how to remove empty directory in linux,
  • how to remove non empty directory,
  • how to remove directory without confirmation linux
  • how to remove files with and without confirmation in linux.

So, this tutorial guide will show you you how to use the rmunlink, and rmdir commands to remove or delete files and directories in Linux with and without confirmation.

https://www.tutsmake.com/how-to-remove-directories-and-files-using-linux-command-line/

#how to delete directory in linux #how to remove non empty directory in linux #remove all files in a directory linux #linux delete all files in current directory #linux delete all files in a directory recursively #delete all files in a directory linux