aliyun添加数据盘parted方式分区格式化和lvm挂载及数据盘的扩容
一、普通磁盘分区管理方式
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 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
# 规范的做法是在分区时需要一个修改磁盘分区格式为linux lvm 代码为8e的操作
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# cat /proc/partitions
major minor #blocks name
11 0 1048575 sr0
253 0 41943040 vda
253 1 41942016 vda1
253 16 2097152000 vdb
253 17 2097150976 vdb1
# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
# vgcreate myvg /dev/vdb1
Volume group "myvg" successfully created
# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 1.95 TiB
PE Size 4.00 MiB
Total PE 511999
Alloc PE / Size 0 / 0
Free PE / Size 511999 / 1.95 TiB
VG UUID RpMeCU-gIV2-kEe5-fe6C-8iVI-xe0i-vf4ocp
# lvcreate -L 1.95T -n mylv myvg
Rounding up size to full physical extent 1.95 TiB
Logical volume "mylv" created.
# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID e1nL7K-0qyc-BHt8-x9oO-1gGC-6qWn-a52o6x
LV Write Access read/write
LV Creation host, time iZ2ze47of4mpxkhhzcgjheZ, 2017-01-07 12:18:26 +0800
LV Status available
# open 0
LV Size 1.95 TiB
Current LE 511181
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
# mke2fs -t ext4 -b 2048 /dev/myvg/mylv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
130863104 inodes, 1046898688 blocks
52344934 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1315438592
63898 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
2048000, 3981312, 5619712, 10240000, 11943936, 35831808, 39337984,
51200000, 107495424, 256000000, 275365888, 322486272, 967458816
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
# mkdir /data
# mount /dev/myvg/mylv /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 356K 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/mapper/myvg-mylv ext4 2.0T 24M 1.9T 1% /data
开机自启动挂载分区
vim /etc/fstab
加入以下内容:
/dev/myvg/mylv /data ext4 defaults,noatime 0 0
# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue May 3 13:48:10 2016
#
# 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=80b9b662-0a1d-4e84-b07b-c1bf19e72d97 / ext4 defaults 1 1
/dev/myvg/mylv /data ext4 defaults,noatime 0 0
逻辑卷扩容的示例
# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 120.00 GiB
PE Size 4.00 MiB
Total PE 30719
Alloc PE / Size 28160 / 110.00 GiB
Free PE / Size 2559 / 10.00 GiB
VG UUID v5LSS8-E5HW-htEL-ioet-Up3T-zUFz-vtCzlA
[root@mini2 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 30G 1.8G 29G 6% /
devtmpfs devtmpfs 907M 0 907M 0% /dev
tmpfs tmpfs 917M 0 917M 0% /dev/shm
tmpfs tmpfs 917M 8.6M 908M 1% /run
tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup
/dev/mapper/centos-data xfs 40G 33M 40G 1% /data
/dev/mapper/myvg-mylv ext4 109G 19M 103G 1% /aliyun
/dev/sda1 xfs 297M 115M 183M 39% /boot
tmpfs tmpfs 184M 0 184M 0% /run/user/0
1.新增一块60G的硬盘,分区
# fdisk /dev/sdc
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 0x58d7841e.
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.
2.将新增加的分区/dev/sdc1扩容到物理卷myvg中
# vgextend myvg /dev/sdc1
Physical volume "/dev/sdc1" successfully created
Volume group "myvg" successfully extended
# 可以看到由10G扩展到了59.99G
[root@mini2 ~]# vgdisplay myvg
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 169.99 GiB
PE Size 4.00 MiB
Total PE 43518
Alloc PE / Size 28160 / 110.00 GiB
Free PE / Size 15358 / 59.99 GiB
VG UUID v5LSS8-E5HW-htEL-ioet-Up3T-zUFz-vtCzlA
# lvdisplay /dev/myvg/mylv
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID 3H0Qgm-tDJr-BJ96-Y0Vh-TMOE-1EZv-DN3qUE
LV Write Access read/write
LV Creation host, time mini2, 2017-01-07 13:55:37 +0800
LV Status available
# open 1
LV Size 110.00 GiB
Current LE 28160
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
3.扩展物理边界为150G
[root@mini2 ~]# lvextend -L 150G /dev/myvg/mylv
Size of logical volume myvg/mylv changed from 110.00 GiB (28160 extents) to 150.00 GiB (38400 extents).
Logical volume mylv successfully resized.
可以看到已经有110变成了150G
[root@mini2 ~]# lvdisplay /dev/myvg/mylv
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID 3H0Qgm-tDJr-BJ96-Y0Vh-TMOE-1EZv-DN3qUE
LV Write Access read/write
LV Creation host, time mini2, 2017-01-07 13:55:37 +0800
LV Status available
# open 1
LV Size 150.00 GiB
Current LE 38400
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@mini2 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 30G 1.8G 29G 6% /
devtmpfs devtmpfs 907M 0 907M 0% /dev
tmpfs tmpfs 917M 0 917M 0% /dev/shm
tmpfs tmpfs 917M 8.6M 908M 1% /run
tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup
/dev/mapper/centos-data xfs 40G 33M 40G 1% /data
/dev/mapper/myvg-mylv ext4 109G 19M 103G 1% /aliyun
/dev/sda1 xfs 297M 115M 183M 39% /boot
tmpfs tmpfs 184M 0 184M 0% /run/user/0
4.扩展逻辑边界,可以看到磁盘分区/aliyun由109G变成了148G
[root@mini2 ~]# resize2fs /dev/myvg/mylv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/myvg/mylv is mounted on /aliyun; on-line resizing required
old_desc_blocks = 110, new_desc_blocks = 150
The filesystem on /dev/myvg/mylv is now 78643200 blocks long.
[root@mini2 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 30G 1.8G 29G 6% /
devtmpfs devtmpfs 907M 0 907M 0% /dev
tmpfs tmpfs 917M 0 917M 0% /dev/shm
tmpfs tmpfs 917M 8.6M 908M 1% /run
tmpfs tmpfs 917M 0 917M 0% /sys/fs/cgroup
/dev/mapper/centos-data xfs 40G 33M 40G 1% /data
/dev/mapper/myvg-mylv ext4 148G 17M 141G 1% /aliyun
/dev/sda1 xfs 297M 115M 183M 39% /boot
tmpfs tmpfs 184M 0 184M 0% /run/user/0
扩容阿里云数据盘由1T变为2T,非lvm
1.登录云服务器管理控制台。
更多 > 磁盘扩容将磁盘容量改为2000G
2.重启服务器,进入实例列表页面,点击 更多,选择 重启(注意:一定要通过控制台重启,通过shell进去重启ecs不生效)
3.取消挂载
# umount /data
umount: /data: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
# 提示/data目标繁忙,找到这些进程强制结束
# fuser -m /data
/data: 1080c 1081cm
# ps -ef|grep 1080
yunva 1080 1 0 15:05 ? 00:00:00 bash -c cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &
yunva 1081 1080 98 15:05 ? 00:08:11 /usr/java/jdk1.8.0_111/bin/java -Xms32g -Xmx32g -XX:+UseG1GC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -server -Djava.awt.headless=true
-Dfile.encoding=UTF-8 -Djna.nosys=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Xss256k -Des.path.home=/data/elasticsearch-5.0.1
-cp /data/elasticsearch-5.0.1/lib/elasticsearch-5.0.1.jar:/data/elasticsearch-5.0.1/lib/* org.elasticsearch.bootstrap.Elasticsearch
root 2027 1296 0 15:13 pts/1 00:00:00 grep --color=auto 1080
# kill -9 1080
# kill -9 1081
# 再次卸载成功
# umount /data
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 2.0G 36G 6% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 300K 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
# fdisk /dev/vdb
删除原有的/dev/vdb1分区
d
1
新建分区
n
p
1
w
# 如下提示表示成功
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4.检查文件系统,并变更文件系统大小
# e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 6083/65536000 files (6.5% non-contiguous), 221329845/262143744 blocks
# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 524287744 (4k) blocks.
The filesystem on /dev/vdb1 is now 524287744 blocks long.
重新挂载,看到已经成功了,启动里面的业务程序即可
# mount /dev/vdb1 /data
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 2.0G 36G 6% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 300K 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 2.0T 829G 1.1T 45% /data
当硬盘或者单个磁盘分区大于2T时的分区方法:
# 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: 6442.5 GB, 6442450944000 bytes, 12582912000 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: 0x9ac7dffd
Device Boot Start End Blocks Id System
2.使用parted工具进行分区(fdisk无法支持单个分区大于2T)
# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
# 1. 打印基本分区信息
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 6442GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
(parted) mklabel gpt# 2. 标记为gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) mkpart
# 3. 新建分区
Partition name? []? # 4. 保持默认
File system type? [ext2]? ext4 # 5. 文件系统分区格式为ext4
Start? # 6. 起始位置
End? -1# 7. 结束(整个磁盘)
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore# 8. 选择Ignore(忽略)
(parted) print# 9. 再次打印分区信息,此时已经分好区为6442G了
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 6442GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 6442GB 6442GB
# 如果不使用lvm逻辑分卷,此时直接退出然后 # mkfs.ext4 /dev/vdb1 分区,挂载即可
(parted) p
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 6442GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 6442GB 6442GB lvm
(parted) quit# 退出
Information: You may need to update /etc/fstab.
# 再次查看磁盘分区信息,此时已经分区成功了
# 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: 6442.5 GB, 6442450944000 bytes, 12582912000 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: 0x00000000
Device Boot Start End Blocks Id System
/dev/vdb1 1 4294967295 2147483647+ ee GPT
3.分区已经划分好,此时需要创建lvm:
①创建物理卷
# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
# pvdisplay
"/dev/vdb1" is a new physical volume of "5.86 TiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size 5.86 TiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID tbHjVp-Szmc-5q3O-S3eY-waTF-Ybzx-l3I7bR
②创建逻辑卷组
# vgcreate myvg /dev/vdb1
Volume group "myvg" successfully created
# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 5.86 TiB
PE Size 4.00 MiB
Total PE 1535999
Alloc PE / Size 0 / 0
Free PE / Size 1535999 / 5.86 TiB
VG UUID mQjQYq-uN4O-RUdV-0aZ3-he8g-aD4l-a2lhSc
③创建lv逻辑卷
# lvcreate -L 5.86T -n mylv myvg
Rounding up size to full physical extent 5.86 TiB
Volume group "myvg" has insufficient free space (1535999 extents): 1536164 required. # 超出大小
# lvcreate -L 5.8T -n mylv myvg
Rounding up size to full physical extent 5.80 TiB
Logical volume "mylv" created.
# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID 0xzuSU-BeVP-uUit-8DRl-8ytZ-az8E-W64gxp
LV Write Access read/write
LV Creation host, time iZ2zehv5i5lv499i7u6i5vZ, 2017-02-27 15:48:54 +0800
LV Status available
# open 0
LV Size 5.80 TiB
Current LE 1520436
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
④格式化
# mke2fs -t ext4 -b 4096 /dev/myvg/mylv
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
194617344 inodes, 1556926464 blocks
77846323 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3705667584
47514 block groups
32768 blocks per group, 32768 fragments per group
4096 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, 512000000, 550731776, 644972544
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
⑤挂载
# mkdir /data
# mount /dev/myvg/mylv /data
# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 40G 1.8G 36G 5% /
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 340K 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/mapper/myvg-mylv ext4 5.8T 89M 5.5T 1% /data
开机自启动挂载分区
vim /etc/fstab
加入以下内容:
/dev/myvg/mylv /data ext4 defaults,noatime 0 0
移除pv、移除vg的命令
pvremove /dev/vdb1
vgremove myvg
新购买的ECS数据盘1T,用了阿里云的400G数据盘作为模板
登录进去后数据盘只有400G,在控制台关闭ECS,重新初始化磁盘 [root@eus-timed-task01:~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 79G .0G 66G % /
tmpfs tmpfs .9G .9G % /dev/shm
[root@eus-timed-task01:~]# mount -a
[root@eus-timed-task01:~]# mount
/dev/vda1 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=,mode=)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) # 想通过格式化/dev/vdb1 成ext4 [root@eus-timed-task01:~]# mkfs.ext4 /dev/vdb1
mke2fs 1.41. (-May-)
/dev/vdb1 is apparently in use by the system; will not make a filesystem here! 解决办法:
[root@eus-timed-task01:~]# dmsetup status
VG_Data-lv_data: linear
[root@eus-timed-task01:~]# dmsetup remove_all
[root@eus-timed-task01:~]# demesup status
-bash: demesup: command not found
[root@eus-timed-task01:~]# dmsetup status
No devices found
[root@eus-timed-task01:~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created # lvm分区 [root@eus-timed-task01:~]# vgcreate myvg /dev/vdb1
Volume group "myvg" successfully created
[root@eus-timed-task01:~]# vgdisplay
--- Volume group ---
VG Name myvg
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 1000.00 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size /
Free PE / Size / 1000.00 GiB
VG UUID oeMYkq-8l6C-dHZx-In5b-3m8m-3jj5-dihQ3M --- Volume group ---
VG Name VG_Data
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 400.00 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 400.00 GiB
Free PE / Size /
VG UUID 6dlcbY-mLx3-spKv-DUQ3-Av2S-7fVD-ye8JVC # 磁盘使用率设置为100%
[root@eus-timed-task01:~]# lvcreate -l %VG -n mylv myvg
Logical volume "mylv" created.
[root@eus-timed-task01:~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvg/mylv
LV Name mylv
VG Name myvg
LV UUID iq0LKn-bDSO-QPAn-C0mV-jADG-vc4W-PRPawO
LV Write Access read/write
LV Creation host, time eus-timed-task01, -- :: -
LV Status available
# open
LV Size 1000.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/VG_Data/lv_data
LV Name lv_data
VG Name VG_Data
LV UUID Yn1sTI-gAop-kodn-cvsN-OYnN-fNES-n7l9uk
LV Write Access read/write
LV Creation host, time iZrj9citgdpobfu83gsgodZ, -- :: -
LV Status NOT available
LV Size 400.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto [root@eus-timed-task01:~]# mke2fs -t ext4 -b /dev/myvg/mylv
mke2fs 1.41. (-May-)
Filesystem label=
OS type: Linux
Block size= (log=)
Fragment size= (log=)
Stride= blocks, Stripe width= blocks
inodes, blocks
blocks (5.00%) reserved for the super user
First data block=
Maximum filesystem blocks=
block groups
blocks per group, fragments per group
inodes per group
Superblock backups stored on blocks:
, , , , , , , , ,
, , , , , , ,
, , , , Writing inode tables: done
Creating journal ( blocks): done
Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every mounts or
days, whichever comes first. Use tune2fs -c or -i to override.
[root@eus-timed-task01:~]# ls /data
[root@eus-timed-task01:~]# mount /dev/myvg/mylv /data
[root@eus-timed-task01:~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 79G .2G 69G % /
tmpfs tmpfs .9G .9G % /dev/shm
/dev/mapper/myvg-mylv
ext4 985G 23M 935G % /data
[root@eus-timed-task01:~]# vim /etc/fstab
/dev/myvg/mylv /data ext4 defaults,noatime # 重新启动看能否正常挂载
aliyun添加数据盘parted方式分区格式化和lvm挂载及数据盘的扩容的更多相关文章
- Linux系统添加硬盘设备(磁盘分区-格式化-挂载-使用)
当全新安装了一块新的硬盘设备后,为了更充分.更安全的利用硬盘空间首先要进行磁盘的分区, 然后格式化,最后挂载使用. 实例:对新添加的硬盘设备进行分区.格式化并挂载到/newFS目录. 第一步:在vmw ...
- Linux添加新硬盘,设置分区和开机自动挂载之图文教程!
虚拟机添加硬盘的步骤就不多废话了,主要列出添加硬盘后要进行设置的几个详细步骤: 1.查看磁盘信息:fdisk -ls 添加前如下图所示: 添加后如下图: 也可以用:ls /dev/sd*查看,如下图: ...
- oracle数据库数据转储最好方式(数据库表、数据结构和数据一并导出)
导入:使用plsql:Tools --> Import Tables --> SQL Inserts 得到的为sql文件,在转储的过程中当导入另一个库的时候老是报 “表或视图不存在” ...
- Virtualbox中Linux添加新磁盘并创建分区
原文:https://www.linuxidc.com/Linux/2017-01/139616.htm ----------------------------------------------- ...
- linux挂载新硬盘并进行分区格式化
最近要给小伙伴们写几篇文章,关于<linux下误删除文件之后该如何恢复>.对于没有进程占用的文件想要进行数据恢复,不同的文件系统格式需要使用不同的工具,比如:ext4.xfs等.我找遍了我 ...
- 详解Tensorflow数据读取有三种方式(next_batch)
转自:https://blog.csdn.net/lujiandong1/article/details/53376802 Tensorflow数据读取有三种方式: Preloaded data: 预 ...
- Spring 让 LOB 数据操作变得简单易行,LOB 代表大对象数据,包括 BLOB 和 CLOB 两种类型
转自:https://www.ibm.com/developerworks/cn/java/j-lo-spring-lob/index.html 概述 LOB 代表大对象数据,包括 BLOB 和 CL ...
- aliyun添加数据盘后的物理分区和lvm逻辑卷两种挂载方式
一.普通磁盘分区管理方式 1.对磁盘进行分区 列出磁盘 # fdisk -l # fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2). Change ...
- linux入门系列12--磁盘管理之分区、格式化与挂载
前面系列文章讲解了VI编辑器.常用命令.防火墙及网络服务管理,本篇将讲解磁盘管理相关知识. 本文将会介绍大量的Linux命令,其中有一部分在"linux入门系列5--新手必会的linux命令 ...
随机推荐
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- 4月1日->-4月15日 2周阶段性计划
4月1日->4月14日 ST表 树状数组 LCA 一周的时间,力求掌握这三个知识点并各刷五道题左右. 树状数组 ST表 LCA 然而:进展总比计划快(......什么鬼) 树状数组刷了5题,ST ...
- EClipse for PHP 中文乱码问题
UTF-8 格式的php,中文都是乱码. 如果此时在EClipse中输入中文会有 CP1252 错误( CP1252不支持xxxx ) 解决方法: windows->preferences-&g ...
- CPU温度问题
台式机和笔记本的CPU温度多少合适,过高会怎样, cpu温度跟环境温度有很大关系,夏天的时候会高一点的.一般CPU空闲的时候温度在50°以内,较忙时65°以内,全速工作时75°以内都是正常的,所以我们 ...
- conda常用命令总结
conda 一些背景历史以及如何安装这里就不说了,因为实在是漫天都在飞,随便都能找到相关的资料.我这里只是将平时常用到的 Conda 命令进行汇总,以备不时之需,因为我也是一个忘性极大的人,实在是记不 ...
- springmvc 中@Controller和@RestController的区别
@Controller和@RestController的区别? 官方文档:@RestController is a stereotype annotation that combines @Respo ...
- Css的前世今生
Css的基础知识扫盲 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. HTML的用法没有什么技巧,就是死记硬背,当然你不需要都记下来,能记住20个常用的标签基本上就OK了,其他不常用 ...
- Word不能添加目录?
我复制粘贴了一大把文字,标题也设置了,就是添加不了目录,也不知道是什么原因. 后来同事给我指点了一下,真是万分感激啊 比如下面这张图,第13章那么大的标题在那里,但是就是添加不了目录 原因是在于换行的 ...
- TCP/IP详解 卷1 第一章概述
第一章概述 1.2 分层 网络编程通常分不同层次进行开发,每一层负责不同的通信功能. 一个协议族比如TCP/IP,通常是一组不同层次上多个协议的组合.一般可以认为是是四层协议系统: 链路层:有时也称作 ...
- 文本编辑框QTextEdit
QTextEdit类是一个多行文本框控件,可以显示多行文本内容,当文本内容超出控件显示范围时,可以显示水平个垂直滚动条,Qtextedit不仅可以用来显示文本还可以用来显示HTML文档 import ...