Linux Plus-Managing Linux Disks and Partitions
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
- -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
- sda - first disk
- sda1 - SWAP - mounting point
- sda2 - / - root filesystem
To find the disk space, use df
To find the size of the directory
1
2
df -h /etc/services
680K /etc/services
To find and display the large file size
Understanding Disk Files
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
Linking Devices to Files
Understanding Disk Partitions
Partitioning Disks
- Using the
fdisk
command - Using the
parted
command - Using
partprobe
to read partition tables
Encrypting Disks and Partitions Using LUKS
- 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.