4-06 12 views
1. 磁盘初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
[root@host-10-166-224-16 ~]# fdisk /dev/vdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x2aefce9a. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p Disk /dev/vdc: 107.4 GB, 107374182400 bytes 16 heads, 63 sectors/track, 208050 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2aefce9a Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 1 First cylinder (1-208050, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-208050, default 208050): Using default value 208050 Command (m for help): p Disk /dev/vdc: 107.4 GB, 107374182400 bytes 16 heads, 63 sectors/track, 208050 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2aefce9a Device Boot Start End Blocks Id System /dev/vdc1 1 208050 104857168+ 5 Extended Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (1-208050, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-208050, default 208050): Using default value 208050 Command (m for help): p Disk /dev/vdc: 107.4 GB, 107374182400 bytes 16 heads, 63 sectors/track, 208050 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2aefce9a Device Boot Start End Blocks Id System /dev/vdc1 1 208050 104857168+ 5 Extended /dev/vdc5 1 208050 104857137 83 Linux Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e Changed system type of partition 5 to 8e (Linux LVM) Command (m for help): p Disk /dev/vdc: 107.4 GB, 107374182400 bytes 16 heads, 63 sectors/track, 208050 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x2aefce9a Device Boot Start End Blocks Id System /dev/vdc1 1 208050 104857168+ 5 Extended /dev/vdc5 1 208050 104857137 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. |
如果是在线扩容
通过device/rescan刷新
1 2 3 4 |
[root@host-10-166-224-16 ~]# ls /sys/class/scsi_device/ 1:0:0:0 2:0:0:0 2:0:1:0 2:0:2:0 [root@host-10-166-224-16 ~]# echo 1 > /sys/class/scsi_device/2\:0\:2\:0/device/rescan #一般最大的就是最后添加的, |
2. 创建pv
1 2 |
[root@host-10-166-224-16 ~]# pvcreate /dev/vdc5 Physical volume "/dev/vdc5" successfully created |
3. 查看pv
1 2 3 4 |
[root@host-10-166-224-16 ~]# pvs PV VG Fmt Attr PSize PFree /dev/vdb5 vgdata lvm2 a-- 100.00g 1020.00m /dev/vdc5 lvm2 --- 100.00g 100.00g |
如果是在原有的磁盘上进行的扩容,也没有分区的情况
使用pvresize刷新PVSize
1 2 3 |
[root@host-10-166-224-16 ~]# pvresize /dev/sdc [root@host-10-166-224-16 ~]# lvextend -l +100%FREE /dev/vgdata/lvdata [root@host-10-166-224-16 ~]# resize2fs /dev/vgdata/lvdata |
3. 磁盘格式化
1 |
[root@host-10-166-224-16 ~]# mkfs.ext4 /dev/vdc5 |
4. 查看当前vg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[root@host-10-166-224-16 ~]# vgdisplay --- Volume group --- VG Name vgdata 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 100.00 GiB PE Size 4.00 MiB Total PE 25599 Alloc PE / Size 25344 / 99.00 GiB Free PE / Size 255 / 1020.00 MiB VG UUID rQ21KY-4Yr4-ise4-hz2S-3INi-L1oc-Gev3yR |
5. 扩展vg并查看
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[root@host-10-166-224-16 ~]# vgextend vgdata /dev/vdc5 Volume group "vgdata" successfully extended [root@host-10-166-224-16 ~]# vgdisplay --- Volume group --- VG Name vgdata 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 199.99 GiB PE Size 4.00 MiB Total PE 51198 Alloc PE / Size 25344 / 99.00 GiB Free PE / Size 25854 / 100.99 GiB VG UUID rQ21KY-4Yr4-ise4-hz2S-3INi-L1oc-Gev3yR |
6. 查看lv状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@host-10-166-224-16 ~]# lvdisplay --- Logical volume --- LV Path /dev/vgdata/lvdata1 LV Name lvdata1 VG Name vgdata LV UUID 6xFrQR-BMwi-cj8Q-WuaB-Wpj9-6hB4-cWtk2k LV Write Access read/write LV Creation host, time host-10-166-224-16, 2015-09-22 17:57:36 +0800 LV Status available # open 1 LV Size 99.00 GiB Current LE 25344 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 |
7. 扩展lv并查看
可以使用”lvextend -l 100%FREE /dev/vgdata/lvdata1″将剩余的空间全部扩充
注:如果用的是xfs格式的,使用xfs_growfs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[root@host-10-166-224-16 ~]# lvextend -L 199G /dev/vgdata/lvdata1 Size of logical volume vgdata/lvdata1 changed from 99.00 GiB (25344 extents) to 199.00 GiB (50944 extents). Logical volume lvdata1 successfully resized [root@host-10-166-224-16 ~]# lvdisplay --- Logical volume --- LV Path /dev/vgdata/lvdata1 LV Name lvdata1 VG Name vgdata LV UUID 6xFrQR-BMwi-cj8Q-WuaB-Wpj9-6hB4-cWtk2k LV Write Access read/write LV Creation host, time host-10-166-224-16, 2015-09-22 17:57:36 +0800 LV Status available # open 1 LV Size 199.00 GiB Current LE 50944 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@host-10-166-224-16 ~]# resize2fs /dev/vgdata/lvdata1 # 如果磁盘是xfs格式的,使用xfs_growfs resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vgdata/lvdata1 is mounted on /data; on-line resizing required old desc_blocks = 7, new_desc_blocks = 13 Performing an on-line resize of /dev/vgdata/lvdata1 to 52166656 (4k) blocks. The filesystem on /dev/vgdata/lvdata1 is now 52166656 blocks long. |
8. 查看磁盘信息
1 2 3 4 5 6 |
[root@host-10-166-224-16 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 20G 6.5G 13G 35% / tmpfs tmpfs 16G 0 16G 0% /dev/shm /dev/mapper/vgdata-lvdata1 ext4 196G 90G 97G 49% /data |
如果想赏钱,可以用微信扫描下面的二维码,一来能刺激我写博客的欲望,二来好维护云主机的费用; 另外再次标注博客原地址 itnotebooks.com 感谢!