Linux Commands For Managing Partitioning Troubleshooting
Linux Commands For Managing Partitioning Troubleshooting
troubleshooting
networkworld.com /article/3221415/linux/linux-commands-for-managing-partitioning-troubleshooting.html
By Sandra Henry-Stocker
How much do you need to know about disks to successfully manage a Linux system? What commands do what?
How do you make good decisions about partitioning? What kind of troubleshooting tools are available? What kind of
problems might you run into? This article covers a lot of territory from looking into the basics of a Linux file systems
to sampling some very useful commands.
Disk technology
In the beginning days of Unix and later Linux, disks were physically large, but very small in terms of storage capacity.
A 300 megabyte disk in the mid-90s was the size of a shoebox. Today, you can get multi-terrabyte disks that are the
size of a slice of toast.
Traditionally, files resided within file systems that resided in disk partitions that were themselves simply slices of
disks. This organization still dominates today, though servers in large data centers often take on an entirely different
structure.
/\
/ \
/ \
/ file \
/ \
/==========\
/ \
/ file system \
/ \
/==================\
/ disk partition \
/======================\
/ disk
\
/==========================\
This simplistic view still works for many systems, but these days there are lot of complexities that make disk
management harder in some ways and easier in others. A file system might be virtual no longer residing on a
single disk and more complex to manage, but far easier to resize as needed. In fact, the entire system could be
virtual. And what we might manage as if it were a single disk could actually be some portion of a very large disk
array.
Disk management
Sysadmins generally have to deal with many issues when it comes to managing disks. These include:
Partitioning disks
Creating file systems
1/6
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 its 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 systems
Partitioning commands
For most Linux servers, partitioning is done before the servers are deployed. On the other hand, you might add
disks at some later time or hold back some significant amount of free disk space for future use.
To make changes or verify partitions, enter a command such as fdisk /dev/sda to start fdisk interactively and then
type m to see a list of the things that you can do with the fdisk command.
2/6
As you can see, the fdisk command provides a lot of functionality. The partitions that you set up may look something
like this configuration in which four partitions have been set up on a single disk /dev/sda.
sda
+------------+------------------------+--------------------+------+
| / 40G | /home 80G | /apps 70G |
swap |
+------------+------------------------+--------------------+------+
sda1 sda2 sda3
sda4
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 969M 4.0K 969M 1% /dev
tmpfs 196M 1.1M 195M 1% /run
/dev/sda1 37G 4.5G 31G 13% /
none 4.0K 0 4.0K 0%
/sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 980M 152K 979M 1% /run/shm
none 100M 36K 100M 1% /run/user
/dev/sda3 28G 44M 26G 1% /apps
The pydf command (think "python df" as it's really a python script) also provides a very useful disk usage display
showing mount points and cute little illustrations for how full each partition is.
$ pydf
Filesystem Size Used Avail Use% Mounted
on
/dev/sda1 37G 4534M 30G 12.1 [##...........] /
/dev/sda3 27G 44M 26G 0.2 [.............] /apps
3/6
$ sudo parted -l
Model: ATA WDC WD800AAJS-60 (scsi)
Disk /dev/sda: 80.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
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.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE
MOUNTPOINT
sda 8:0 0 74.5G 0 disk
sda1 8:1 0 37.3G 0 part /
sda2 8:2 0 9.3G 0 part [SWAP]
sda3 8:3 0 28G 0 part /apps
The fdisk command reports more details on disk partitions and uses very different numbers. You can also use fdisk
to create or delete partitions, list unpartitioned space, change a partition type, or verify the partition table.
$ sudo fdisk -l
The sfdisk command is similar to fdisk, but makes some partition manipulation activities easier to perform.
4/6
$ sudo sfdisk -l -uM
The cfdisk command can also be used to display or manipulate disk partitions.
$ sudo cfdisk
Probably one of the most informative commands for looking at disk health is smartctl (part of smartmontools). While
the command generates a lot of output, it provides valuable measurements that might help you pinpoint disk
problems, particularly once you get used to working with its extensive output.
6/6