1. 以Redhat 7.2为例
1.1. 磁盘分区
1. 查看磁盘分区,可以发现sdb还没有分区。
[root@server01 ~]# fdisk -l
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 /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0007263c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 2508799 1048576 82 Linux swap / Solaris
/dev/sda3 2508800 20971519 9231360 83 Linux
2. 使用parted进行分区,其中p是查看当前分区,q是退出。
[root@server01 ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Error: /dev/sdb: unrecognised disk label
Model: ATA VMware Virtual I (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
(parted)
(parted) mklabel gpt
(parted) mkpart
Partition name? []? sdb1
File system type? [ext2]? ext4
Start? 0
End? -1
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i
(parted)
(parted)
(parted) p
Model: ATA VMware Virtual I (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 21.5GB 21.5GB sdb1
(parted) q
Information: You may need to update /etc/fstab.
[root@server01 ~]#
3. 分区后查看
[root@server01 ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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: gpt
# Start End Size Type Name
1 34 41941087 20G Microsoft basic sdb1
Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0007263c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 2508799 1048576 82 Linux swap / Solaris
/dev/sda3 2508800 20971519 9231360 83 Linux
4. 执行partprobe或重启
[root@server01~]# partprobe
Error: Error informing the kernel about modifications to partition /dev/sdb1 -- Device or resource busy. This means Linux won't know about any changes you made to /dev/sdb1 until you reboot -- so you shouldn't mount it or use it in any way before rebooting.
Error: Failed to add partition 1 (Device or resource busy)
[root@server01 ~]# reboot
1.2. 格式化
1. 分区后需要进行格式化。
[root@server01 ~]# mkfs.ext4 /dev/sdb1
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
1310720 inodes, 5242631 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
1.3. 挂载
1. 方法一是直接mount,但操作系统重启后失效。
[root@server01 ~]# mount /dev/sdb1 /opt/
[root@server01 ~]# df -h /opt/
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 20G 45M 19G 1% /opt
2. 方法二是编辑/etc/fstab文件,重启后仍生效。要使当前生效请执行mount -a。
#添加如下内容
/dev/sdb1 /opt ext4 defaults 0 0
[root@server01 ~]# mount -a
[root@server01 ~]# df -h /opt/
Filesystem Size Used Avail Use% Mounted on
/dev/sdb1 20G 45M 19G 1% /opt