The disk is a very important hardware resource in Linux system, how to manage them effectively is directly related to performance of the whole system. If you have some experiences on the Linux disk management and should know that “df”, “du” and “fdisk” these three commands: df is used to check the file system disk usage, du checks a disk space usage, and fdisk is used to disk partition.
1. df
df command can get how much space is occupied and how much availabe space is left, it cal also display the usage information for both inode and disk blocks.
df command can get how much space is occupied and how much availabe space is left, it cal also display the usage information for both inode and disk blocks.
df options:
-a: show all file system disk usage -k: display output in K bytes -i: display inode infomation -t:Display disk space usage for each of the specified type of File system -T: display file system type
Sample outputs:
Display Each File System Disk Space Usage
Display Each File System Disk Space Usage
[root@devops ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/xvda1 20641404 1165572 18427308 6% / tmpfs 250416 0 250416 0% /dev/shm /dev/xvdb1 10317828 2392496 7401216 25% /media/
- The first column of Filesystem is the device file path name of file system (usually the hard disk partitions);
- The second column of Inodes is the amount of inode of data block.
- The third and fourth columns are the amount of used and available data block number.you may feel strange, why the total block number for third and fourth columns is not equal to the amount in the second column. because each partition left little space for the system administrator by default. Even the ordinary user space is full, there are still have spaces so that administrator can login to solve the problem.
Show Inode Ssage For Each File System
[root@devops ~]# df -ia Filesystem Inodes IUsed IFree IUse% Mounted on /dev/xvda1 1310720 26718 1284002 3% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts tmpfs 62604 1 62603 1% /dev/shm xenfs 0 0 0 - /proc/xen
Show File System Type
[root@devops ~]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/xvda1 ext3 20641404 1165580 18427300 6% / tmpfs tmpfs 250416 0 250416 0% /dev/shm /dev/xvdb1 ext3 10317828 2392612 7401100 25% /media
2. du
du is the abbreviation of “disk usage”, this command will progressively into each subdirectory of the specified directory and display how many blocks were occupied. If not given a specified directory, then will show the statistics of the current directory.
du options:
-a:write counts for all files, not just directories -s: display only a total for each argument -b: display output in bytes( the default is K) -k: display output in K bytes -c: produce a grand total -l: count sizes many times if hard linked
Sample output:
Check The Disk Space Usage For /mnt Directory
[root@devops ~]# du -abk /mnt 4 /mnt
Display The Disk Space Usage Of Each Directory(do not include FILE)
[root@devops boot]# du 252 ./efi/EFI/redhat 256 ./efi/EFI 260 ./efi 288 ./grub 19804 .
Display The Disk Usage For All Of File And Directory(pass -a option) and display output in bytes(pass -b option)
[root@devops]# du -ab /boot/ 166 /boot/.vmlinuz-2.6.32-279.el6.x86_64.hmac 13057907 /boot/initramfs-2.6.32-279.el6.x86_64.img 3986608 /boot/vmlinuz-2.6.32-279.el6.x86_64 179157 /boot/symvers-2.6.32-279.el6.x86_64.gz 101820 /boot/config-2.6.32-279.el6.x86_64 249106 /boot/efi/EFI/redhat/grub.efi 253202 /boot/efi/EFI/redhat 257298 /boot/efi/EFI 261394 /boot/efi 2341856 /boot/System.map-2.6.32-279.el6.x86_64 64 /boot/grub/device.map 11364 /boot/grub/vstafs_stage1_5
3. fdisk
fdisk can be used to manage disk partitions, you can create a new paritition, delete an existing partition…
the below let us see how to use fdisk command:
Warning:if you don't know what you are doing, pls don't delete paritition or modify partition, or you may will lost your data in disk!!
Display All Existing Disk Partitions With -i Option
Before you need to create one new disk parititon or modify paritiion, you may need to know which disk is availabe now, then “fdisk -l” is a best command to get those information.
Before you need to create one new disk parititon or modify paritiion, you may need to know which disk is availabe now, then “fdisk -l” is a best command to get those information.
[root@devops ~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00073f45 Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x44cd3aea Device Boot Start End Blocks Id System /dev/xvdb1 1 1305 10482381 83 Linux
Display All Fdisk Command Option Using “m” Command
Enter the following command:
[root@AY130531111251020ecaZ ~]# fdisk /dev/xvdb1 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x15bea85f. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): m // input "m" command 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) Command (m for help):
Normally, we should print the partition table using “p” command, so that we can get all avavilable partition info.
[root@devops ~]# fdisk /dev/sdh WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/sdh: 2003 MB, 2003828736 bytes 64 heads, 32 sectors/track, 1911 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x49e2fd2f Device Boot Start End Blocks Id System /dev/sdh1 5 900 917504 5 Extended /dev/sdh4 * 1 4 4080 4 FAT16 <32m 112624="" 254="" 255984="" 255="" 292848="" 504="" 505="" 5="" 614="" 615="" 6="" 900="" are="" command="" dev="" disk="" entries="" fat16="" fc="" for="" help="" in="" m="" not="" order="" partition="" pre="" sdh5="" sdh6="" sdh7="" sdh8="" table="" vmkcore="" vmware="">Delete A Partition Using “d” Command[root@devops ~]# fdisk /dev/sdh WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): d Partition number (1-9): 8Create A New Disk Partition Using “n” CommandCommand (m for help): n Command action e extended p primary partition (1-4) p Partiton number(1-4):1 First cylinder(1023-2048):1 Last cylinder or + size or +sizeK or + sizeM(1023-2048):After you created new parition or modified one pairtition, you need save your change with “w” command. if you do not save your change, just using “q” command and exit fdisk directly.32m>
0 comments:
Post a Comment