Synopsis:
fdisk只能创建mbr分区,所以创建的分区大小最大为2TB
fdisk -l 列出所有磁盘和分区信息
disk label=dos #MBR
disk laber=gpt #GPT
因为新挂载的硬盘遵循udev命名规则,例如SCSI接口会显示为sd[a-z]
下面演示对一块新硬盘进行设置分区表,创建分区,格式化,挂载(永久挂载)等基本操作。
例如 新挂载的硬盘为sdb 系统识别的第二块SCSI接口硬盘
[root@localhost ~]# 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): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-41943039, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +4G
Partition 2 of type Linux and of size 4 GiB is set
Command (m for help): p
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: dos
Disk identifier: 0x00737d72
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 12584959 4194304 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partprobe
[root@localhost ~]# partprobe
[root@localhost ~]# mkdir -p /tmp/app
[root@localhost ~]# mkfs.ext4 /dev/sdb2
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
262144 inodes, 1048576 blocks
52428 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 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: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mount /dev/sdb2 /tmp/app/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 3.1G 14G 18% /
/dev/sdb1 2.0G 3.1M 1.9G 1% /tmp/backup
/dev/sda1 1014M 195M 820M 20% /boot
tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb2 3.9G 16M 3.6G 1% /tmp/app
最后为了在下次重启时能够自动挂载,需要修改 /etc/fstab 配置文件
[root@localhost ~]# vi /etc/fstab
/dev/sdb2 /tmp/backup ext4 defaults 0 0