Disk management

From English Wiki
Revision as of 04:14, 15 August 2022 by Kentlee7 (talk | contribs) (Created page with "The following are common Linux commands for disk management. ==Disk management== {| class="wikitable sortable" ! Command !! Function |- | badblocks -s /dev/sda || Test...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The following are common Linux commands for disk management.


1 Disk management

Command Function
badblocks -s /dev/sda Test for unreadable blocks on disk /dev/sda
df -h Show free and used space on mounted file systems in human-readable format
df -i Shows free inodes of mounted file systems; inodes contain information on disk block locations and other attributes.
du -ah Display disk usage for all files and directories in human readable format
du -hs Display the size of the current directory
du -s Give important information regarding the disk usage (storage space) on your Linux system. It is efficient when combined with the Sudo command.
du -sh Display the currently active directory's disk usage
eject Eject a disk
fdisk -l Display all disk partitions sizes and types
fdisk -l Edit a disk partition
fdisk /dev/sda Create a new partition on /dev/sda
file -b -i Helps identify the type of file on your system.
findmnt Displays the mount points associated with all file systems
fsck File check and repair
fsck -A -N Check and repair a file system.
fsck.ext4 /dev/sda1 Check and repair a filesystem for errors
hdparm -tT /dev/sda Perform a read speed test on disk /dev/sda
lsblk Display information about block devices
lsusb Display USB ports and devices
lsusb -tv Display all USB devices
lvcreate Create a logical volume.
lvcreate Create a logical volume
md5sum Calculate md5sum
mkfs -t -V Create a new file system.
mkfs -t [partition-type] -c -v [/partition] Formats partition with the specified filesystem
mkfs -t xfs -c -v /home Creates xfs partition as /home; -v = verbose, -c = check for bad blocks
mkfs.ext4 /dev/sda1 Format the partition /dev/sda1
mkswap /dev/sda5 Create swap on sda5
mount Mount partition
mount -a -t Mount a file system.
mount -a /etc/fstab Mount all file systems listed in fstab
mount -t type /dev/sda Mount partition by type
mount /dev/sda1 /mnt Mount a partition to a directory
mount device_path mount_point Mount a device.
pvcreate Create a physical volume.
swapon /dev/sda5 Activate swap on sda5
umount Unmount a partition
umount -l Lazy unmount; immediately unmount and clean up later
unmount -f -v Unmount a mounted file system.


2 RAID disk management

Command Function
lsblk -o name, f­sty­pemou­ntpoint Find devices constituting a RAID array
mdadm --create /dev/md0 --level=1 /dev/sda1 /dev/sdb1 Create RAID array, level 1, with sda + sdb
mdadm --remove /dev/md0 Remove RAID array
mdadm --scan --assemble –uuid=UUID Scan RAID array
mdadm --stop /dev/md0 Stop RAID array
mdadm –assemble [device names] Assemble RAID array



3 See also