Wu Yuxiong - natural born Linux operating system: Linux disk management

Linux disk management is directly related to the performance of the whole system. 
Linux disk management commands used three to df, du, and fdisk. 
df: lists the file system of the overall disk usage 
du: Check disk space usage 
fdisk: a disk partition
df 
df command parameters Function: Check the file system disk space occupancy. You can use this command to obtain the hard drive is taking up much space, how much space is left in the current information. 
Syntax: 
DF [ - ahikHTm] [directory or filename] 
options and parameters:
 -a: List all file systems, including system-specific / proc file system and the like;
 - K: Display each file system with a capacity of KBytes;
 - m: MBytes displayed in the capacity of each file system;
 - H: people to easily read GBytes, MBytes, KBytes own display format;
 -H: in m = m = 1000K unsubstituted carry embodiment of 1024K;
 - T: display file type system, together with the partition of the filesystem name (e.g., ext3) also lists;
 - I: no hard disk capacity, and the inode number to be displayed 
example 1 
lists all the file systems within the system! 
[the root WWW @ ~] # DF 
the Filesystem 1K-Blocks Used the Available the Use% Mounted ON
/ dev / HDC2 9,920,624 3,823,112 5585444 41 is% / 
/ dev / hdc3 4,956,316 141 376 4559108. 4% / Home
 / dev / hdc1 101 086 11126 84741 12 is% / Boot 
tmpfs               371 332 0 371 332 0% / dev / SHM 
in Linux underneath if df does not add any option, then the system will default within all (in the file system and swap excluding special memory) are at 1 Kbytes capacity to be listed!
Example 2 
The capacity results are displayed in readable volume format 
[the root WWW @ ~] # DF -H 
the Filesystem Size Used Avail the Use% Mounted ON
 / dev / 3.7G 5.4G 41 is 9.5 g of HDC2% / 
/ dev / 4.8G hdc3 4.4G. 4% 139M / Home
 / dev / 99M 11M 83M 12 is hdc1% / Boot 
tmpfs 363M 0 363M 0 % / dev / SHM
Example 3 
All the special file formats and names are listed in the system will be 
[the root WWW @ ~] # DF -at 
the Filesystem the Type 1K-Blocks Used the Available the Use% Mounted ON
 / dev / HDC2 ext3 9,920,624 5,585,444 41 is 3823112% / 
proc proc 0 0 0    - / proc 
the sysfs the sysfs 0 0 0    - / SYS 
the devpts the devpts 0 0 0    - / dev / PTS
Example 4 
The / etc under the available disk capacity is displayed in readable format capacity 
[the root WWW @ ~] # DF -H / etc 
the Filesystem Size Used Avail the Use% Mounted ON
 / dev / 3.7G 5.4G 41 is 9.5 g of HDC2% /
du 
Linux du command also see the use of space, but with a different command df is Linux du command is the disk space the files and directories used to view, or df command and there are some differences, introduce Linux du command here. 
Syntax: 
du [ - ahskm] file or directory name 
options and parameters:
 - A: Lists all files and directories capacity because the amount of the default file under the directory only statistics only.
-h: people to easily read volume format (G / M) display;
 - S: total listed only without listing each respective directory empty capacity;
 -S: Total does not include subdirectories , and - S a little different.
- K: capacity display lists in KBytes;
 - m: MBytes listed in the display capacity; 
Example . 1 
only lists all files in the folder capacity in the current directory (including hidden folder): 
[the root WWW @ ~] # du 
. 8. / test4 <== each directory will be listed
 . 8 ./ test2 
.... .... omitted intermediate
 12 ./.gconfd <== includes hidden file directory
220. <== This directory (.) Occupied by the total amount of 
direct input is not the time du plus any options, du will analyze the current file and directory disk space occupied by the directory. 
Example 2 
capacity will be listed file 
[the root WWW @ ~] # du -a 
12 is ./install.log.syslog <== have a list of files
 . 8 ./ .bash_logout
 . 8 ./ Test4
 . 8 ./ test2 
.. .. .... omitted intermediate
 12 ./.gconfd
Example 3 
checks each directory under the root directory of the volume occupied by 
[the root WWW @ ~] # du -sm / * 
. 7 / bin
 . 6 / Boot 
