存储结构、磁盘划分

常见目录

目录名称应放置文件的内容
/boot开机所需文件——内核、开机菜单以及所需配置文件等
/dev以文件形式存放任何设备与接口
/etc配置文件
/home用户家目录
/bin存放单用户模式下还可以操作的命令
/lib开机时用到的函数库,以及/bin与/sbin下面的命令要调用的函数
/sbin开机过程中需要的命令
/media用于挂载设备文件的目录
/opt放置第三方的软件
/root系统管理员的家目录
/srv一些网络服务的数据文件目录
/tmp任何人均可使用的“共享”临时目录
/proc虚拟文件系统,例如系统内核、进程、外部设备及网络状态等
/usr/local用户自行安装的软件
/usr/sbinLinux系统开机时不会使用到的软件/命令/脚本
/usr/share帮助与说明文件,也可放置共享文件
/var主要存放经常变化的文件,如日志
/lost+found当文件系统发生错误时,将一些丢失的文件片段存放在这里

常见硬件设备

硬件设备文件名称
IDE设备/dev/hd[a-d]
SCSI/SATA/U盘/dev/sd[a-p]
软驱/dev/fd[0-1]
打印机/dev/lp[0-15]
光驱/dev/cdrom
鼠标/dev/mouse
磁带机/dev/st0或/dev/ht0

2个知识点

1、/dev目录中sda设备之所以是a,由系统内核识别顺序决定

2、分区数字编码,不一定是顺延,也有可能是手工指定

1
/dev/sda5

/dev 硬件设备目录

hd IDE设备

sd SCSI设备

a 磁盘顺序号

5 分区顺序号

常见文件系统

Ext3 日志文件系统

Ext4 Ext3改进版,存储容量1EB,批量分配block,读写效率高

XFS 高性能日志文件系统,存储容量18EB

NTFS

Dos FS

minix

inode 记录文件信息

该文件的访问权限(read、write、execute)

该文件的所有者与所属组(owner、group)

该文件的大小(size)

该文件的创建或内容修改时间(ctime)

该文件的最后一次访问时间(atime)

该文件的修改时间(mtime)

文件的特殊权限(SUID、SGID、SBIT)

该文件的真实数据地址(point)

block 存储文件

以4kb block为例

1、文件1KB,占用一个block,浪费3KB

2、文件5KB,占用两个block(5KB-4KB后,剩下1KB也要占用一个block)

mount 挂载设备

mount命令参数

参数作用
-a挂载所有在/etc/fstab中定义的文件系统
-t指定文件系统的类型

1
mount /dev/sdb2 /backup

挂载信息格式

字段意义
设备文件一般为设备的路径+设备名称,也可以写唯一识别码(UUID,Universally_Unique_Identifier)
挂载目录指定要挂载到的目录,需在挂载前创建好
格式类型指定文件系统的格式,比如Ext3、Ext4、XFS、SWAP、iso9660(此为光盘设备)等
权限选项若设置为defaults,则默认权限为:rw,suid,dev,exec,auto,nouser,async
自检若为1则开机后进行磁盘自检,为0则不自检
优先级若“自检”字段为1,则可对多块硬盘进行自检优先级设置

系统重启,自动挂载

 1  2  3  4  5  6  7  8  9 10 11 12 13
vim /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 4 19:26:23 2017 # # 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 # /dev/mapper/rhel-root / xfs defaults 1 1 UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2 /dev/mapper /rhel-swap swap swap defaults 0 0 /dev/cdrom /media/cdrom iso9660 defaults 0 0 /dev/sdb2 /backup ext4 defaults 0 0

umount 撤销挂载

1
umount /dev/sdb2

fdisk 管理设备

fdisk命令参数

参数作用
m查看全部可用的参数
n添加新的分区
d删除某个分区信息
l列出所有可用的分区类型
t改变某个分区的类型
p查看分区信息
w保存并退出
q不保存直接退出

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x47d24a34. Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x47d24a34 Device Boot Start End Blocks Id System Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048):此处敲击回车 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G Partition 1 of type Linux and of size 2 GiB is set Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x47d24a34 Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. file /dev/sdb1 /dev/sdb1: cannot open (No such file or directory) #分区信息同步到内核 partprobe partprobe file /dev/sdb1 /dev/sdb1: block special #格式化 mkfs mkfs mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat mkfs.xfs /dev/sdb1 meta-data=/dev/sdb1 isize=256 agcount=4, agsize=131072 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=524288, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 #挂载使用 mkdir /newFS mount /dev/sdb1 /newFS/ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 3.5G 15G 20% / devtmpfs 905M 0 905M 0% /dev tmpfs 914M 140K 914M 1% /dev/shm tmpfs 914M 8.8M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sr0 3.5G 3.5G 0 100% /media/cdrom /dev/sda1 497M 119M 379M 24% /boot /dev/sdb1 2.0G 33M 2.0G 2% /newFS

