Linux中的逻辑卷
逻辑卷可以很灵活的对Linux中的挂载点在线的扩容存储以及收缩,本文罗列如何在Linux中应用逻辑卷的技术细节。
1.准备好存储介质
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@em12c ~]# fdisk -l Disk /dev/sda: 21.4 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 38 305203+ 83 Linux /dev/sda2 39 2353 18595237+ 83 Linux /dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris Disk /dev/sdb: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk /dev/sdb doesn't contain a valid partition table [root@em12c ~]# |
2.对存储介质分区
Shell Log
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 |
[root@em12c ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. The number of cylinders for this disk is set to 3916. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): p Disk /dev/sdb: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-3916, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-3916, default 3916): Using default value 3916 Command (m for help): p Disk /dev/sdb: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 3916 31455238+ 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@em12c ~]# |
在操作系统中应用分区表的改变
1 2 3 4 5 |
[root@em12c ~]# partprobe /dev/sdb [root@em12c ~]# ll /dev/ | grep --color sdb brw-r----- 1 root disk 8, 16 Aug 9 18:02 sdb brw-r----- 1 root disk 8, 17 Aug 9 18:09 sdb1 [root@em12c ~]# |
3.制作PV
从这一步开始,就是对逻辑卷配置的开始。
Shell Log
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@em12c ~]# pvcreate /dev/sdb1 dev_is_mpath: failed to get device for 8:17 Writing physical volume data to disk "/dev/sdb1" Physical volume "/dev/sdb1" successfully created [root@em12c ~]# [root@em12c ~]# pvdisplay "/dev/sdb1" is a new physical volume of "30.00 GB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 30.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID LTYYRO-tx2H-eEDl-a1ts-9UEX-3Hb0-vMlsU6 [root@em12c ~]# |
4.制作VG
Shell Log
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 |
[root@em12c ~]# vgcreate vg_cloudcontrol /dev/sdb1 Volume group "vg_cloudcontrol" successfully created [root@em12c ~]# vgdisplay --- Volume group --- VG Name vg_cloudcontrol 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 30.00 GB PE Size 4.00 MB Total PE 7679 Alloc PE / Size 0 / 0 Free PE / Size 7679 / 30.00 GB VG UUID uW5yrI-hsUf-LfgM-TCHz-Q6jo-ocRQ-CVfirY [root@em12c ~]# |
5.制作LV
Shell Log
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@em12c ~]# lvcreate -L 29G -n lv_cloudcontrol vg_cloudcontrol Logical volume "lv_cloudcontrol" created [root@em12c ~]# lvdisplay --- Logical volume --- LV Name /dev/vg_cloudcontrol/lv_cloudcontrol VG Name vg_cloudcontrol LV UUID fo8NLZ-KUgF-GnoP-xnWp-SHhL-Y9EK-solKW2 LV Write Access read/write LV Status available # open 0 LV Size 29.00 GB Current LE 7424 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@em12c ~]# |
6.为逻辑卷添加文件系统类别
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@em12c ~]# mkfs.ext3 /dev/vg_cloudcontrol/lv_cloudcontrol mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 3801088 inodes, 7602176 blocks 380108 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 232 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@em12c ~]# |
7.挂载
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[root@em12c ~]# mkdir /cloudcontrol [root@em12c ~]# [root@em12c ~]# tail -n 1 /etc/fstab /dev/vg_cloudcontrol/lv_cloudcontrol /cloudcontrol ext3 defaults 0 0 [root@em12c ~]# [root@em12c ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 9.1G 7.3G 56% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 2.0G 0 2.0G 0% /dev/shm /dev/sr1 4.1G 4.1G 0 100% /iso [root@em12c ~]# mount -a [root@em12c ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 9.1G 7.3G 56% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 2.0G 0 2.0G 0% /dev/shm /dev/sr1 4.1G 4.1G 0 100% /iso /dev/mapper/vg_cloudcontrol-lv_cloudcontrol 29G 173M 27G 1% /cloudcontrol [root@em12c ~]# |
8.访问挂载点
1 2 3 |
[root@em12c ~]# ls /cloudcontrol/ lost+found [root@em12c ~]# |
————————————————————————————
Ending。
1 thought on “Linux中的逻辑卷”