Disk Space and Usage Commands
Display Disk Space Information
Command:
df
Description: Displays the amount of disk space used and available on filesystems.Command:
df -h
Description: Provides a human-readable format (e.g., in GB or MB) for easier interpretation of disk space usage.
Display Disk Usage
Command:
du ~
Description: Shows the disk usage of your home directory, listing the size of each subdirectory.Command:
du -sh ~
Description: Gives a summary of the total disk usage in your home directory, displaying it in a human-readable format.
Creating a Virtual Disk
To create a virtual disk, use the following command:
bash
dd if=/dev/zero of=vdisk.img bs=1M count=256
Explanation of Parameters
if=/dev/zero: Specifies the input file as /dev/zero, a special file that produces null bytes. This is useful for creating empty files or disks.
of=vdisk.img: Sets the output file to vdisk.img, which will be the virtual disk created.
bs=1M: Defines both the input and output block size as 1 megabyte, optimizing the speed of the operation.
count=256: Limits the operation to 256 blocks, resulting in a total size of 256 MB for the virtual disk.
Verifying the Virtual Disk
To verify the creation of the virtual disk, run:
bash
ls -lh vdisk.img
This command lists the details of vdisk.img, including its size and permissions.
Formatting the Virtual Disk
Format the virtual disk with the ext4 filesystem using the following command:
bash
sudo mkfs.ext4 vdisk.img
Additional Details
The mkfs.ext4 command creates an ext4 filesystem on the specified file. This is commonly used for new disks or partitions, ensuring optimal performance for most usage scenarios [[1]] [[2]].
You can customize the filesystem parameters if needed, but the default options are generally sufficient for typical use cases [[1]].
Creating a Mount Point
Create a directory to serve as the mount point for the virtual disk:
bash
sudo mkdir /mnt/vdisk
This directory will be used to access the contents of the virtual disk.
Mounting the Virtual Disk
Finally, mount the virtual disk using:
bash
sudo mount -o loop vdisk.img /mnt/vdisk
Explanation of the Command
The -o loop option allows you to mount a file as if it were a disk. This is particularly useful for virtual disks created from image files.
Now, you can access the contents of your virtual disk at /mnt/vdisk.
Top comments (0)