du 查看占用硬盘空间

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
cp -rf /etc/* /newFS/ ls /newFS/ abrt hosts pulse adjtime hosts.allow purple aliases hosts.deny qemu-ga aliases.db hp qemu-kvm alsa idmapd.conf radvd.conf alternatives init.d rc0.d anacrontab inittab rc1.d ………………省略部分输入信息……………… du -sh /newFS/ 33M /newFS/ #写入配置文件 vim /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 4 19:26:23 2017 # # 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 # /dev/mapper/rhel-root / xfs defaults 1 1 UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2 /dev/mapper /rhel-swap swap swap defaults 0 0 /dev/cdrom /media/cdrom iso9660 defaults 0 0 /dev/sdb1 /newFS xfs defaults 0 0

交换分区

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xb3d27ce1. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p Partition number (2-4, default 2): First sector (4196352-41943039, default 4196352): 此处敲击回车 Using default value 4196352 Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +5G Partition 2 of type Linux and of size 5 GiB is set Command (m for help): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xb0ced57f Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux /dev/sdb2 4196352 14682111 5242880 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. 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) Syncing disks. #交换分区专用格式化 mkswap /dev/sdb2 Setting up swapspace version 1, size = 5242876 KiB no label, UUID=2972f9cb-17f0-4113-84c6-c64b97c40c75 free -m total used free shared buffers cached Mem: 1483 782 701 9 0 254 -/+ buffers/cache: 526 957 Swap: 2047 0 2047 swapon /dev/sdb2 free -m total used free shared buffers cached Mem: 1483 785 697 9 0 254 -/+ buffers/cache: 530 953 Swap: 7167 0 7167 vim /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 4 19:26:23 2017 # # 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 # /dev/mapper/rhel-root / xfs defaults 1 1 UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults 1 2 /dev/mapper /rhel-swap swap swap defaults 0 0 /dev/cdrom /media/cdrom iso9660 defaults 0 0 /dev/sdb1 /newFS xfs defaults 0 0 /dev/sdb2 swap swap defaults 0 0

quota 磁盘容量配额

软限制:当达到软限制时会提示用户,但仍允许用户在限定的额度内继续使用

硬限制:当达到硬限制时会提示用户,且强制终止用户的操作

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21
vim /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 4 19:26:23 2017 # # 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 # /dev/mapper/rhel-root / xfs defaults 1 1 UUID=812b1f7c-8b5b-43da-8c06-b9999e0fe48b /boot xfs defaults,uquota 1 2 /dev/mapper /rhel-swap swap swap defaults 0 0 /dev/cdrom /media/cdrom iso9660 defaults 0 0 /dev/sdb1 /newFS xfs defaults 0 0 /dev/sdb2 swap swap defaults 0 0 reboot mount | grep boot /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota) useradd tom chmod -Rf o+w /boot

xfs_quota XFS文件系统磁盘容量配额

-c 以参数形式设置要执行的命令

-x 专家模式

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22
#bsoft、bhard 硬盘使用量的软限制、硬限制分别为3MB和6MB #isoft、ihard 创建文件数量的软限制、硬限制分别为3个和6个 xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 tom' /boot xfs_quota -x -c report /boot User quota on /boot (/dev/sda1) Blocks User ID Used Soft Hard Warn/Grace ---------- -------------------------------------------------- root 95084 0 0 00 [--------] tom 0 3072 6144 00 [--------] su - tom dd if=/dev/zero of=/boot/tom bs=5M count=1 1+0 records in 1+0 records out 5242880 bytes (5.2 MB) copied, 0.123966 s, 42.3 MB/s dd if=/dev/zero of=/boot/tom bs=8M count=1 dd: error writing ‘/boot/tom’: Disk quota exceeded 1+0 records in 0+0 records out 6291456 bytes (6.3 MB) copied, 0.0201593 s, 312 MB/s

edquota 编辑quota配额限制

-u 针对哪个用户

-g 针对哪个用户组

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18
edquota -u tom Disk quotas for user tom (uid 1001): Filesystem blocks soft hard inodes soft hard /dev/sda 6144 3072 8192 1 3 6 su - tom Last login: Mon Sep 7 16:43:12 CST 2017 on pts/0 dd if=/dev/zero of=/boot/tom bs=8M count=1 1+0 records in 1+0 records out 8388608 bytes (8.4 MB) copied, 0.0268044 s, 313 MB/s dd if=/dev/zero of=/boot/tom bs=10M count=1 dd: error writing ‘/boot/tom’: Disk quota exceeded 1+0 records in 0+0 records out 8388608 bytes (8.4 MB) copied, 0.167529 s, 50.1 MB/s

浙ICP备11005866号-12