..... .... intermediate omitted 
0        / proc 
..... omitting the middle ....
 1 / tmp
 3859 / usr <== initial maximum system it is him!
77 / var

* Wildcard to represent each directory.

And is not the same as df, du command will actually directly into the file system to find all the file data.

fdisk 
fdisk is a Linux disk partition table manipulation tools. 
Syntax: 
the fdisk [ - L] means the name of 
the option parameter:
 -l: rear contact means output the contents of all partitions. If only fdisk - when l, the system will be able to find a partition of the entire system of the apparatus are listed. 
Example 1 
lists all the partition information 
[the root @ AY120919111755c246621 tmp] # the fdisk -l 

Disk / dev / xvda: 21.5 GB, 21,474,836,480 bytes
 255 Heads, 63 is sectors / Track, 2610. Cylinders 
Units = Cylinders of 16065 * 512 = 8.22528 million bytes 
Sector size (Logical / PHYSICAL): 512 bytes / 512 bytes
Examples 2 
to find out where the root directory of the disk in your system, and access to relevant information in the hard disk 
[the WWW root @ ~] # df / <== Note: Key in the file name to find the disk just 
Filesystem 1K-blocks Used Available Use % Mounted ON
 / dev / hdc2 9920624 3823168 5,585,388 41% / 

[root @ the WWW ~] # fdisk / dev / HDC <== closer look, do not add a digital Oh! 
Number The Cylinders of at The for the this Disk IS the SET to 5005 . 
There IS Nothing Wrong with that, But the this IS larger Within last 1024 ,
 and could in Certain Problems with the cause is Setups:
 1) That the runs AT Boot Time Software (EG, Old versions of the LILO)
 2) the Booting and Partitioning Software from OTHER OSs only. 
   (EG, the FDISK the DOS, the OS / 2 the FDISK) 

the Command (m for Help): <== wait for your input! 
After entering m, these commands will see below describes 
the Command (m for Help): m <== enter m, these commands will see below describes 
the Command Action 
   A Toggle A Bootable In Flag 
   B Edit the disklabel BSD 
   C Toggle The DOS In Flag Compatibility 
   D a delete Partition             <== delete a Partition 
   L List Known types Partition 
   m    Print the this MENU
   A new new Partition the Add n-            <== add a Partition 
   O Create new new empty the DOS Partition Table A 
   P    Print The Partition Table <== displayed on the screen division table 
   Q quit the without Saving Changes    <== not leave the reservoir fdisk program 
   s create a the Sun the disklabel empty new new 
   T Change a Partition ' S System ID 
   U Change the display / entry Units 
   V Verify the Partition table 
   W to Disk write table and Exit <== will just write operation partition table 
   x extra functionality (experts only) 
leaving fdisk when you press q, then all the action will not take effect! Instead, the operation means is press w effect. 
The Command (m forhelp): p <== herein may output the current status of the disk 

Disk / dev / HDC: 41.1 GB, 41,174,138,880 bytes <== this disk file name and capacity
 255 heads, 63 sectors / track, 5005 cylinders <== head, a sector size cylinders 
Units = cylinders of 16065 * 512 = 8.22528 million bytes <== size of each of cylinders 

   Device Id the Boot the Start End Blocks the System
 / dev / hdc1. 1 * 104 391 83 13 is   the Linux
 / dev / HDC2 14 1288 10241437+ 83   the Linux
 / dev / hdc3 83 1289 1925 5116702+   the Linux
 / dev / hdc4 1926 5005 24.7401 million. 5   Extended
 / dev / 2052 1020096 82 1926 hdc5 the swap the Linux /The Solaris
 # device filename promoter No Start cylinders last cylinder capacity of 1K size of the disk partition tank system 

the Command (m for Help): q 
want to leave without saving it? Press q on the right! Do not press w ah! 
Use p to list the current partition table information Fengyun disks, the upper half of the information displayed in the status of the entire disk. 
Disk format 
after the completion of the disk split nature is to format the file system, formatted command is very simple to use mkfs (make filesystem) command. 
Syntax: 
mkfs [ - t file system format] device filename 
options and parameters:
 - t: you can access the file system format, such as ext3, ext2, vfat, etc. (support system to take effect) 
Examples 1 
View mkfs supported file formats 

