Linux磁盘卷组管理
PV、VG、LV
服务器磁盘分区情况:
[root@iZ25ou6jy8jZ ~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00060953 Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 322.1 GB, 322122547200 bytes 255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 [root@iZ25ou6jy8jZ ~]# [root@iZ25ou6jy8jZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 1.4G 18G 8% / tmpfs 1.9G 0 1.9G 0% /dev/shm
1. 查看有无安装lvm
# rpm -qa|grep lvm lvm2-libs-2.02.100-8.el6.x86_64 mesa-private-llvm-3.3-0.3.rc3.el6.x86_64 lvm2-2.02.100-8.el6.x86_64
2. 将磁盘/dev/xvdb分区并转为lvm磁盘
[root@iZ25ou6jy8jZ ~]# fdisk /dev/xvdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x035ef8d3. 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): n //n进入分区模式 Command action e extended p primary partition (1-4) p //设置为主分区 Partition number (1-4): 1 //设置分区号 First cylinder (1-39162, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-39162, default 39162): Using default value 39162 Command (m for help): p //查看当前分区情况 Disk /dev/xvdb: 322.1 GB, 322122547200 bytes 255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x035ef8d3 Device Boot Start End Blocks Id System /dev/xvdb1 1 39162 314568733+ 83 Linux Command (m for help): l //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 Command (m for help): t //t进入修改分区代码模式 Selected partition 1 Hex code (type L to list codes): 8e //设置为8e,即Linux LVM Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p //p打印出修改结果 Disk /dev/xvdb: 322.1 GB, 322122547200 bytes 255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x035ef8d3 Device Boot Start End Blocks Id System /dev/xvdb1 1 39162 314568733+ 8e Linux LVM Command (m for help): w //w保存修改并退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@iZ25ou6jy8jZ ~]# [root@iZ25ou6jy8jZ ~]# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00060953 Device Boot Start End Blocks Id System /dev/xvda1 * 1 2611 20970496 83 Linux Disk /dev/xvdb: 322.1 GB, 322122547200 bytes 255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x035ef8d3 Device Boot Start End Blocks Id System /dev/xvdb1 1 39162 314568733+ 8e Linux LVM [root@iZ25ou6jy8jZ ~]#
开始创建
3. 创建PV物理卷
[root@iZ25ou6jy8jZ ~]# pvcreate /dev/xvdb1 Physical volume "/dev/xvdb1" successfully created
4. 创建VG卷组
[root@iZ25ou6jy8jZ ~]# vgcreate VolGroup /dev/xvdb1 //VolGroup为卷组名称 Volume group "VolGroup" successfully created
5. 激活卷组
[root@iZ25ou6jy8jZ ~]# vgchange -a y VolGroup Volume group "VolGoup" not found Skipping volume group VolGoup
6. 创建LV逻辑卷
[root@iZ25ou6jy8jZ ~]# lvcreate -L 102400 -n data VolGroup Logical volume "data" created
102400代表100GB,data表示逻辑卷名称
删除LV逻辑卷:
如已经创建了文件系统并挂载,先umount已经挂载的目录
# umount /data/
# lvremove /dev/VolGroup/data
Do you really want to remove active logical volume content? [y/n]: y
Logical volume "data" successfully removed
扩展LV卷:
[root@iZ25hxew2yfZ ~]# lvextend -L +51200 /dev/VolGroup/data
Extending logical volume opt to 450.00 GiB
Logical volume opt successfully resized
刷新容量:
[root@iZ25hxew2yfZ ~]# resize2fs /dev/VolGroup/data
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/data is mounted on /opt; on-line resizing required
old desc_blocks = 25, new_desc_blocks = 29
Performing an on-line resize of /dev/VolGroup/data to 117964800 (4k) blocks.
The filesystem on /dev/VolGroup/data is now 117964800 blocks long.
7. 创建文件系统
[root@iZ25ou6jy8jZ ~]# mkfs.ext4 /dev/VolGroup/data //格式化为ext4 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6553600 inodes, 26214400 blocks 1310720 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 800 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 20 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@iZ25ou6jy8jZ ~]#
8. 挂载
[root@iZ25ou6jy8jZ ~]# mkdir /data [root@iZ25ou6jy8jZ ~]# mount /dev/VolGroup/data /data/ [root@iZ25ou6jy8jZ ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 20G 1.4G 18G 8% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/mapper/VolGroup-data 99G 188M 94G 1% /usr/local/data [root@iZ25ou6jy8jZ ~]#
9.开机时挂载,在/etc/fstab末尾添加以下:
/dev/VolGroup/data /data ext4 defaults 0 0
10.reboot重启服务器测试是否成功。
共有 0 条评论