[root@localhost ~]# cat /etc/filesystems //查看centos7所支持的系統格式 xfs //系統默認的支持的格式 ext4 ext3 ext2 nodev proc nodev devpts iso9660 vfat hfs hfsplus * [root@localhost ~]#
[root@localhost ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 1.2G 17G 7% / devtmpfs 483M 0 483M 0% /dev tmpfs 493M 0 493M 0% /dev/shm tmpfs 493M 6.8M 486M 2% /run tmpfs 493M 0 493M 0% /sys/fs/cgroup /dev/sda1 197M 109M 88M 56% /boot tmpfs 99M 0 99M 0% /run/user/0
[root@localhost ~]# fdisk -l 磁盤 /dev/sda:21.5 GB, 21474836480 字節,41943040 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標籤類型:dos 磁盤標識符:0x000c928b 設備 Boot Start End Blocks Id System /dev/sda1 * 2048 411647 204800 83 Linux /dev/sda2 411648 4605951 2097152 82 Linux swap / Solaris /dev/sda3 4605952 41943039 18668544 83 Linux 磁盤 /dev/sdb:10.7 GB, 10737418240 字節,20971520 個扇區 Units = 扇區 of 1 * 512 = 512 bytes 扇區大小(邏輯/物理):512 字節 / 512 字節 I/O 大小(最小/最佳):512 字節 / 512 字節 磁盤標籤類型:dos 磁盤標識符:0x3ca78df9 設備 Boot Start End Blocks Id System /dev/sdb1 2048 16779263 8388608 83 Linux
[root@localhost ~]# echo 1 > 2.txt [root@localhost ~]# ls =lh 2.txt ls: 沒法訪問=lh: 沒有那個文件或目錄 2.txt [root@localhost ~]# ls -lh 2.txt //查看文件的大小 -rw-r--r--. 1 root root 2 11月 3 15:48 2.txt [root@localhost ~]# du -sh 2.txt //查看塊大小 4.0K 2.txt [root@localhost ~]# du -sb 2.txt 2 2.txt
這裏會看到ls -lh和du -sb查看文件的大小相同 而ls -lh查看的是文件的大小,du -sh 查看是塊的大小
修改文件文件系統兩種命令node
[root@localhost ~]# mke2fs -t ext4 -b 2048 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤= OS type: Linux 塊大小=2048 (log=1) 分塊大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 524288 inodes, 4194304 blocks 209715 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=272629760 256 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 [root@localhost ~]#
[root@localhost ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤= OS type: Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 524288 inodes, 2097152 blocks 104857 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=2147483648 64 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 [root@localhost ~]#
[root@localhost ~]# mkfs.xfs -f /dev/sdb1 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=524288 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2097152, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 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 [root@localhost ~]#
[root@localhost ~]# mke2fs -t xfs -b 2048 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Your mke2fs.conf file does not define the xfs filesystem type. Aborting...
[root@localhost ~]# blkid /dev/sdb1 /dev/sdb1: UUID="ebdc3a7b-d16d-4bd8-8019-275e587d359e" TYPE="xfs"
[root@hf-01 ~]# mke2fs -b 8194 /dev/sdb1 Warning: blocksize 8194 not usable on most systems. mke2fs 1.42.9 (28-Dec-2013) mke2fs: 8192-byte blocks too big for system (max 4096) 不管如何也要繼續? (y,n) n [root@hf-01 ~]# mke2fs -b 2048 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤= OS type: Linux 塊大小=2048 (log=1) 分塊大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 2621440 blocks 131072 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=540016640 160 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000 Allocating group tables: 完成 正在寫入inode表: 完成 Writing superblocks and filesystem accounting information: 完成
[root@hf-01 ~]# mke2fs -t ext4 -m 1 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤= OS type: Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 13107 blocks (1.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
[root@hf-01 ~]# mke2fs -i 8192 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤= OS type: Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: 完成 正在寫入inode表: 完成 Writing superblocks and filesystem accounting information: 完成 [root@hf-01 ~]#
[root@hf-01 ~]# mkfs.xfs -f /dev/sdb meta-data=/dev/sdb isize=256 agcount=4, agsize=1310720 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 data = bsize=4096 blocks=5242880, 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
[root@hf-01 ~]# blkid /dev/sdb /dev/sdb: UUID="fdf63a90-eaf9-4cd0-b82c-5afd2965da2a" TYPE="xfs"
[root@hf-01 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 2.4G 16G 14% / devtmpfs 489M 0 489M 0% /dev tmpfs 494M 0 494M 0% /dev/shm tmpfs 494M 6.7M 487M 2% /run tmpfs 494M 0 494M 0% /sys/fs/cgroup /dev/sda1 197M 75M 123M 38% /boot [root@hf-01 ~]# mount /dev/sdb /mnt/ [root@hf-01 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 2.4G 16G 14% / devtmpfs 489M 0 489M 0% /dev tmpfs 494M 0 494M 0% /dev/shm tmpfs 494M 6.7M 487M 2% /run tmpfs 494M 0 494M 0% /sys/fs/cgroup /dev/sda1 197M 75M 123M 38% /boot /dev/sdb 20G 33M 20G 1% /mnt
會看到最後一行,多了一個分區,也可稱之爲磁盤
[root@hf-01 ~]# cd /mnt/ [root@hf-01 mnt]# ls [root@hf-01 mnt]# touch 1.txt 2.txt [root@hf-01 mnt]# mkdir 124 [root@hf-01 mnt]# cd [root@hf-01 ~]# umount /dev/sdb [root@hf-01 ~]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 2.4G 16G 14% / devtmpfs 489M 0 489M 0% /dev tmpfs 494M 0 494M 0% /dev/shm tmpfs 494M 6.7M 487M 2% /run tmpfs 494M 0 494M 0% /sys/fs/cgroup /dev/sda1 197M 75M 123M 38% /boot [root@hf-01 ~]#
[root@hf-01 ~]# mount /dev/sdb /mnt/ [root@hf-01 ~]# ls /mnt 124 1.txt 2.txt [root@hf-01 ~]# cd /mnt/ [root@hf-01 mnt]# umount /dev/sdb umount: /mnt:目標忙。 (有些狀況下經過 lsof(8) 或 fuser(1) 能夠 找到有關使用該設備的進程的有用信息) [root@hf-01 mnt]# umount -l /mnt/ [root@hf-01 mnt]# df -h 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 18G 2.4G 16G 14% / devtmpfs 489M 0 489M 0% /dev tmpfs 494M 0 494M 0% /dev/shm tmpfs 494M 6.7M 487M 2% /run tmpfs 494M 0 494M 0% /sys/fs/cgroup /dev/sda1 197M 75M 123M 38% /boot
defaults Use default options: rw, suid, dev, exec, auto, nouser, and async.
# UUID=ce0b257e-62c5-4355-9117-b1edc7085e58 / xfs defaults 1 1 UUID=a9ea9597-52e8-4d73-8975-0ecb3970c760 /boot xfs defaults 1 2 UUID=06c3de3e-7c95-4f75-905e-c5d4fbf4a5fa swap swap defaults 0 0
# # /etc/fstab # Created by anaconda on Sun Aug 20 21:03:05 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 # UUID=ce0b257e-62c5-4355-9117-b1edc7085e58 / xfs defaults 1 1 UUID=a9ea9597-52e8-4d73-8975-0ecb3970c760 /boot xfs defaults 1 2 UUID=06c3de3e-7c95-4f75-905e-c5d4fbf4a5fa swap swap defaults 0 0 這裏本身添加的 /dev/sdb /mnt xfs defaults 0 0
若想寫UUID,可使用blkid命令去查看填寫
[root@hf-01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100 記錄了100+0 的讀入 記錄了100+0 的寫出 104857600字節(105 MB)已複製,0.728387 秒,144 MB/秒 [root@hf-01 ~]# du -sh /tmp/newdisk 100M /tmp/newdisk [root@hf-01 ~]#
[root@hf-01 ~]# mkswap -f /tmp/newdisk //格式化swap空間 正在設置交換空間版本 1,大小 = 102396 KiB 無標籤,UUID=7355a547-2562-4320-8470-cff6b7bda975
[root@hf-01 ~]# free -m //查看磁盤使用狀況 total used free shared buffers cached Mem: 987 793 193 6 0 209 -/+ buffers/cache: 583 403 Swap: 2047 0 2047 [root@hf-01 ~]# swapon /tmp/newdisk //添加swap空間添加到現有的swap上去 swapon: /tmp/newdisk:不安全的權限 0644,建議使用 0600。 [root@hf-01 ~]# free -m total used free shared buffers cached Mem: 987 793 193 6 0 209 -/+ buffers/cache: 583 403 Swap: 2147 0 2147
會看到添加swap的時候,提示不安全,但free -m查看的的時候,會看到添加成功
[root@hf-01 ~]# chmod 0600 /tmp/newdisk
[root@hf-01 ~]# swapoff /tmp/newdisk [root@hf-01 ~]# free -m total used free shared buffers cached Mem: 987 793 193 6 0 209 -/+ buffers/cache: 583 403 Swap: 2047 0 2047 [root@hf-01 ~]#
這時會看到swap空間恢復原有大小了
[root@hf-01 ~]# rm -f /tmp/newdisk [root@hf-01 ~]#