Introduction
Mounting disks and managing partitions are essential tasks in Linux system administration. This guide provides detailed steps and commands for various Linux distributions to help you mount disks, create partitions, and manage your storage effectively.
Prerequisites
- Root or sudo privileges.
- Basic understanding of Linux terminal commands.
- Disk or partition to work with (ensure no critical data is lost during formatting).
Listing Available Disks
To see all available disks and partitions:
sudo fdisk -l
For a more detailed view:
lsblk
Example Output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 100G 0 part /
├─sda2 8:2 0 200G 0 part /home
└─sda3 8:3 0 200G 0 part
Mounting a Disk
To mount a disk, you need to know its device name (e.g., /dev/sdb1
) and create a mount point.
Steps:
- Create a mount point (directory):
sudo mkdir /mnt/mydisk
- Mount the disk:
sudo mount /dev/sdb1 /mnt/mydisk
- Verify the disk is mounted:
df -h
Persistent Mounting:
To make the mount persistent across reboots, edit the /etc/fstab
file:
sudo nano /etc/fstab
Add the following line:
/dev/sdb1 /mnt/mydisk ext4 defaults 0 2
Partitioning a Disk
Use tools like fdisk
, parted
, or gparted
for partitioning.
Using fdisk:
- Select the disk:
sudo fdisk /dev/sdb
- Create a new partition:
n # Add a new partition
p # Primary partition
1 # Partition number
# Accept default start and end sectors
w # Write changes
- Format the partition:
sudo mkfs.ext4 /dev/sdb1
Using parted:
- Start parted:
sudo parted /dev/sdb
- Create a new partition table:
mklabel gpt
- Create a partition:
mkpart primary ext4 0% 100%
- Exit:
quit
Common Errors and Solutions
- Error:
mount: wrong fs type
Solution: Ensure the correct file system is specified. Usesudo blkid
to identify the file system. - Error:
Permission denied
Solution: Usesudo
or ensure proper permissions for the mount point.
Examples for Different Linux Flavors
Ubuntu/Debian:
sudo mount /dev/sdb1 /mnt/mydisk
sudo apt-get install gparted
CentOS/RHEL:
sudo mount /dev/sdb1 /mnt/mydisk
yum install gparted
Arch Linux:
sudo mount /dev/sdb1 /mnt/mydisk
sudo pacman -S gparted
Note: Learn how to mount a disk and manage Linux partitions with step-by-step instructions and examples above for various Linux distributions.