[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
fdisk是分区工具:fdisk /dev/vdb,进入分区工具设置。
[root@runsdata-test-0004 ~]# 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 0x051e2cc7.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
输入m命令,则是查看有哪些命令可以使用。其中可以先看看这个数据盘有什么分区了。
输入p命令,查看该数据盘已经有哪些分区
Command (m for help): p
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x051e2cc7
Device Boot Start End Blocks Id System
Command (m for help):
可以看出这块数据盘暂时还没有任何分区,那么下面我先来进行分区。
下面进入分区,‘n’选一个分区类型,如没有其他设置可按默认下到返回m for help处。最后按'w'保存设置。
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-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
Command (m for help): p
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x051e2cc7
Device Boot Start End Blocks Id System
/dev/vdb1 2048 104857599 52427776 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 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: 0x051e2cc7
Device Boot Start End Blocks Id System
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
根据上面的步骤,再对另一个数据盘进行分区,执行如下:
分区:
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# fdisk /dev/vdc
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 0x420d8007.
Command (m for help): p
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x420d8007
Device Boot Start End Blocks Id System
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-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
设置为LVM
[root@runsdata-test-0004 ~]# fdisk /dev/vdc
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): p
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x420d8007
Device Boot Start End Blocks Id System
/dev/vdc1 2048 104857599 52427776 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x420d8007
Device Boot Start End Blocks Id System
/dev/vdc1 2048 104857599 52427776 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@runsdata-test-0004 ~]#
创建物理卷 PV
安装pv系列命令, yum install lvm2 -y
阿里云的服务器默认没有安装pv的相关命令的。
[root@runsdata-test-0004 ~]# pvcreate
-bash: pvcreate: command not found
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# fdisk -l | grep dev
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
/dev/vda1 * 2048 83884031 41940992 83 Linux
Disk /dev/vdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
/dev/vdb1 2048 104857599 52427776 8e Linux LVM
Disk /dev/vdc: 53.7 GB, 53687091200 bytes, 104857600 sectors
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvcreate /dev/vdb
vdb vdb1
[root@runsdata-test-0004 ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]#
查看创建好的物理卷
[root@runsdata-test-0004 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 lvm2 --- <50.00g <50.00g
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# pvdisplay
"/dev/vdb1" is a new physical volume of "<50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <50.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID oMzorH-1mfB-0VEy-eZDB-HHU3-UM9C-0EoPTU
[root@runsdata-test-0004 ~]#
[root@runsdata-test-0004 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/docker
LV Name docker
VG Name vgdata
LV UUID XWcgud-iAYP-j2Mo-x8kq-SjQ2-edP2-Usa4RZ
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:57:01 +0800
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
--- Logical volume ---
LV Path /dev/vgdata/data
LV Name data
VG Name vgdata
LV UUID HVfQpR-Zs81-RFiZ-rAFC-lBMk-bMhe-MTB1zl
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:58:36 +0800
LV Status available
# open 0
LV Size 49.00 GiB
Current LE 12544
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
[root@runsdata-test-0004 ~]#
那么这时候已经有docker、data两个逻辑卷了,下面就是进行格式化,目录的挂载了。
逻辑卷格式化
执行lvdisplay查看逻辑卷信息,获取逻辑卷LV的Path
对逻辑卷进行格式化mkfs.ext4 /dev/vgdata/docker
## 查看lv的详细信息
[root@runsdata-test-0004 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/docker
LV Name docker
VG Name vgdata
LV UUID XWcgud-iAYP-j2Mo-x8kq-SjQ2-edP2-Usa4RZ
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:57:01 +0800
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0
--- Logical volume ---
LV Path /dev/vgdata/data
LV Name data
VG Name vgdata
LV UUID HVfQpR-Zs81-RFiZ-rAFC-lBMk-bMhe-MTB1zl
LV Write Access read/write
LV Creation host, time runsdata-test-0004, 2018-12-10 13:58:36 +0800
LV Status available
# open 0
LV Size 49.00 GiB
Current LE 12544
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
## 对逻辑卷进行ext4格式化
[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/docker
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
3276800 inodes, 13107200 blocks
655360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
400 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: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
## 对逻辑卷进行ext4格式化
[root@runsdata-test-0004 ~]# mkfs.ext4 /dev/vgdata/data
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
3211264 inodes, 12845056 blocks
642252 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2162163712
392 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: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@runsdata-test-0004 ~]#
挂载文件目录
[root@runsdata-test-0004 ~]# cd /
[root@runsdata-test-0004 /]# ls
bin dev home lib64 media opt root sbin sys usr
boot etc lib lost+found mnt proc run srv tmp var
[root@runsdata-test-0004 /]# mkdir docker
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mount /dev/vgdata/docker docker
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mkdir data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# mount /dev/vgdata/data data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 1.5G 36G 4% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 352K 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/vgdata-docker 50G 53M 47G 1% /docker
/dev/mapper/vgdata-data 49G 53M 46G 1% /data
[root@runsdata-test-0004 /]#
[root@runsdata-test-0004 docker]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sun Oct 15 15:19:00 2017
#
# 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=eb448ab..省略...6a31 / ext4 defaults 1 1
/dev/mapper/vgdata-docker /docker ext4 defaults 1 1
/dev/mapper/vgdata-data /data ext4 defaults 1 1