[ @ WWW the root ~] # mkfs [Tab] [Tab] 
mkfs mkfs.cramfs the mkfs.ext2 the mkfs.ext3 mkfs.msdos mkfs.vfat 

press two [tab], will find a supported file format mkfs shown above. 
Example 2 
partition / dev /hdc6 (partition may specify your own) ext3 file system formatted as: 
[the root WWW @ ~] # the mkfs -t ext3 / dev / hdc6 
the mke2fs 1.39 (29-On May-2006 ) 
the Filesystem label = <== herein refers to a dividing grooves name (label) 
the OS type: the Linux 
Block size = 4096 (log = 2) <== Block size configured 4K 
Fragment size = 4096 (log = 2 )
 251 392 of inodes, Blocks 502 023 <== configuration decisions whereby the inode / number Block
 25101 Blocks (5.00%) Reserved for the Super User 
First Data Block = 0 
the Maximum filesystem Blocks = 515 899 392 
16 Block Groups
 32768 Blocks per Group, 32768per Group fragments
 15712 of inodes per Group 
of Superblock Backups Stored ON Blocks:
         32768, 98304, 163840, 229376, 294 912 

Writing the inode Tables: DONE 
Creating TECHNOLOGY ( 8192 Blocks): DONE <== have logging 
Writing superblocks and filesystem accounting Information: DONE 

This Automatically the checked by will BE Every filesystem 34 mounts or 
180 Days, whichever Comes First the Use tune2fs -c. or - . i to the override
 # this will create up Ext3 file system we need it! simple and clear!
Disk test 
fsck (file system check) for inspection and maintenance inconsistent file system. 
If the system is powered down or disk problems occur, you can check the file system using the fsck command. 
Syntax: 
fsck [ -t File System] [- Acay] device name 
options and parameters:

 type of a given file system, if the / etc /: -t has been defined in fstab or kernel itself plus you do not need support this parameter
 - S: sequentially one by one to check the fsck command execution
 -A: on / etc / fstab all listed partitions (partition) for examination
 - C: show the full check progress
 - D: Print out the e2fsck results debug
 -p: while - when the condition a, while a plurality of inspection performed with fsck
 -R: -A while when conditions are omitted / not checked
 - V: detailed display mode
 - a: If the check is wrong automatically repair
 - r: If the check is wrong by the user to answer whether the repair
 -y: option specifies detect each file is automatically entered yes, the uncertainty that is not normal, they can execute # fsck -y to check all repair.
Examples 1 
to view the system how many file system supports fsck command: 
[root @ the WWW ~] # fsck [the Tab] [the Tab] 
fsck fsck.cramfs fsck.ext2 fsck.ext3 fsck.msdos fsck.vfat 

example 2 
mandatory testing / dev / hdc6 partition: 
[the root WWW @ ~] # the fsck -t ext3 -C -f / dev / hdc6 
the fsck 1.39 (29-On May-2006 ) 
the e2fsck 1.39 (29-On May-2006 ) 
Pass . 1: Checking of inodes, Blocks, and sizes 
Pass 2 : Checking Directory Structure 
Pass 3 : Checking Directory Connectivity 

If you do not add-f option, because the file system did not have problems, check through a very fast! If coupled with -f Force checking, appear one by one in the process.
Disk mount and dismount 
Linux disk mounted using the mount command, uninstall using the umount command. 

Disk Mount Syntax: 
Mount [ -t file system] [-L Label Name] [-o extra options] [- the n-] device filename mount point 

example 1 
with the default way that will just create / dev / hdc6 hanging upload to / mnt / hdc6 above! 

[the root WWW @ ~] # mkdir / mnt / hdc6 
[the root WWW @ ~] # Mount / dev / hdc6 / mnt / hdc6 
[the root WWW @ ~] # DF 
the Filesystem 1K-Blocks Used the Available the Use% Mounted ON 
.... the middle omitted .....
 / dev / hdc6 1,976,312 42072 1833836 3% / mnt / hdc6 

disk umount uninstall command syntax: 
options and parameters:

 - f: a forced dismount! Available under similar Network File System (NFS) Unable to read;
-n: Do not upgrade / etc / lower case mtab removed. 

Unloading / dev / hdc6 
[the root WWW @ ~] # umount / dev / hdc6     

 

Guess you like

Origin www.cnblogs.com/tszr/p/12110167.html