文件系统管理
复习:文件系统的创建,修改 fdisk:老牌的磁盘创建的工具: fdisk [-uc] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device fdisk -l [-u] [device...]查看当前列表中的磁盘分区 fdisk -s partition... fdisk -v fdisk -h [root@localhost ~]# fdisk -l /dev/sda Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 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: 0x00073dc7 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2675 20971520 83 Linux /dev/sda3 2675 3981 10485760 83 Linux /dev/sda4 3981 15666 93858816 5 Extended /dev/sda5 3981 4242 2097152 82 Linux swap / Solaris /dev/sda6 4242 5547 10486742 83 Linux 使用分idisk命令进入指定的磁盘空间: [root@localhost ~]# fdisk /dev/sda 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): 默认情况下,一块磁盘上可以有4个主分区,和逻辑分区,但是fdisk命令默认最大支持的磁盘分区为15块 查看内核是否已经识别新的分区: cat/proc/partations 通知内核重新读取硬盘分区表 partx -a /dev/DEVICE 如果partx -a不生效的情况下使用koartx -a 创建文件系统: cat /proc/filesystems mkfs:磁盘管理工具: CentOS6上: [root@localhost ~]# mkfs mkfs mkfs.ext2 mkfs.ext4 mkfs.msdos mkfs.cramfs mkfs.ext3 mkfs.ext4dev mkfs.vfat CentOS7上: [root@localhost home]# mkfs mkfs mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat [root@localhost ~]# mkfs.ext4 -L 'MYDATA' -m 3 /dev/sda7 mke2fs 1.41.12 (17-May-2010) Filesystem label=MYDATA OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655776 inodes, 2622603 blocks 78678 blocks (3.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 35 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 使用blkid命令查看所指定的磁盘的内容: 包括(卷标,UUID,分区类型) [root@localhost ~]# blkid /dev/sda7 /dev/sda7: LABEL="MYDATA" UUID="f90557c2-3db3-44c4-9ced-aac776e655c9" TYPE="ext4" e2label:管理ext系列文件系统的LABEL [root@localhost ~]# e2label /dev/sda7 'wostop' [root@localhost ~]# [root@localhost ~]# blkid /dev/sda7 /dev/sda7: LABEL="wostop" UUID="f90557c2-3db3-44c4-9ced-aac776e655c9" TYPE="ext4" tune2fs:修改ext系列的文件系统可调整的参数的值: dumpe2fs: -h:查看超级块信息 文件系统检测: fsck: [root@localhost ~]# fsck /dev/sda7 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) wostop: clean, 11/655776 files, 79700/2622603 blocks e2fsck:ext系列文件专用的检测修复工具 -y:自动回答为yes; -f:强制修复;
文件系统挂载:
文件系统管理: 将额外文件系统与根文件系统某现存的目录建立起关系,进而使得此目录做为其他文件访问入口的行为称之为挂载: 文件系统挂载命令:mount 这里注意:最好挂载在空目录下:切记切记!! 可以使用磁盘名称: UUID: 卷标等进行挂载!! 使用cat /proc/mounts命令查看内核当中已挂载的所有设备: 卸载命令: # umount DEVICE # umount MOUNT_POINT 查看正在访问指定文件系统的进程: # fuser -v MOUNT_POINT 终止所有在正访问指定的文件系统的进程: # fuser -km MOUNT_POINT [root@localhost mnt]# fuser -v maydata USER PID ACCESS COMMAND maydata: root 3109 ..c.. bash [root@localhost mnt]# fuser -km maydata maydata: 3109c 挂载交换分区: 启用:swapon swapon [OPTION]... [DEVICE] -a:激活所有的交换分区; -p PRIORITY:指定优先级; 禁用:swapoff [OPTION]... [DEVICE] 前提是需要先使用fdisk命令修改磁盘类型: [root@localhost mnt]# free total used free shared buffers cached Mem: 1020540 491308 529232 0 69844 170232 -/+ buffers/cache: 251232 769308 Swap: 2097144 0 2097144 [root@localhost mnt]# free -m total used free shared buffers cached Mem: 996 479 516 0 68 166 -/+ buffers/cache: 245 751 Swap: 2047 0 2047 [root@localhost mnt]# free -g total used free shared buffers cached Mem: 0 0 0 0 0 0 -/+ buffers/cache: 0 0 Swap: 1 0 1 综上可以看出,在内存查看中可以看到,由于先前使用的命令或程序,在内存中进行了缓存,所以看到的值需要将buffer和cash值加上才是真正的内存剩余空间: 文件系统空间占用等信息的查看工具: df: [root@localhost mnt]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 20642428 3242992 16350860 17% / tmpfs 510268 228 510040 1% /dev/shm /dev/sda1 495844 33755 436489 8% /boot /dev/sda3 10321208 155720 9641200 2% /home /dev/sda7 10325748 154136 9856900 2% /mnt/maydata -h: human-readable [root@localhost mnt]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 20G 3.1G 16G 17% / tmpfs 499M 228K 499M 1% /dev/shm /dev/sda1 485M 33M 427M 8% /boot /dev/sda3 9.9G 153M 9.2G 2% /home /dev/sda7 9.9G 151M 9.5G 2% /mnt/maydata -i:inodes instead of blocks [root@localhost mnt]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1310720 97370 1213350 8% / tmpfs 127567 6 127561 1% /dev/shm /dev/sda1 128016 38 127978 1% /boot /dev/sda3 655360 287 655073 1% /home /dev/sda7 655776 11 655765 1% /mnt/maydata [root@localhost mnt]# df -ih Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda2 1.3M 96K 1.2M 8% / tmpfs 125K 6 125K 1% /dev/shm /dev/sda1 126K 38 125K 1% /boot /dev/sda3 640K 287 640K 1% /home /dev/sda7 641K 11 641K 1% /mnt/maydata -P: 以Posix兼容的格式输出; [root@localhost mnt]# df -P Filesystem 1024-blocks Used Available Capacity Mounted on /dev/sda2 20642428 3242984 16350868 17% / tmpfs 510268 228 510040 1% /dev/shm /dev/sda1 495844 33755 436489 8% /boot /dev/sda3 10321208 155720 9641200 2% /home /dev/sda7 10325748 154136 9856900 2% /mnt/maydata 查看某目录总体空间占用状态:du: du [OPTION]... DIR -h: human-readable -s: summary 文件挂载的配置文件:/etc/fstab [root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Sun Jul 10 08:30:21 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=36e12a53-107b-4f2c-93d2-1a4836d67bab / ext4 defaults 1 1 UUID=b66484d9-582d-4371-b4d0-e4ced790c209 /boot ext4 defaults 1 2 UUID=001595df-98dd-441b-bb32-267407ff2e30 /home ext4 defaults 1 2 UUID=6578a451-4708-43da-b64c-376745edcefe swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 要挂载的设备或伪文件系统 挂载点 文件系统类型 挂载选项 转储频率 自检次序 要挂载的设备或伪文件系统: 设备文件、LABEL(LABEL="")、UUID(UUID="")、伪文件系统名称(proc,sysfs) 挂载选项: default:rw, suid, dev, exec, auto, nouser, and async 转储频率: 0:不做备份 1:每天转储一次 2:每隔一天转储 自检次序: 0:不自检 1:首先自检:一般只有rootfs才有1; 2:第二位自检
原创文章,作者:wostop,如若转载,请注明出处:http://www.178linux.com/25116