Linux常用命令(4)-磁盘管理

案数据除了档案实际内容外, 通帯有非帯多癿属性,例如 Linux 操作系统的档案权限(rwx)和文件属性(拞有者、群组、时间参数等)。 
文件系统会将这两部数据分别存放在不同的区块,权限属性放置到 inode 中,至亍实际数据则放置到 data block 区块中。 另外,还有一个超级区块 (superblock) 会记彔整个
文件系统癿整体信息,包括 inode 不 block 癿总量、使用量、剩余量等。 
每个inode与block 都有编号,三者数据的含义可以简略说明如下: 
superblock:记录此 filesystem的整体信息,包括 inode/block的总量、使用量、剩余量, 以及文件系统癿格式不相关信息等; 
inode:记彔档案的属性,一个档案占用一个 inode,同时记彔此档案的数据所在的 block 号码; 
block:实际记彔档案癿内容,若档案太大时,会占用多个 block。
文件系统的简单操作
#df -k 列出文件系统的整体磁盘使用量。单位是k, 可选参数[k],[m],[i]inodes 显示inode信息。 df 主要读叏癿数据几乎都是针对一整个文件系统,因此读取的范围主要是在Superblock内的信
息。
# df -m /home
Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/sda8                12084      4833    6638    43% /home

#du -k 评估文件或者目录的磁盘使用量.可选参数[k],[m],[s]表示求和只输出总容量
# du -k /home/chenlly/eclipse/configuration
104     /home/chenlly/eclipse/configuration/org.eclipse.equinox.simpleconfigurator
8       /home/chenlly/eclipse/configuration/org.eclipse.equinox.source
36      /home/chenlly/eclipse/configuration/org.eclipse.update
156     /home/chenlly/eclipse/configuration

如果你叧想要知道该目彔占了多少总容量的话用-s
# du -s /home/chenlly/eclipse/configuration
156     /home/chenlly/eclipse/configuration
#df -h      要查看磁盘还剩多少空间
#du -sh *   你是需要知道当前的文件夹下的磁盘使用情况
# mount      加载文件系统
在弄清楚mount之前要弄清的概念:
设备一般在/dev目录里 /dev/hda1  hd表示硬盘 fd 表示软盘 eth 网络设备(eth0 第一个网络设备)  a标识第一个设备,通常一个设备接口可以接四个设备(如四个硬盘),1表示第一个分区,所以hdb2表示的是第二块硬盘的第二个分区
mount -t vfstype 显示被加载文件系统的类型
比如,要访问CD-ROM里的内容,需要将CD-ROM设备挂载在某个文件下,Linux可以标识的文件系统有如下几种
FAT32 :vfat
NTFS :ntfs
CD-ROM:iso9660
Linux文件系统:EXT2  EXT3
应用:mount -t iso9660  /dev/hdc/mnt/cdrom  将CD-ROM 挂载在mnt/cdrom下,一般在mnt下有如下目录:mnt/cdrom,mnt/floppy
比如利用mount挂载windows下的c盘  ,首先在mnt下新建winc目录
mkdir winc
mount -t vfat /dev/hda1/mnt/winc
unmount 卸载文件系统
unmount  /cdrom
eg:CentOS挂载新硬盘
1.查看当前硬盘使用状况:
df -h
2.查看新硬盘,Disk /dev/sda 4T的硬盘是需要挂载的。
#fdisk –l 

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              64       36405   291908608   8e  Linux LVM

Disk /dev/sda: 4000.8 GB, 4000787030016 bytes
255 heads, 63 sectors/track, 486401 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: 0xa820dbce

Disk /dev/mapper/VolGroup-LogVol01: 264.6 GB, 264551530496 bytes
255 heads, 63 sectors/track, 32163 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

Disk /dev/mapper/VolGroup-LogVol00: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 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

3、硬盘分区,由于centOS 只能一次挂载2T。所有4T的需要分两个区
#sudo fdisk /dev/sda
Command (m for help):m
(1)、输入m 进入帮助界面
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)

(2)、 输入n 添加分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
(3)、选择分区数
Partition number (1-4): 2
(4)设置柱面,这里选择默认值就可以 
First cylinder (267350-486401, default 267350): 267350
Last cylinder, +cylinders or +size{K,M,G} (267350-486401, default 486401): 486401

4、挂载分区
# fdisk -l 查看分区情况

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              64       36405   291908608   8e  Linux LVM

Disk /dev/sda: 4000.8 GB, 4000787030016 bytes
255 heads, 63 sectors/track, 486401 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: 0xa820dbce

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1      267349  2147480811   83  Linux
/dev/sda2          267350      486401  1759535190   83  Linux

Disk /dev/mapper/VolGroup-LogVol01: 264.6 GB, 264551530496 bytes
255 heads, 63 sectors/track, 32163 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

Disk /dev/mapper/VolGroup-LogVol00: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 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/sda1和/dev/sda2两个分区
(1)、新建目录maphd1和maphd2 用于挂载/dev/sda1 和 /dev/sda2两个分区
(2)、在挂载之前先格式化
# mkfs.ext4 /dev/sda1
# mkfs.ext4 /dev/sda2
(3)、分别挂载
# mount /dev/sda1 /maphd1
# mount /dev/sda2 /maphd2

5. 设置开机启动自动挂载 
新创建的分区不能开机自动挂载,每次重启机器都要手动挂载。 
    设置开机自动挂载需要修改/etc/fstab文件 
    #vi /etc/fstab 
    在文件的最后增加一行 
    /dev/sda1 /maphd1 ext4 defaults 1 2 
    /dev/sda1 /maphd1 ext4 defaults 1 2 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。