linux View Hard Disk Size and Mount Hard Disk Implementation
- 2021-06-28 14:34:53
- OfStack
linux has both mounted and unmounted hard disks (similar to hard disk partitions on windows (C, D, E disks))
(1) View the size of the mounted hard disk: df-h
(2) View detailed hard disk partitions (including both mounted and unmounted hard disk sizes): fdisk-l
Introduction:
(1) df is used to check file system disk usage
(2) du checks disk space usage
(3) fdisk for disk partitioning
Details:
1.df
The df command can get information about how much space has been occupied on the hard disk and how much space is left. It can also show the usage of i nodes and disk blocks by all file systems.
The various options of the df command mean the following:
-a: Displays disk usage for all file systems, including 0 block (block) file systems, such as/proc file systems.
-k: Displays in k bytes.
-i: Displays i node information, not disk blocks.
-t: Displays disk space usage for each specified type of file system.
-x: Lists disk space usage for file systems of a type other than 1 (as opposed to the t option).
-T: Displays the file system type.
Let's first look at an example of using the df command:
// List disk space usage for each file system
#df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda5 381139 332921 28540 93% /
/dev/hda1 46636 6871 37357 16% /boot
/dev/hda3 10041144 6632528 2898556 70% /home
none 127372 0 127372 0% /dev/shm
/dev/hda2 27474876 24130460 1948772 93% /usr
/dev/hda6 256667 232729 10686 96% /var
The first column is the path name of the device file that represents the file system (1 is usually a partition on the hard disk);Column 2 gives the number of data blocks (1024 bytes) that a partition contains.Columns 3 and 4 represent the number of data blocks used and available, respectively.
Users may wonder that the sum of the blocks in columns 3 and 4 is not equal to the number of blocks in column 2.This is because each partition by default leaves a small amount of space for system administrators to use.Administrators can log in and leave the workspace they need to solve problems even when the normal user space is full.The Use% column in the list represents the percentage of normal user space usage, and if this number reaches 100%, the partition still has room for system administrators.
Finally, the Mounted on column represents the installation point of the file system.
// List the file systems i Node usage.
#df - - /proc
/dev/hda1 12048 38 12010 1% /boot
none 0 0 0 ia
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/hda5 98392 23919 74473 25% /
none 0 0 0 - /dev/pts
/dev/hda3 1275456 355008 920448 28% /home
none 31843 1 31842 1% /dev/shm
/dev/hda2 3489792 133637 3356155 4% /usr
/dev/hda6 66264 9876 56388 15% /var
// Lists the types of file systems.
#df -T
Filesystem Type 1k-blocks Used Available Use% Mounted on
/dev/hda5 ext3 381139 332921 28540 93% /
/dev/hda1 ext3 46636 6871 37357 16% /boot
/dev/hda3 ext3 10041144 6632528 2898556 70% /home
none tmpfs 127372 0 127372 0% /dev/shm
/dev/hda2 ext3 27474876 24130460 1948772 93% /usr
/dev/hda6 ext3 256667 232729 10686 96% /var2
2.du
du, in English, means "disk usage". It means to show the usage of disk space and to count the amount of disk space occupied by a catalog (or file).The function of this command is to step into each subdirectory of the specified directory and display how the directory occupies a file system data block (1024 bytes).If the specified directory is not given, the current directory is counted.
The options for the df command mean the following:
-s: Only the total number of data blocks occupied is given for each Names parameter.
-a: Recursively displays the number of data blocks occupied by each file in a specified directory and by each file in a subdirectory.If neither -s nor -a is specified, only the number of disk blocks per directory and subdirectories in Names is displayed.
-b: Lists disk space usage in bytes (system defaults to k bytes).
-k: Lists disk space usage in 1024 bytes.
-c: Add one more total (system default).
-l: Compute all file sizes, and for hard-linked files, multiple times.
-x: Skip directories on different file systems and do not count.
-h: Convert to a readable display of 2M, 2G.
The following examples illustrate the use of the du command:
// See /mnt Disk space occupied by directories
#du � abk /mnt
1 /mnt/cdrom
1 /mnt/floppy
3 /mnt
// Lists the disk space occupied by each directory, but does not detail the space occupied by each file
#du
3684 ./log
84 ./libnids-1.17/doc
720 ./libnids-1.17/src
32 ./libnids-1.17/samples
1064 ./libnids-1.17
4944 .
The first column in the output list is the disk space capacity in blocks, and the second column lists the name of the directory in which the space is used in the directory.
This may be a very long list, sometimes only a total is required.You can then add the -s option to the du command to get the total number:
#du � s /mnt
3 /mnt
// List the space occupied by all files and directories (using a Option) in bytes (using b Option) to calculate size
#du � ab /root/mail
6144 mail/sent-mail
1024 mail/saved-messages
8192 mail
3. fdisk
fdisk can partition disks.The following steps are given for partitioning disks using the Fdisk command:
#fdisk /dev/had // Use /dev/had As default partition device
Command (m for help): m // Choose Command Options
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
By prompting the user to type "m", you can display a description of each parameter of the Fdisk command.
Fdisk has many parameters, but only a few are commonly used.
In the Linux partitioning process, 1 generally displays the hard disk partition table information through the p parameter, and then determines the future partitions based on the information.As follows:
Disk /dev/sda: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 41 522 3871665 83 Linux
/dev/hda2 1 40 321268+ 82 Linux swap
Partition table entries are not in disk order
Command (m for help):
If you want to completely change the partition format of the hard disk, you can delete the existing hard disk partitions one by one through the d parameter.Once deleted, new partitions can be added through the n parameter.When you press "n", you can see the following:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partiton number(1-4):1
First cylinder(1-1023):1
Last cylinder or + size or +sizeK or + sizeM(1-1023):+258M
Here you choose the new partition type, primary or extended partition.And select p or e.Then set the size of the partition.
_It is important to note that if there are extended partitions on the hard disk, only logical partitions can be added, not extended partitions.
When adding partitions, their types are the default Linux Native. If you want to change some of them to other types, such as Linux Swap or FAT32, you can change them by commanding t. When you press "t" to change the partition type, you will be prompted which partition to change.And why change the type (type l if you want to know the partition type supported by the system), as follows:
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap)
After changing the partition type, you can press "w" to save and exit.If you do not want to save, you can choose "q" to exit directly, as follows:
Command (m for help) : w
By doing so, you can successfully partition your disks as needed.