Difference between revisions of "Disk management"

From English Wiki
Jump to navigation Jump to search
(Created page with "The following are common Linux commands for disk management. ==Disk management== {| class="wikitable sortable" ! Command !! Function |- | badblocks -s /dev/sda || Test...")
 
m
 
Line 86: Line 86:
 
|}
 
|}
 
 
+
 +
==Disk errors==
 +
Disk errors may cause boot issues. Sometimes these can be dealt with the file repair command for the.
 +
* fsck /dev/sda1
 +
* e2fsck /dev/sda1 [specifically for ext filesystems]
 +
 
 +
Errors with magic numbers in superblocks can be more difficult. One must first query the locations of the superblocks on the device like so.
 +
* mke2fs -n /dev/sda
 +
 
 +
This outputs a list of superblock locations. The one needs to manually try to rebuild the superblocks by entering the following repair command with each superblock number, until a usable superblock is found. Usually one needs to try this with each superblock location, one by one, from the mke2fs output, until the right one is found.
 +
* e2fsck -b 32768 /dev/sda1
 +
 
 +
 
 +
 
==RAID disk management==
 
==RAID disk management==
  

Latest revision as of 01:51, 9 February 2023

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 Disk errors

Disk errors may cause boot issues. Sometimes these can be dealt with the file repair command for the.

  • fsck /dev/sda1
  • e2fsck /dev/sda1 [specifically for ext filesystems]

Errors with magic numbers in superblocks can be more difficult. One must first query the locations of the superblocks on the device like so.

  • mke2fs -n /dev/sda

This outputs a list of superblock locations. The one needs to manually try to rebuild the superblocks by entering the following repair command with each superblock number, until a usable superblock is found. Usually one needs to try this with each superblock location, one by one, from the mke2fs output, until the right one is found.

  • e2fsck -b 32768 /dev/sda1


3 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



4 See also