Disk partitioning and management in Linux
Disk partitioning and management in Linux involves creating, resizing, and deleting partitions on a hard drive or SSD. Here are some code examples for common disk partitioning and management tasks in Linux:
- Listing partitions
To list the partitions on a disk in Linux, use the lsblk command. Here's an example:
lsblk
This command will display a list of the available disks and their partitions, along with their sizes and mount points.
- Creating a new partition
To create a new partition on a disk in Linux, use the fdisk command. Here's an example:
sudo fdisk /dev/sda
# Press "n" to create a new partition
# Specify the partition size and type
# Press "w" to write the changes and exit
This command will start the fdisk utility for the /dev/sda disk. You can then create a new partition by following the prompts.
- Resizing a partition
To resize a partition on a disk in Linux, use the resize2fs command. Here's an example:
sudo resize2fs /dev/sda1 10G
This command will resize the partition /dev/sda1 to 10GB. Note that you may need to use a different command depending on the filesystem type of the partition.
- Mounting a partition
To mount a partition in Linux, use the mount command. Here's an example:
sudo mount /dev/sda1 /mnt/mydata
This command will mount the partition /dev/sda1 to the directory /mnt/mydata. Note that you may need to create the mount directory first.
- Checking disk usage
To check disk usage in Linux, use the df command. Here's an example:
df -h
This command will display a list of the mounted filesystems and their usage statistics, including the total size, used space, and available space.
These are some examples of basic disk partitioning and management tasks in Linux. There are many more advanced options available, such as creating RAID arrays and managing LVM volumes, but these commands should be enough to get you started
Leave a Comment