一、普通磁盘分区管理方式
1.对磁盘进行分区
列出磁盘
# fdisk -l
# fdisk /dev/vdb
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 0x4765885b.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-2097151999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151999, default 2097151999):
Using default value 2097151999
Partition 1 of type Linux and of size 1000 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x635e6c7d
Device Boot Start End Blocks Id System
/dev/vda1 2048 83886079 41942016 83 Linux
Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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: 0x4765885b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2097151999 1048574976 83 Linux
2.对磁盘格式化成ext4格式
# mkfs.ext4 /dev/vdb1
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
65536000 inodes, 262143744 blocks
13107187 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2409627648
8000 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
3.将新的磁盘挂载在/data目录下
mkdir /data
# mount /dev/vdb1 /data
查看是否挂载成功
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 1.3G 37G 4% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 292K 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/vdb1 ext4 985G 77M 935G 1% /data
4.添加自动挂载,重启系统后依然生效
vim /etc/fstab
/dev/vdb1 /data ext4 defaults 0 0
也可以通过uuid的方式进行挂载
# mkdir /data# mount /dev/vdb1 /data
①使用lsblk命令可以清晰的获取全局的块设备布局
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
vda 253:0 0 40G 0 disk
└─vda1 253:1 0 40G 0 part /
vdb 253:16 0 150G 0 disk
└─vdb1 253:17 0 150G 0 part
②使用blkid命令可以获取设备的UUID,复制记下vdb1的UUID
# blkid
/dev/vda1: UUID="af414ad8-9936-46cd-b074-528854656fcd" TYPE="ext4"
/dev/vdb1: UUID="a2dc5e87-a07a-4976-86c3-d13b3d264124" TYPE="ext4"
③开机挂载磁盘
vim /etc/fstab
UUID=a2dc5e87-a07a-4976-86c3-d13b3d264124 /data ext4 defaults 0 0
二、逻辑卷的方式
yum install -y lvm2 vim unzip iftop
# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x635e6c7d
Device Boot Start End Blocks Id System
/dev/vda1 2048 83886079 41942016 83 Linux
Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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
# fdisk /dev/vdb
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 0x31ab9b87.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-4194303999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303999, default 4194303999):
Using default value 4194303999
Partition 1 of type Linux and of size 2 TiB is set
Selected partition 1
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x