第四章 磁盤分區(qū)知識與Linux系統(tǒng)分區(qū)實踐
1悼瓮、fdisk命令分區(qū)
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.
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x000b907d
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):
Using default response p
Partition number (1-4, default 1):
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +150M
Partition 1 of type Linux and of size 150 MiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (309248-2097151, default 309248):
Using default value 309248
Last sector, +sectors or +size{K,M,G} (309248-2097151, default 2097151): +150M
Partition 2 of type Linux and of size 150 MiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
Partition number (3,4, default 3):
First sector (616448-2097151, default 616448):
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +150M
Partition 3 of type Linux and of size 150 MiB is set
Command (m for help): N
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e):
Using default response e
Selected partition 4
First sector (923648-2097151, default 923648):
Using default value 923648
Last sector, +sectors or +size{K,M,G} (923648-2097151, default 2097151):
Using default value 2097151
Partition 4 of type Extended and of size 573 MiB is set
Command (m for help): P
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x000b907d
Device Boot Start End Blocks Id System
/dev/sdb1 2048 309247 153600 83 Linux
/dev/sdb2 309248 616447 153600 83 Linux
/dev/sdb3 616448 923647 153600 83 Linux
/dev/sdb4 923648 2097151 586752 5 Extended
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@yuzhiwei/]# cat /proc/partitions
major minor #blocks name
11 0 4481024 sr0
8 0 20971520 sda
8 1 204800 sda1
8 2 2048000 sda2
8 3 18717696 sda3
8 16 1048576 sdb
8 17 153600 sdb1
8 18 153600 sdb2
8 19 153600 sdb3
8 20 1 sdb4
8 21 153600 sdb5
分區(qū)完成后使用partprobe /dev/sdb 命令將分區(qū)信息通知內(nèi)核
2隙疚、parted命令分區(qū)
分區(qū)前先看一下分區(qū)格式土铺,fdisk命令分區(qū)用dos分區(qū)格式,parted命令分區(qū)使用gpt分區(qū)格式绒北。
[root@yuzhiwei/]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be
lost. Do you want to continue?
Yes/No? y
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart primary 0 480
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 480MB 480MB primary
(parted) mkpart primary 481 580
(parted) mkpart logic 581 600
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 480MB 480MB primary
2 481MB 580MB 98.6MB primary
3 581MB 600MB 18.9MB logic
parted命令分區(qū)時沒有擴展分區(qū),只有主分區(qū)和邏輯分區(qū)。
3沿后、文件系統(tǒng)
3.1、什么是文件系統(tǒng)朽砰?
計算機存儲和組織數(shù)據(jù)的方法或者機制尖滚,落地是一個軟件喉刘。
3.2、為什么需要文件系統(tǒng)漆弄?
磁盤睦裳、物理介質(zhì)幻枉、磁粒子物理元素样刷。硬件需要軟件驅(qū)動使用爹橱,磁盤需要文件系統(tǒng)驅(qū)動落蝙。
文件系統(tǒng)實現(xiàn)通過磁盤管理規(guī)劃贡这、存取數(shù)據(jù)巷燥。
3.3倔撞、文件系統(tǒng)有哪些類型寸士?
Windows:NTFS渤愁、fat32牵祟、msdos
Linux:ext2、ext3(C5)猴伶、ext4(C6)课舍、xfs(C7)、btrfs
3.4他挎、創(chuàng)建文件系統(tǒng)
首先用上面的命令創(chuàng)建分區(qū)
首先對分區(qū)進行格式化筝尾,其實關(guān)鍵就是生成一定數(shù)量的Inode和Block。
[root@yuzhiwei/]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
38456 inodes, 153600 blocks
7680 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
19 block groups
8192 blocks per group, 8192 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
也可以指定指定塊大小和inode大小進行格式化
[root@oldboyedu ~]# mkfs -t ext4 -b 4096 -I 512 /dev/sdb3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
38400 inodes, 38400 blocks
1920 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=39845888
2 block groups
32768 blocks per group, 32768 fragments per group
19200 inodes per group
Superblock backups stored on blocks:
32768
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
然后進行掛載并查看掛載結(jié)果
[root@yuzhiwei/]# mount /dev/sdb1 /mnt
[root@yuzhiwei/]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.7G 17G 10% /
devtmpfs 900M 5.0M 895M 1% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.6M 901M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/sda1 197M 116M 82M 59% /boot
tmpfs 182M 0 182M 0% /run/user/0
/dev/sdb1 142M 1.6M 130M 2% /mnt
[root@yuzhiwei/]# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/sdb1 /mnt ext4 rw,relatime,data=ordered 0 0
以上掛載命令只是臨時掛載到/mnt
如何開機自動掛載办桨?
/etc/fstab 開機自動掛載
幾列筹淫? 6列
[root@oldboyedu ~]# cat /etc/fstab
UUID=3a3a295f-88f8-456d-94dc-1a3eeb517c02 / xfs defaults 0 0
UUID=fd2e0ca7-32be-425f-86a2-85c02b9ec5ea /boot xfs defaults 0 0
UUID=79a3924b-739e-48dc-ab0c-0444b9ac6591 swap swap defaults 0 0
設(shè)備 掛載點 文件系統(tǒng)類型 默認掛載選項 是否備份 是否開機磁盤檢查
/dev/sdb2 /opt xfs defaults 0 0
umount -lf 命令可以強制卸載掛載