linux 学习随笔-磁盘管理

1:df 用于查看已挂载磁盘的容量信息

-i 查看inodes使用情况
-h 以合适的单位显示
-k -m 分别以k M单位显示
2:du 查看某个文件或者目录占用的空间 du [-abckmsh] [文件名目录名]
du + 目录 只会列出目录及其子目录的大小
du -a +目录 会列出目录子目录及文件的大小
常用 du -sh +目录 表示以合适的单位列出总和
2:磁盘分区
fdisk -l 列出当前所有的分区情况
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x00000000
可以看到/dev/sdb为新增的一块磁盘,还没有进行分区。输入fdisk /dev/sdb
fdisk不加l可以进入另一个模式,开始分区。
输入p打印当前分区情况:
Command (m for help): p
 
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x2543f3b6
 
   Device Boot      Start         End      Blocks   Id  System
可以看到,还没有进行分区,输入n 建立分区:
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x2543f3b6
 
   Device Boot      Start         End      Blocks   Id  System
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
输入p(主分区):
Partition number (1-4): 1
First cylinder (1-1044, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +1000M
依次输入分区数量,分区其实位置,结束位置即大小
输入p查看:
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x2543f3b6
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         128     1028128+  83  Linux
第一个分区创建完成。
linux最多支持创建4个主分区,如果还需要创建更多的分区,需要使用命令删除第4个分区,在输入n创建分区时选择扩展分区。如下所示
Disk /dev/sdb: 8589 MB, 8589934592 bytes 
255 heads, 63 sectors/track, 1044 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: 0x2543f3b6
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         128     1028128+  83  Linux
/dev/sdb2             129         256     1028160   83  Linux
/dev/sdb3             257         384     1028160   83  Linux
/dev/sdb4             385        1044     5301450    5  Extended
/dev/sdb4 为扩展分区,最好把剩余的空间分配给扩展分区,扩展分区不能格式化,以后创建的主分区是从扩展分区中分配出来的称为逻辑分区。
在使用d命令删除分区时,如果删除了扩展分区,那么他下面的子分区即逻辑分区就会被删除。
在完成分区后,输入w保存退出。
3:格式化分区
mke2fs 
-t 指定文件系统类型
mke2fs -t ext4 /dev/sdb5 指定文件系统为ext4格式 默认的块大小为4kb。linux写入文件是一个块一个块的写入,比如写入1个5k文件,则会存在2个块上。
-L 指定标签 -p 指定块大小 1024的整数倍如:
 mke2fs -t ext4 -L TEST -b 8192 -c /dev/sdb5
4:挂载磁盘
在完成磁盘分区和格式化后,需要建立一个挂载点即目录,才能往磁盘写入数据
 mount /dev/sdb5 newdir/ 挂载该分区
df -h 查看挂载的目录信息
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_flex-lv_root
                       18G  3.5G   13G  22% /
tmpfs                 932M     0  932M   0% /dev/shm
/dev/sda1             477M   37M  415M   9% /boot
/dev/sdb5             973M  1.3M  921M   1% /home/flex/newdir
可以看到 sdb5分区挂载成功
5:在/etc/fstab 文件中增加一行
/dev/sdb5               /home/flex/newdir                 ext4    defaults        0 0
这个文件中列出了系统启动时需要挂载的各个分区
umount /dev/sdb5 卸载掉sdb5挂载的分区
mount -a 会执行这个文件中指定的挂载文件
posted @ 2016-05-25 23:27  flex-  阅读(424)  评论(0编辑  收藏  举报