Linux磁盘分区

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux磁盘分区相关的知识,希望对你有一定的参考价值。

[[email protected] ~]# part
parted partprobe partx
[[email protected] ~]# parted
anaconda-ks.cfg .cache/ initial-setup-ks.cfg
.bash_history .config/ .tcshrc
.bash_logout .cshrc .Xauthority
.bash_profile g3308l
.bashrc g3308l.1
[[email protected] ~]# parted /dev/sdb mklabel gpt
gpt是改磁盘格式
警告: 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? yes
信息: You may need to update /etc/fstab.

[[email protected] ~]#
[[email protected] ~]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志

[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# parted /dev/sdb mkpart primary ext4 1 50G
mkprat 创建
信息: You may need to update /etc/fstab.

[[email protected] ~]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志
1 1049kB 50.0GB 50.0GB primary

[[email protected] ~]# parted /dev/sdb mkpart primary ext4 50G 220G
信息: You may need to update /etc/fstab.

[[email protected] ~]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志
1 1049kB 50.0GB 50.0GB primary
2 50.0GB 220GB 170GB primary

[[email protected] ~]# parted /dev/sdb mkpart primary ext4 220G 400G
信息: You may need to update /etc/fstab.

[[email protected] ~]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志
1 1049kB 50.0GB 50.0GB primary
2 50.0GB 220GB 170GB primary
3 220GB 400GB 180GB primary

[[email protected] ~]# parted /dev/sdb mkpart primary ext4 400G 450G
信息: You may need to update /etc/fstab.

[[email protected] ~]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志
1 1049kB 50.0GB 50.0GB primary
2 50.0GB 220GB 170GB primary
3 220GB 400GB 180GB primary
4 400GB 450GB 50.0GB primary

[[email protected] ~]# parted /dev/sdb mkpart primary ext4 450G 490.4G
信息: You may need to update /etc/fstab.

[[email protected] ~]#
[[email protected] ~]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志
1 1049kB 50.0GB 50.0GB primary
2 50.0GB 220GB 170GB primary
3 220GB 400GB 180GB primary
4 400GB 450GB 50.0GB primary
5 450GB 490GB 40.4GB primary
[[email protected] ~]#
[[email protected] ~]# mkf
mkfifo mkfs mkfs.ext2 mkfs.fat mkfs.vfat
mkfontdir mkfs.btrfs mkfs.ext3 mkfs.minix mkfs.xfs
mkfontscale mkfs.cramfs mkfs.ext4 mkfs.msdos
[[email protected] ~]# mkfs.ext
mkfs.ext2 mkfs.ext3 mkfs.ext4
[[email protected] ~]# 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
3055616 inodes, 12206848 blocks
610342 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2160066560
373 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

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
10379264 inodes, 41503744 blocks
2075187 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2189426688
1267 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

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mkfs.ext4 /dev/sdb3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
10993664 inodes, 43945472 blocks
2197273 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2191523840
1342 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

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mkfs.ext4 /dev/sdb4
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3055616 inodes, 12206848 blocks
610342 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2160066560
373 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

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

[[email protected] ~]# mkfs.ext4 /dev/sdb5
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2469152 inodes, 9870848 blocks
493542 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2157969408
302 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[[email protected] ~]#
[[email protected] ~]# fdisk - l
用法:
fdisk [选项] <磁盘> 更改分区表
fdisk [选项] -l <磁盘> 列出分区表
fdisk -s <分区> 给出分区大小(块数)

选项:
-b <大小> 扇区大小(512、1024、2048或4096)
-c[=<模式>] 兼容模式:“dos”或“nondos”(默认)
-h 打印此帮助文本
-u[=<单位>] 显示单位:“cylinders”(柱面)或“sectors”(扇区,默认)
-v 打印程序版本
-C <数字> 指定柱面数
-H <数字> 指定磁头数
-S <数字> 指定每个磁道的扇区数

[[email protected] ~]# fdisk -l

磁盘 /dev/sda:108.4 GB, 108447924224 字节,211812352 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000f1e5e

设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 211812351 105393152 8e Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

磁盘 /dev/sdb:490.4 GB, 490431578112 字节,957874176 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:gpt
Disk identifier: B191B484-44AF-438D-938F-11D274A49EB4

Start End Size Type Name

1 2048 97656831 46.6G Microsoft basic primary
2 97656832 429686783 158.3G Microsoft basic primary
3 429686784 781250559 167.7G Microsoft basic primary
4 781250560 878905343 46.6G Microsoft basic primary
5 878905344 957872127 37.7G Microsoft basic primary

磁盘 /dev/mapper/centos-root:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/mapper/centos-swap:8321 MB, 8321499136 字节,16252928 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

磁盘 /dev/mapper/centos-home:45.8 GB, 45843742720 字节,89538560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

创建多个目录挂载(同级目录)!
[[email protected] ~]#mkdir -p /{data,data_db,data_mm,data_zk,data-bak}
[[email protected] /]#
挂载
[[email protected] /]# mount /dev/sdb1 /data
[[email protected] /]# mount /dev/sdb2 /data_db
[[email protected] /]# mount /dev/sdb3 /data_mm
[[email protected] /]# mount /dev/sdb4 /data_zk
[[email protected] /]# mount /dev/sdb5 /data_bak
[[email protected] /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 4.2G 46G 9% /
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 35M 7.6G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/centos-home 43G 38M 43G 1% /home
/dev/sda1 497M 207M 290M 42% /boot
tmpfs 1.6G 12K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/sdb1 46G 53M 44G 1% /data
/dev/sdb2 156G 61M 148G 1% /data_db
/dev/sdb3 165G 61M 157G 1% /data_mm
/dev/sdb4 46G 53M 44G 1% /data_zk
/dev/sdb5 37G 49M 35G 1% /data_bak
[[email protected] /]#
添加开机自启
[[email protected] /]# vi /etc/fstab
#

/etc/fstab

Created by anaconda on Thu May 10 21:49:38 2018

#

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/centos-root / xfs defaults 0 0
UUID=b1d9e140-abb0-4d5c-b79e-fdd0ef5b5c3d /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
~
~

#

/etc/fstab

Created by anaconda on Thu May 10 21:49:38 2018

#

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/centos-root / xfs defaults 0 0
UUID=b1d9e140-abb0-4d5c-b79e-fdd0ef5b5c3d /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/sdb3 on /data_mm type ext4 (rw,relatime,seclabel,data=ordered)
"/etc/fstab" 17L, 916C written
[[email protected] /]#
[[email protected] /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 50G 4.2G 46G 9% /
devtmpfs 7.7G 0 7.7G 0% /dev
tmpfs 7.7G 0 7.7G 0% /dev/shm
tmpfs 7.7G 35M 7.6G 1% /run
tmpfs 7.7G 0 7.7G 0% /sys/fs/cgroup
/dev/mapper/centos-home 43G 38M 43G 1% /home
/dev/sda1 497M 207M 290M 42% /boot
tmpfs 1.6G 12K 1.6G 1% /run/user/42
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/sdb1 46G 53M 44G 1% /data
/dev/sdb2 156G 61M 148G 1% /data_db
/dev/sdb3 165G 61M 157G 1% /data_mm
/dev/sdb4 46G 53M 44G 1% /data_zk
/dev/sdb5 37G 49M 35G 1% /data_bak
[[email protected] /]#
[[email protected] /]# parted /dev/sdb print
Model: DELL PERC H330 Adp (scsi)
Disk /dev/sdb: 490GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name 标志
1 1049kB 50.0GB 50.0GB ext4 primary
2 50.0GB 220GB 170GB ext4 primary
3 220GB 400GB 180GB ext4 primary
4 400GB 450GB 50.0GB ext4 primary
5 450GB 490GB 40.4GB ext4 primary

以上是关于Linux磁盘分区的主要内容,如果未能解决你的问题,请参考以下文章

linux怎样查看磁盘分区情况

Linux 磁盘分区详解

Linux 磁盘 操作

linux系统的磁盘分区有哪几种?

Linux磁盘管理

linux磁盘分区fdisk分区和parted分区