文件系统管理
2016-08-04 21:50
288 查看
添加一块新硬盘第一步:查看添加的硬盘、分区
第二步:创建文件系统
第三步:查看文件系统属性
第四步:修改文件系统属性
第五步:文件系统检测
第六步:文件系统的挂载
第七步:文件系统的卸载
第八步:交换分区的创建、启用和禁用
补充:
fdisk - manipulate disk partition table # fdisk -l device [OPTION] -l List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used. # fdisk device fdisk提供了一个交互式接口来管理分区,它有许多子命令,分别用于不同的管理功能 所有操作均在内存中完成,没有直接同步到磁盘,知道使用w命令保存此磁盘上 常用命令: (m for help) n add a new partition d delete a partition t change a partition's system id l list known partition types w write table to disk and exit q quit without saving changes p print the partition table 注意:在已经分区并且已经挂载其中某个分区的磁盘设备上创建新分区, 内核可能在创建完成后无法直接识别 通知内核强制重读磁盘分区表: centos 5 :partprobe centos 6,7:partx,kpartx partx - tell the Linux kernel about the presence and numbering of on-disk partitions # partx -a device -a, --add Add the specified partitions, or read the disk and add all partitions kpartx - Create device maps from partition tables # kpartx -af device -a Add partition mappings -f force creation of mappings; overrides 'no_partitions' feature
第二步:创建文件系统
ext系列文件系统专用管理工具:mke2fs mke2fs - create an ext2/ext3/ext4 filesystem -t {ext2|ext3|ext4}:指明要创建的文件系统类型 -t fs-type Specify the filesystem type (i.e., ext2, ext3, ext4, etc.) that is to be created -b{1024|2048|4096}:指明文件系统的块大小 -b block-size -b block-size Specify the size of blocks in bytes. Valid block-size values are 1024 2048 and 4096 bytes per block -L label:指明卷标 -L new-volume-label -L new-volume-label Set the volume label for the filesystem to new-volume-label. The maximum length of the volume label is 16 bytes. -j:创建有日志功能的文件系统ext3 -j Create the filesystem with an ext3 journal -i #:bytes-per-inode,指明inode与字节的比率;即每多少字节创建一个inode -i bytes-per-inode Specify the bytes/inode ratio -N #:直接指明要给此文件系统创建的inode的数量 -N number-of-inodes Overrides the default calculation of the number of inodes that should be reserved for the filesystem (which is based on the number of blocks and the bytes-per-inode ratio). -m #:指定预留的空间,百分比 -m reserved-blocks-percentage Specify the percentage of the filesystem blocks reserved for the super-user -O [^]FEATURE:以指定的特性创建目标文件系统
第三步:查看文件系统属性
e2label命令:卷标的查看与设定 e2label - Change the label on an ext2/ext3/ext4 filesystem e2label device [ new-label ] e2label will display or change the filesystem label on the ext2,ext3,or ext4 filesystem 查看:# e2label device 设定:# e2label device LABEL dumpe2fs:显示ext系列文件系统的属性信息 dumpe2fs - dump ext2/ext3/ext4 filesystem information [option] -h only display the superblock information and not any of the block group descriptor detail information. # dumpe2fs - [-h] device blkid命令 blkid - locate/print block device attributes # blkid device blkid -L label :根据LABEL定位设备 blkid -U uuid:根据UUID定位设备
第四步:修改文件系统属性
tune2fs查看后修改ext系列文件系统的某些属性 adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems 注意:块大小创建后不可修改; tune2fs [OPTIONS] device -l:查看超级块的内容 -l List the contents of the filesystem superblock, including the current values of the parameters that can be set via this program. 修改指定文件系统的属性: -j:ext2-->ext3; -j Add an ext3 journal to the filesystem -L label:修改-L volume-label 卷标 -L volume-label Set the volume label of the filesystem. -m #:调整预留空间百分比 -m reserved-blocks-percentage Set the percentage of the filesystem which may only be allocated by privileged processes. -O [^]FEATHER:开启或关闭某种特性 -O [^]feature[,...] -o [^]mount_options:开启或关闭某种默认挂载选项 acl ^acl
第五步:文件系统检测
fsck命令:用于实现文件系统检测的工具 因进程意外中止或系统崩溃等原因导致操作系统非正常终止时, 可能会造成文件损坏,此时,应该检测并修复文件系统 建议:离线进行; ext系列文件系统的专业工具; e2fsck:e2fsck - check a Linux ext2/ext3/ext4 file system e2fsck [OPTIONS] device -y:对所有问题自动回答为YES; -y Assume an answer of `yes' to all questions -f:即使文件系统处于clean状态,也要强制进行检测; -f Force checking even if the file system seems clean. fsck:fsck - check and repair a Linux filesystem -t:fstype:指明文件系统类型 fsck -t ext4 = fsck.ext4 -a:无须交互而自动修复所有错误 -a Automatically repair the filesystem without any questions (use this option with caution). -r:交互式修复 -r Interactively repair the filesystem (ask for confirmations).
第六步:文件系统的挂载
跟文件系统之外的其他文件系统要想能够被访问,都必须通过“关联”至跟文件系统上的某个目录来实现,此关联操作为“挂载”,此目录即为挂载点; 挂载点:mount_point,用于作为另一个文件系统的访问入口 挂载点: 1、事先存在的目录 2、最好应该使用未被或不会被其他进程使用到的目录 3、挂载点下原有的文件将会被隐藏 mount命令: mount - mount a filesystem mount [-nrw] [-t vfstype] [-o options] device dir 命令选项: -r:readonly,只读挂载 -w:write and read,读写挂载; -n:默认情况下,设备的挂载或卸载的操作会同步更新至/etc/mtab文件中,、 -n用于禁止此特性 -t:vfstype;指明要挂载的设备上的文件系统的类型;默认情况下可省略 此时mount会通过blkid来判断要挂载的设备的文件系统类型 -L:label;挂载时以卷标的方式指明设备 # mount -L LABEL dir -U uuid:挂载是以UUID的方式指明设备 # mount -U UUID dir -o:option;挂载选项 1、sync/async;同步/异步操作; 2、atime/noatime;文件或目录在被访问时是否更新其访问时间戳 3、diratime/nodiratime:目录在被访问时是否更新其访问时间戳 4、remount:重新挂载; 5、acl:支持使用facl功能,访问控制列表 # mount -o acl device dir # tune2fs -o acl device 6、ro:只读 7、rw:读写 8、dev/nodev;此设备上是否允许创建设备文件 9、exec/noexec:是否允许运行此设备上的程序文件 10、auto/noauto; 11、user/nouser;是否允许普通用户挂载此文件系统 12、suid/nosuid;是否允许程序文件上的suid和sgid特殊权限生效 defaults Use default options: rw, suid, dev, exec, auto, nouser, and async. 另一个使用技巧; 可以实现将目录绑定至另一个目录上,作为其临时访问入口; # mount --bind 源目录 目标目录 查看当前系统所有以挂载的设备; # mount # cat etc/mtab # cat /proc/mounts 挂载光盘: #mount -r /dev/cdrom mount_point 光盘设备文件:/dev/cdrom,/dev/dvd 挂载U盘 事先识别U盘的设备文件; 挂载本地的回环设备 # mount -o loop /path/to/some_loop_file MOUNT_POINT
第七步:文件系统的卸载
umount命令: # umount device|dir 注意:正在被进程访问到的挂载点无法被卸载 查看被哪个或那些进程所占用 lsof -- list open files # lsof MOUNT_POINT fuser - identify processes using files or sockets -v, --verbose Verbose mode. Processes are shown in a ps-like style. The fields PID, USER and COMMAND are similar to ps. ACCESS shows how the process accesses the file. Verbose mode will also show when a particular file is being access as a mount point, knfs export or swap file. In this case kernel is shown instead of the PID. # fuser -v MOUNT_POINT 终止所有正在访问某挂载点的进程 -m NAME, --mount NAME NAME specifies a file on a mounted file system or a block device that is mounted. All processes accessing files on that file system are listed. If a directory file is specified, it is automatically changed to NAME/. to use any file system that might be mounted on that directory. fuser -km /home kills all processes accessing the file system /home in any way. # fuser -km MOUNT_POINT
第八步:交换分区的创建、启用和禁用
swap文件系统: Linux上的交换分区,必须使用独立的文件系统; 其文件系统的system ID必须为82; 创建swap设备:mkswap命令 mkswap [OPTIONS] device -L label:指明卷标 -f:强制 free命令: -m mega Display the amount of memory in megabytes. -h, --human 交换分区的启用: 创建交换分区的命令;mkswap 启用:swapon # swapon [option] device -a:定义在/etc/fstab文件中的所有swap设备 交换分区的禁用:swapoff # swapoff DEVICE
补充:
设定除根文件系统以外的其它文件系统能够开机时自动挂载:/etc/fstab 每行定义一个要挂载的文件系统及相关属性: 6个字段: (1):要挂载的设备 设备文件 LABEL UUID 伪文件系统:如sysfs,proc,tmpfs等 (2):挂载点 swap类型的设备的挂载点为swap (3):文件系统类型 (4):挂载选项 defaults:使用默认挂载选项 如果要同时指明多个挂载选项,彼此间以逗号分隔 defaults,acl,noatime,noexec (5)转储频率 0:从不备份 1:每天备份 2:每隔一天备份 (6):自检次序 0:不自检 1:首先自检,通常只能是根文件系统可用1 2:次级自检 ....... # mount -a:可自动挂载定义在此文件中的所支持自动挂载的设备 df:查看磁盘使用 -l:仅显示本地文件的相关信息 -h:human-readable -i:显示inode的使用状态和非blocks du:查看目录实际的大小 -s:summary -h:human-readable
[root@centos7 /]# mke2fs -t ext4 -j -m 3 -N 10000 -L mydata -b 1024 /dev/sdb1 [root@centos7 /]# dumpe2fs -h /dev/sdb1 | egrep "Filesystem volume|Inode c|Reserved block c|Block s" dumpe2fs 1.42.9 (28-Dec-2013) Filesystem volume name: mydata Inode count: 10240 Reserved block count: 314572 Block size: 1024 [root@centos7 /]# blkid /dev/sdb1 | grep -o "TYPE.*" TYPE="ext4" [root@centos7 /]# tune2fs -L MYDATA -m 10 /dev/sdb1 [root@centos7 /]# dumpe2fs -h /dev/sdb1 | egrep "Filesystem volume|Reserved block c" dumpe2fs 1.42.9 (28-Dec-2013) Filesystem volume name: MYDATA Reserved block count: 1048576
相关文章推荐
- 文件系统管理
- 第八章、Linux 磁盘与文件系统管理
- Linux Vim,Find使用方法以及磁盘与文件系统管理
- 磁盘和文件系统管理LVM(二)
- Linux Admintration系列-文件系统管理
- 鸟哥的Linux私房菜10.14 磁盘与文件系统管理
- linux 文件系统管理
- 分区管理,文件系统管理
- 《鸟哥Linux私房菜》学习笔记_chap10_磁盘 文件系统管理
- 《Linux 八》 文件系统管理
- U8Linux磁盘与文件系统管理
- linux系统管理命令-文件系统管理
- Linux学习之四——磁盘与文件系统管理
- 文件系统管理
- 关于 磁盘、文件系统管理
- 鸟哥学习笔记8:Linux磁盘与文件系统管理
- 文件系统管理【Ubuntu-shell】
- Linux_磁盘与文件系统管理
- 【学习笔记——Linux】Linux磁盘和文件系统管理
- 文件系统管理