每天学五分钟 Liunx 100 | 存储篇:磁盘分区
这一节主要介绍 Liunx 是怎么用磁盘的。
磁盘分区
[root@test1 test]# ll /dev/ | grep sda
brw-rw----. 1 root disk 8, 0 Mar 12 22:45 sda
brw-rw----. 1 root disk 8, 0 Mar 12 22:45 sda1
brw-rw----. 1 root disk 8, 0 Mar 12 22:45 sda2
brw-rw----. 1 root disk 8, 0 Mar 12 22:45 sdb
[root@test1 test]# ll /dev/ | grep sda
brw-rw----. 1 root disk 8, 0 Mar 12 22:45 sda
brw-rw----. 1 root disk 8, 1 Mar 12 22:45 sda1
brw-rw----. 1 root disk 8, 2 Mar 12 22:45 sda2
brw-rw----. 1 root disk 8, 0 Mar 12 22:45 sdb
[root@test1 ~]# 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 0xd2793837.
The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-1875385007, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1875385007, default 1875385007):
Using default value 1875385007
Partition 1 of type Linux and of size 894.3 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@controller-0 sqg04]# partprobe
[root@controller-0 sqg04]# cd /dev/sd
sda sda1 sda2 sdb sdb1
文件系统
# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 4.7G 33G 13% /
tmpfs tmpfs 16G 20M 16G 1% /tmp
/dev/mapper/vol1-provider_ccs ext4 4.6G 22M 4.3G 1% /mnt/bricks/ccs
tmpfs tmpfs 294M 267M 28M 91% /mnt/rcpha/image
/dev/loop0 ext4 277M 125M 134M 49% /mnt/rcpha/etcd
example-5gbts-04-OAM-000.local:/mstate nfs4 477M 77M 371M 18% /mnt/mstate
sct-20a-12345678-oam-000.local:/services fuse.glusterfs 1.8G 234M 1.4G 15% /mnt/services
[root@test1 ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
58613760 inodes, 234422870 blocks
11721143 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2382364672
7155 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, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载点
[root@test1 home]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 895G 848G 47G 95% /
[root@test1 home]# mount /dev/sdb1 /home/test
[root@test1 home]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 xfs 895G 848G 47G 95% /
/dev/sdb1 ext4 881G 77M 836G 1% /home/test
文件系统实例
[root@test2:/home/robot]
# dumpe2fs /dev/vda1
dumpe2fs 1.45.5 (07-Jan-2020)
Filesystem volume name: rootfs # 文件系统的名称(Label)
Last mounted on: /sysroot
Filesystem UUID: 18b9201d-3a23-4c98-ab26-7b52c342da23
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean # 文件系统的状态没问题
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 2621440 # 总的 inode 数目
Block count: 10485499 # 总的 block 数目
Reserved block count: 450842
Free blocks: 9018609
Free inodes: 2580673
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 763
Blocks per group: 32768 # 每个 group 有多少个 block
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512 # 每个 group 有多少个 inode
Flex block group size: 16
Filesystem created: Wed Feb 12 16:09:19 2020
Last mount time: Fri Mar 13 14:25:56 2020
Last write time: Fri Mar 13 14:25:56 2020
Mount count: 8
Maximum mount count: -1
Last checked: Thu Feb 13 09:58:45 2020
Check interval: 0 (<none>)
Lifetime writes: 12 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 32
Desired extra isize: 32
Journal inode: 8
First orphan inode: 262571
Default directory hash: half_md4
Directory Hash Seed: 35426ac6-7885-4c68-9f84-f5d639422c77
Journal backup: inode blocks
Journal features: journal_incompat_revoke journal_64bit
Journal size: 64M
Journal length: 16384
Journal sequence: 0x00008261
Journal start: 5725
Group 0: (Blocks 0-32767) csum 0x2580 [ITABLE_ZEROED]
Primary superblock at 0, Group descriptors at 1-5 # superbock
Reserved GDT blocks at 6-768
Block bitmap at 769 (+769)
Inode bitmap at 785 (+785)
Inode table at 801-1312 (+801)
20030 free blocks, 808 free inodes, 878 directories
Free blocks: 9036-9759, 10152-10173, 10766, 10769, 10771-10773, 13489-32767
Free inodes: 264-783, 803, 1270-1289, 1326-1336, 1346-1361, 1381-1390, 1430-1468, 1619-1634, 1650-1662, 2408-2471, 2687-2713, 2741-2791, 2826-2834, 2868-2878
Group 1: (Blocks 32768-65535) csum 0x0061 [ITABLE_ZEROED]
Backup superblock at 32768, Group descriptors at 32769-32773 # backup superblock
Reserved GDT blocks at 32774-33536
Block bitmap at 770 (bg #0 + 770)
Inode bitmap at 786 (bg #0 + 786)
Inode table at 1313-1824 (bg #0 + 1313)
1971 free blocks, 2605 free inodes, 638 directories, 2374 unused inodes
Free blocks: 35584-35647, 35712-35791, 35812-35839, 35968-36031, 36120-36127, 36160-36163, 36234-36236, 36332-36543, 36573-36591, 36611, 36622-36635, 36725-36831, 36863, 36896-37375, 38010, 38020-38021, 38023-38034, 38037-38038, 38040-38046, 38048-38050, 38053-38911
Free inodes: 8380, 8425, 8749-8765, 8862-8864, 8867-8869, 8871-8872, 8874-8875, 8877-8912, 8968, 8971, 8974, 8996-9020, 9024-9047, 9049-9062, 9247, 9277-9294, 9823, 10168-10209, 10809-10811, 11341, 11395-11396, 13426-13428, 13436-13446, 13453, 13455, 13994-14009, 14011-16384
[root@test1:/home/robot]
# touch fileSystem.log
[root@example-5gbts-04-OAM-000:/home/robot]
# ll -hi
total 0
524586 -rw-r--r-- 1 root root 0 Mar 15 11:03 fileSystem.log
[root@test1:/home/robot]
# ll -di test/
656226 drwxr-xr-x 2 root root 4096 Mar 15 11:30 test/
[root@test1:/home/robot/test]
# ll -di /home/robot/test/
656226 drwxr-xr-x 2 root root 4096 Mar 15 11:36 /home/robot/test/
[root@test1:/home/robot/test]
# ln -s fileSystem.log fileSystem_sln.log
[root@test1:/home/robot/test]
# ln fileSystem.log fileSystem_hln.log
[root@test1:/home/robot/test]
# ll -i
total 0
524586 -rw-r--r-- 2 root root 0 Mar 15 11:03 fileSystem_hln.log
524586 -rw-r--r-- 2 root root 0 Mar 15 11:03 fileSystem.log
656227 lrwxrwxrwx 1 root root 14 Mar 15 11:36 fileSystem_sln.log -> fileSystem.log
[root@test1:/home/robot/test]
# ll -di / /home/ /home/robot/ /home/robot/test/
2 drwxr-sr-x 20 root root 4096 Mar 13 14:27 /
8197 drwxr-xr-x 5 root root 4096 Mar 13 14:27 /home/
524372 drwxr-xr-x 4 robot root 4096 Mar 15 11:36 /home/robot/
656226 drwxr-xr-x 2 root root 4096 Mar 15 11:36 /home/robot/test/
[root@test1:/home/robot/test]
# ll -hi
total 0
524586 -rw-r--r-- 2 root root 0 Mar 15 11:03 fileSystem_hln.log
524586 -rw-r--r-- 2 root root 0 Mar 15 11:03 fileSystem.log
656227 lrwxrwxrwx 1 root root 14 Mar 15 11:36 fileSystem_sln.log -> fileSystem.log