LINUX磁盘管理

来源:互联网 发布:jsmd5解密算法 编辑:程序博客网 时间:2024/06/03 12:41

概述:

《跟阿铭学Linux》

1、查看磁盘或者目录的容量

命令:df

-i : 查看inodes使用状况

-h:显示单位为G

-k :显示单位K

-m:显示单位M

[root@iz8vb7xp3jz ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on/dev/vda1        40G  1.8G   36G   5% /devtmpfs        487M     0  487M   0% /devtmpfs           497M     0  497M   0% /dev/shmtmpfs           497M  356K  496M   1% /runtmpfs           497M     0  497M   0% /sys/fs/cgrouptmpfs           100M     0  100M   0% /run/user/0

命令:du (用来查看某个目录或文件所占空间大小)

-a :全部文件与目录大小都列出来。如果不加任何选项和参数只列出目录(包含子目录)大小

-b: 列出的值以bytes为单位输出

-k:列出的值以kb为单位输出(默认输出的单位)

-m :列出的值以MB为单位输出

-h:系统自动调整单位。根据实际情况显示K、或G

-c:最后加总

-s : 只列出总和

[root@iz8v3jz ~]# du /home16      /home/user116      /home/usertest116      /home/test1016      /home/user1220      /home/test88      /home
[root@iz8v6fxp3jz ~]# du -h /home16K     /home/user116K     /home/usertest116K     /home/test1016K     /home/user1220K     /home/test88K     /home[root@iz8vb7cfxp3jz ~]# du -s /home88      /home

2、磁盘的分区和格式化


命令:fdisk

-l :列出所有分区信息

[root@iz8vb7cc5e91muwr6fxp3jz ~]# fdisk -lDisk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0000efd2   Device Boot      Start         End      Blocks   Id  System/dev/vda1   *        2048    83886079    41942016   83  Linux

执行分区命令:

[root@iz8vb7cc5e91muwr6fxp3jz ~]# fdisk /dev/vdaWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition   g   create a new empty GPT partition table   G   create an IRIX (SGI) partition table   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)
-p :打印当前磁盘的分区情况

-n:建立一个新的分区

-w:保存操作(操作之后需要保存才会生效)

-q :退出

-d :删除一个分区

3、格式化磁盘分区

命令:mke2fs, mkfs.ext2, mkfs.ext3, mkfs.ext4

`-b' 分区时设定每个数据区块占用空间大小,目前支持1024, 2048 以及4096 bytes每个块。
`-i' 设定inode的大小
`-N' 设定inode数量,有时使用默认的inode数不够用,所以要自定设定inode数量。
`-c' 在格式化前先检测一下磁盘是否有问题,加上这个选项后会非常慢
`-L' 预设该分区的标签label
`-j' 建立ext3格式的分区,如果使用mkfs.ext3 就不用加这个选项了
`-t' 用来指定什么类型的文件系统,可以是ext2, ext3 也可以是ext4.

命令:e2label 

用于查看或修改分区的标签


4、挂载/卸载磁盘

命令:mount

要将磁盘挂载到对应的目录下


5、磁盘配额

命令:quota (每个用户的用的磁盘资源是有限制的)

命令:edquota (用来编辑某个用户或组的quota的值)

命令:quotaon (启动quota,在编辑好quota才能生效)

命令:quotaoff(关闭quota)

由于采用阿里云服务器,好像这些操作没有用。。。