Disk Management
Disk Management
Sysadmins generally have to deal with many issues when it comes to managing disks. These
include:
Partitioning disks
Creating file systems
Mounting file systems
Sharing file systems
Monitoring free space within file systems
Backing up (and sometimes restoring) file systems
protecting some file systems from running out of space (e.g., you may want the OS partition
to be separated from home directories or applications to keep it from being affected if users’
files begin to take up far an excessive amount of disk space)
improving performance
allocating swap space
facilitating maintenance and backups (e.g., you might be able to unmount /apps if it’s not part
of / and you might want to back up /home more frequently than /usr)
more efficient (and targeted) fsck
maintaining (particularly on test systems) multiple operating systems
reserving enough disk space for file system expansion
sharing select file systems with other system
The “du” (Disk Usage) command line is a standard command under Unix and Linux. It is used to
list the disk space used by files on a machine and crucial for disk space management on unix and
linux systems. Several paramaters enable users to format and filter the results.
Using du is a good starting point when trying to clean up unsed disk space under Unix.
du –s
Display the disk space used by all files in the selected directory by adding -s. You cannot limit the
folder depths while using this argument.
du -s /etc
There are a number of excellent commands for examining disk partitions. The df command is
one of the most commonly used commands for reporting on disk space usage. With the -h
option, the df command displays the measurements in the most "human-friendly" format and
that is, in fact, what the “h” is meant to imply. As you can see in the example below, the
measurements are displayed in kilobytes, megabytes or gigabytes depending on the sizes
rather than all using the same scale.
$ df -h
The lsblk (list block devices) command illustrates the relationship between disks
and their partitions graphically and also supplies the major and minor device
numbers and mount points.
du -h
Adding the parameter -h shows the results in a human-readable format: It adds size information
in Byte, Kilobyte, Megabyte, Gigabyte, Terabyte, and Petabyte.
Sort Results
Add | sort to the command line to sort the output. | sort -rh sorts recursively and displays the
biggest sizes on top.
root@server:/# du -s /* | sort -rh
The df Command
The first way to manage your partition space is with the df (disk free) command. The
command df -k (disk free) displays the disk space usage in kilobytes
The du Command
The du (disk usage) command enables you to specify directories to show disk space usage
on a particular directory.
This command is helpful if you want to determine how much space a particular directory is
taking. The following command displays number of blocks consumed by each directory. A
single block may take either 512 Bytes or 1 Kilo Byte depending on your system.
$du /etc
The /mnt directory, by the Unix convention, is where temporary mounts (such as CDROM
drives, remote network drives, and floppy drives) are located. If you need to mount a file
system, you can use the mount command with the following syntax −
mount -t file_system_type device_to_mount directory_to_mount_to
For example, if you want to mount a CD-ROM to the directory /mnt/cdrom, you can type −
$ mount -t iso9660 /dev/cdrom /mnt/cdrom
This assumes that your CD-ROM device is called /dev/cdrom and that you want to mount it
to /mnt/cdrom.