★ CentOS 7 添加磁盘(MBR:分区与扩展)

4个月前 (01-29) Rain-li 软件使用 已收录 82℃

环境描述:

(本系统为CentOS 7)

需求:

一、此服务器上有一个10GB硬盘。
二、从10GB硬盘中,先建立200M分区,再扩展到500M。

思路:(分区---格式化---挂载---扩展)

< 分区 >

一、使用fdisk -l 命令查看分区的情况,由下图可以看到/dev/vdb为一个10GB的硬盘。
[root@localhost ~]# fdisk -l

 

Disk /dev/vda: 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: 0x00013f3eDevice Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux

Disk /dev/vdb: 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
[root@localhost ~]#

二、使用fdisk /dev/vdb命令,建立一个1GB的物理卷
[root@localhost ~]# 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 0xbb06798e.
Command (m for help): n      //如需要帮助,可以输入m进行查看。
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):        //p为主分区,e为扩展分区。
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):        //保持默认即可
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1G
Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): w       //输入w保存
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/vda: 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: 0x00013f3eDevice Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
Disk /dev/vdb: 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: 0xbb06798eDevice Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 83 Linux
三、建立200M的逻辑卷
[root@localhost ~]# pvcreate /dev/vdb1               //创建物理卷
Physical volume "/dev/vdb1" successfully created
[root@localhost ~]# vgcreate vg01 /dev/vdb1          //创建卷组
Volume group "vg01" successfully created
[root@localhost ~]# lvcreate -L 200M vg01 -n lv01             //创建一个200M的逻辑卷
Logical volume "lv01" created
[root@localhost ~]#

< 格式化 >

一、使用mkfs.ext4命令,对200M的逻辑卷进行格式化。
[root@localhost ~]# mkfs.ext4 /dev/vg01/lv01
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
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]#

< 挂载 >

一、创建挂载目录。
[root@localhost ~]# mkdir /mnt/200M
二、修改配置文件实现永久挂载。
[root@localhost ~]# vim /etc/fstab
/dev/vg01/lv01             /mnt/200M      ext4        defaults      0 0
[root@localhost ~]# cat /etc/fstab
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
#
# 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
#
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
/dev/vg01/lv01       /mnt/200M       ext4              defaults               0 0
[root@localhost ~]#
三、把/dev/vg01/lv01挂载到/mnt/200M/。
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.0G 7.1G 30% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 80K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
[root@localhost ~]# mount /dev/vg01/lv01 /mnt/200M/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.0G 7.1G 30% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 80K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vg01-lv01 190M 1.6M 175M 1% /mnt/200M
[root@localhost ~]#

< 扩展 >

将/dev/vg01/lv01扩展到500M
[root@localhost ~]# lvextend -L +300M /dev/vg01/lv01     //扩展逻辑卷
Extending logical volume lv01 to 500.00 MiB
Logical volume lv01 successfully resized
[root@localhost ~]# resize2fs /dev/vg01/lv01         //扩展文件系统
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg01/lv01 is mounted on /mnt/200M; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/vg01/lv01 is now 512000 blocks long.[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.0G 7.1G 30% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 80K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vg01-lv01      481M       2.3M     452M      1%       /mnt/200M
[root@localhost ~]#
博主

这货来去如风,什么鬼都没留下!!!

相关推荐

嗨、骚年、快来消灭0回复。