Post

Linux Plus-Managing Linux Disks and Partitions

image

Overview

Hardware

  • List hardware devices
  • Create disk files to act as storage
  • List available and used storage

Partitions

  • Create and read partition tables
  • Encrypt partitions

Listing Hardward and Storage

img

img

  • -S - based on size
  • -r - Display reverse

Alma Linux 8.5

Discover Hardware

  • Block device files
  • Available disk space
  • More options to the ls command

lsblk img

  • sda - first disk
  • sda1 - SWAP - mounting point
  • sda2 - / - root filesystem

lspci img

lscpu img

lsusb img

img

To find the disk space, use df

  • -h - human readable
    1
    
    df -h /
    

    img

To find the size of the directory

1
2
df -h /etc/services
680K    /etc/services

To find and display the large file size

  • S - size of the file
  • r - listed in reverse order
    1
    
    ls -lhSr /etc
    

    img

Understanding Disk Files

img

Working with ISO Files

  • Download small ISO and mount it.
  • List devices with lsblk and losetup
    1
    2
    3
    4
    5
    6
    7
    
    yum list wget
    yum provides /usr/bin/wget
    sudo yum install -y wget
    wget https://download.virtualbox.org/virtualbox/4.0.0/VBoxGuestAdditions_4.0.0.iso
    sudo mount VBoxGuestAdditions_4.0.0.iso /mnt
    ls /mnt ; lsblk ; sudo losetup
    sudo unmount /mnt
    

Creating a Disk File

Using either dd or fallocate, we can create disk file. The latter being more efficient as it does not copy the data just allocating space.

  • Create disk file with dd
  • Create disk file with fallocate
1
2
dd if=/dev/zero of=disk1.img bs=1M count=1000
fallocate -l 1G disk2.img

img

Linking Devices to Files

  • Using losetup img

Understanding Disk Partitions

img

Partitioning Disks

  • Using the fdisk command
  • Using the parted command
  • Using partprobe to read partition tables

img

Encrypting Disks and Partitions Using LUKS

img

  • lsblk - list out the block devices
  • dd, fallocate - create raw files and
  • losetup - link them to loop devices with losetup
  • parted or fdisk - create partitiions
  • partprobe - to reread the partition table
  • cryptsetup - encrypting a partition or encrypting a disk will encrypting the underlying structure, so any filesystem that is laid upon it is going to be encrypted.
This post is licensed under CC BY 4.0 by the author.