乱读天书, 不求甚解
周祎骏的个人云笔记
Toggle navigation
乱读天书, 不求甚解
主页
Linux:系统配置
Linux:用户管理
Linux:优化排错
Linux:进程调度
Linux:文件系统
Linux:网络
Linux:系统服务
Linux:安全
Linux:内核
容器:Docker
容器:containerd
容器编排:Kubernetes
IAC:Terraform
大数据:Hadoop
大数据:Zookeeper
大数据:Hbase
消息队列:rsyslog
消息队列:kafka
数据库:MySQL
数据库:MongoDB
搜索引擎:Elasticsearch
时序数据库:OpenTSDB
网站服务:Nginx
编程:Bash
编程:Perl
编程:Python
编程:C
编程:JAVA
编程:Rust
版本控制:gitlab
知识管理:docusaurus
常用小工具
关于我
标签
Linux文件系统 1.0 一些基础操作
2023-01-12 07:19:07
45
0
0
admin
> 一些基础操作 # mke2fs 可以用来格式化ext2/3/4 并详细设置各项参数 ``` [root@localhost ~]# mkfs -t ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 28112 inodes, 112420 blocks 5621 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 14 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 28 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# mount /dev/sdb1 /mnt [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 8.4G 808M 7.2G 10% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 485M 30M 430M 7% /boot /dev/sdb1 107M 5.6M 96M 6% /mnt [root@localhost ~]# ``` # 分区 fdisk -l 查看当前系统总分区信息 当你要分区的磁盘正在使用的时候,可能变动不能被内核知道 要注意如下报错: WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) ``` [root@localhost ~]# fdisk /dev/sdb 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): 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 <-- 修改分区的system id,用来说明这个分区类型 u change display/entry units v verify the partition table w write table to disk and exit <-- 退出,保存 x extra functionality (experts only) Command (m for help): p <-- 显示当前分区 Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0xbce88505 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-261, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261): +100M <-- 100M 的分区 Command (m for help): p Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0xbce88505 Device Boot Start End Blocks Id System /dev/sdb1 1 14 112423+ 83 Linux Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 2 First cylinder (15-261, default 15): Using default value 15 Last cylinder, +cylinders or +size{K,M,G} (15-261, default 261): Using default value 261 Command (m for help): p Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0xbce88505 Device Boot Start End Blocks Id System /dev/sdb1 1 14 112423+ 83 Linux /dev/sdb2 15 261 1984027+ 5 Extended Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (15-261, default 15): Using default value 15 Last cylinder, +cylinders or +size{K,M,G} (15-261, default 261): +100M Command (m for help): p Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0xbce88505 Device Boot Start End Blocks Id System /dev/sdb1 1 14 112423+ 83 Linux /dev/sdb2 15 261 1984027+ 5 Extended /dev/sdb5 15 28 112423+ 83 Linux Command (m for help): d Partition number (1-5): 5 Command (m for help): p Disk /dev/sdb: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0xbce88505 Device Boot Start End Blocks Id System /dev/sdb1 1 14 112423+ 83 Linux /dev/sdb2 15 261 1984027+ 5 Extended Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# ``` ## 内核重载分区 partprobe 让内核读入新的分区表。 查看 内核中当前的分区: cat /proc/partitions 在RHEL 5.5中系统硬盘在分完区后可以直接使用partprobe更新分区,使内核识别分区。 在RHEL6中分区完毕后使用partprobe无法更新分区,必须重新启动服务器后,分区才可以被正常挂载。 partx -a /dev/sda 可以用于RHEL6 # 查看分区信息 ``` 查看uuid, 文件系统类型 [root@fs1 ~]# blkid /dev/sda1 /dev/sda1: UUID="7594f582-ab58-4c3b-ad68-a48e234a25aa" TYPE="ext4" ext2/ext3/ext4 dumpe2fs: [root@fs1 ~]# dumpe2fs /dev/sdb ``` # 修改分区label 名称 ``` [root@www ~]# e2label 裝置名稱 新的Label名稱 例子: [root@localhost mnt]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 8.4G 808M 7.2G 10% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 485M 30M 430M 7% /boot /dev/sdb1 107M 5.6M 96M 6% /mnt/d1 [root@localhost mnt]# e2label /dev/sdb1 lala [root@localhost mnt]# umount d1 [root@localhost mnt]# mount -L lala d1 [root@localhost mnt]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 8.4G 808M 7.2G 10% / tmpfs 250M 0 250M 0% /dev/shm /dev/sda1 485M 30M 430M 7% /boot /dev/sdb1 107M 5.6M 96M 6% /mnt/d1 [root@localhost mnt]# ``` # 分区加密 需要dm_crypt 模块 对改磁盘进行加密和格式化操作 [root@desktopX ~]# cryptsetup luksFormat /dev/sda5 注意:这里会出现警告,本操作将损坏 /dev/sda5 里面的数据,我们输入大写的 YES , 切记是大写,然后输入两遍加密密码。 设置加密磁盘为开机自动挂载: 如果希望这个映射能在开机的时候自动挂载,那么要写入 /etc/fstab 里面去,注意要使 用的是 UUID 号 [root@desktopX ~]# blkid /dev/sda5 [root@desktopX ~]# vim /etc/fstab …… UUID=XXXXXXXXXXXXXXXX /mnt ext4 defaults 0 0 …… 但这个时候系统在启动的时候,会等待你输入密码 如果希望系统启动的时候我们不需要输入密码的话,我们可以先把密码写到一个文本 文件里去,系统再启动的时候自动读取这个文件即可 [root@desktopX ~]# echo -n "redhat">/root/rhce_pw [root@desktopX ~]# cryptsetup luksAddKey /dev/sda5 /root/rhce_pw 编辑 /etc/crypttab [root@desktopX ~]# vim /etc/crypttab …… 写入以下内容 rhce /dev/sdb1 /root/rhce_pw 映射名 硬件名 密码文件(可以是none) # 挂载 ``` mount -t 文件系统类型 -o 选项 device dir mount -L label_name dir # 用label 挂载 mount -a # 按照/etc/fstab 挂载 mount --bind /aaa /bbb 将一个目录挂载在另一个目录下 ``` ``` /etc/filesystems 挂载文件系统时会自动测试的文件系统类型 /proc/filesystems 内核已经加载的文件系统类型 /lib/modules/$(uname -r)/kernel/fs/ 是否有驱动程序 /etc/mtab 每一次操作文件系统,都会动态更新/etc/mtab,当然,也可以读取/proc/mount来获取当前文件系统挂载信息 ``` ## /etc/fstab ``` cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda1 during installation UUID=7383cc33-5d9c-4306-a695-735d42821ae4 / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/nvme0n1p2 during installation UUID=547F-0417 /boot/efi vfat umask=0077 0 1 /swapfile none swap sw 0 0 ``` **参数** ``` async/sync 磁盘是否随时同步数据,不同步性能更好(默认async) auto/noauto mount -a 时是否自动挂载(默认auto) rw/ro 只读,读写 exec/noexec 可执行,不可执行 user/nouser 普通用户能否挂载 suid/nosuid 是否开启suid 功能 usrquota 是否开启usrquota 功能 grpquota 是否开启grpquota 功能 defaults 等同于 rw, suid, dev, exec, auto, nouser, async ```
上一篇:
Linux文件系统 0.0 一些基础知识
下一篇:
Linux文件系统 1.1 LVM
文档导航