linux下为新硬盘创建lvm分区

DELL R410本来有两块146G的硬盘,再新增一块146G硬盘
现在硬盘便宜了,天猫价650,另需硬盘托架一个70大洋.

开启硬件检测后重启服务器

  1. chkconfig haldaemon on
  2. chkconfig messagebus on
  3. #centos6 没有kudzu服务改用udev
  4. chkconfig kudzu on

认出了新硬盘/dev/sdc
# fdisk -l

  1. Disk /dev/sda: 146.8 GB, 146815733760 bytes
  2. 255 heads, 63 sectors/track, 17849 cylinders
  3. Units = cylinders of 16065 * 512 = 8225280 bytes
  4. Device Boot Start End Blocks Id System
  5. /dev/sda1 * 1 25 200781 83 Linux
  6. /dev/sda2 26 1069 8385930 82 Linux swap / Solaris
  7. /dev/sda3 1070 17849 134785350 8e Linux LVM
  8. Disk /dev/sdb: 146.8 GB, 146815733760 bytes
  9. 255 heads, 63 sectors/track, 17849 cylinders
  10. Units = cylinders of 16065 * 512 = 8225280 bytes
  11. Device Boot Start End Blocks Id System
  12. /dev/sdb1 * 1 17849 143372061 8e Linux LVM
  13. Disk /dev/sdc: 146.8 GB, 146815737856 bytes
  14. 255 heads, 63 sectors/track, 17849 cylinders
  15. Units = cylinders of 16065 * 512 = 8225280 bytes
  16. Disk /dev/sdc doesn’t contain a valid partition table

查看现有pv
# pvdisplay

  1. — Physical volume —
  2. PV Name /dev/sdb1
  3. VG Name VolGroup01
  4. PV Size 136.73 GB / not usable 11.78 MB
  5. Allocatable yes (but full)
  6. PE Size (KByte) 32768
  7. Total PE 4375
  8. Free PE 0
  9. Allocated PE 4375
  10. PV UUID p2QSKt-hLuG-xGF5-Cj8t-9IxX-cKCf-hP7hIu
  11. — Physical volume —
  12. PV Name /dev/sda3
  13. VG Name VolGroup00
  14. PV Size 128.54 GB / not usable 10.32 MB
  15. Allocatable yes (but full)
  16. PE Size (KByte) 32768
  17. Total PE 4113
  18. Free PE 0
  19. Allocated PE 4113
  20. PV UUID wdCg83-8jEM-XQtP-gmuX-lYor-IpWn-Hve2mr

对新硬盘分区,lvm的id为8e
# fdisk /dev/sdc

  1. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  2. Building a new DOS disklabel. Changes will remain in memory only,
  3. until you decide to write them. After that, of course, the previous
  4. content won’t be recoverable.
  5. The number of cylinders for this disk is set to 17849.
  6. There is nothing wrong with that, but this is larger than 1024,
  7. and could in certain setups cause problems with:
  8. 1) software that runs at boot time (e.g., old versions of LILO)
  9. 2) booting and partitioning software from other OSs
  10. (e.g., DOS FDISK, OS/2 FDISK)
  11. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  12. Command (m for help): p
  13. Disk /dev/sdc: 146.8 GB, 146815737856 bytes
  14. 255 heads, 63 sectors/track, 17849 cylinders
  15. Units = cylinders of 16065 * 512 = 8225280 bytes
  16. Device Boot Start End Blocks Id System
  17. Command (m for help): n
  18. Command action
  19. e extended
  20. p primary partition (1-4)
  21. p
  22. Partition number (1-4): 1
  23. First cylinder (1-17849, default 1):
  24. Using default value 1
  25. Last cylinder or +size or +sizeM or +sizeK (1-17849, default 17849):
  26. Using default value 17849
  27. Command (m for help): p
  28. Disk /dev/sdc: 146.8 GB, 146815737856 bytes
  29. 255 heads, 63 sectors/track, 17849 cylinders
  30. Units = cylinders of 16065 * 512 = 8225280 bytes
  31. Device Boot Start End Blocks Id System
  32. /dev/sdc1 1 17849 143372061 83 Linux
  33. Command (m for help): t
  34. Selected partition 1
  35. Hex code (type L to list codes): 8e
  36. Changed system type of partition 1 to 8e (Linux LVM)
  37. Command (m for help): p
  38. Disk /dev/sdc: 146.8 GB, 146815737856 bytes
  39. 255 heads, 63 sectors/track, 17849 cylinders
  40. Units = cylinders of 16065 * 512 = 8225280 bytes
  41. Device Boot Start End Blocks Id System
  42. /dev/sdc1 1 17849 143372061 8e Linux LVM
  43. Command (m for help): w

创建pv

  1. # pvcreate /dev/sdc1
  2. Physical volume “/dev/sdc1” successfully created
  3. # pvdisplay
  4. — Physical volume —
  5. PV Name /dev/sdb1
  6. VG Name VolGroup01
  7. PV Size 136.73 GB / not usable 11.78 MB
  8. Allocatable yes (but full)
  9. PE Size (KByte) 32768
  10. Total PE 4375
  11. Free PE 0
  12. Allocated PE 4375
  13. PV UUID p2QSKt-hLuG-xGF5-Cj8t-9IxX-cKCf-hP7hIu
  14. — Physical volume —
  15. PV Name /dev/sda3
  16. VG Name VolGroup00
  17. PV Size 128.54 GB / not usable 10.32 MB
  18. Allocatable yes (but full)
  19. PE Size (KByte) 32768
  20. Total PE 4113
  21. Free PE 0
  22. Allocated PE 4113
  23. PV UUID wdCg83-8jEM-XQtP-gmuX-lYor-IpWn-Hve2mr
  24. “/dev/sdc1” is a new physical volume of “136.73 GB”
  25. — NEW Physical volume —
  26. PV Name /dev/sdc1
  27. VG Name
  28. PV Size 136.73 GB
  29. Allocatable NO
  30. PE Size (KByte) 0
  31. Total PE 0
  32. Free PE 0
  33. Allocated PE 0
  34. PV UUID rifdUK-ACXa-hGlM-L5iD-UkZ5-p4It-pshfwd

创建vg

  1. # vgcreate VolGroup02 /dev/sdc1
  2. Volume group “VolGroup02” successfully created
  3. # vgdisplay
  4. — Volume group —
  5. VG Name VolGroup02
  6. System ID
  7. Format lvm2
  8. Metadata Areas 1
  9. Metadata Sequence No 1
  10. VG Access read/write
  11. VG Status resizable
  12. MAX LV 0
  13. Cur LV 0
  14. Open LV 0
  15. Max PV 0
  16. Cur PV 1
  17. Act PV 1
  18. VG Size 136.73 GB
  19. PE Size 4.00 MB
  20. Total PE 35002
  21. Alloc PE / Size 0 / 0
  22. Free PE / Size 35002 / 136.73 GB
  23. VG UUID YLvkVA-OZQJ-p3yZ-5fEg-4xmH-dXMF-6ZcqTY
  24. — Volume group —
  25. VG Name VolGroup01
  26. System ID
  27. Format lvm2
  28. Metadata Areas 1
  29. Metadata Sequence No 2
  30. VG Access read/write
  31. VG Status resizable
  32. MAX LV 0
  33. Cur LV 1
  34. Open LV 1
  35. Max PV 0
  36. Cur PV 1
  37. Act PV 1
  38. VG Size 136.72 GB
  39. PE Size 32.00 MB
  40. Total PE 4375
  41. Alloc PE / Size 4375 / 136.72 GB
  42. Free PE / Size 0 / 0
  43. VG UUID bTRPY7-sETF-7yrw-8Iaa-jgMp-msLb-VFf9Pv
  44. — Volume group —
  45. VG Name VolGroup00
  46. System ID
  47. Format lvm2
  48. Metadata Areas 1
  49. Metadata Sequence No 3
  50. VG Access read/write
  51. VG Status resizable
  52. MAX LV 0
  53. Cur LV 2
  54. Open LV 2
  55. Max PV 0
  56. Cur PV 1
  57. Act PV 1
  58. VG Size 128.53 GB
  59. PE Size 32.00 MB
  60. Total PE 4113
  61. Alloc PE / Size 4113 / 128.53 GB
  62. Free PE / Size 0 / 0
  63. VG UUID dZu73K-djmf-Qqes-7Bl2-NcGr-12cx-2ygDPt

创建逻辑卷,分配全部空间

  1. # lvcreate -l 100%FREE -n /dev/VolGroup02/LogVol00 VolGroup02
  2. Logical volume “LogVol00” created
  3. # lvdisplay
  4. — Logical volume —
  5. LV Name /dev/VolGroup02/LogVol00
  6. VG Name VolGroup02
  7. LV UUID TThlLG-BUNw-smr9-Cv1d-cv8D-1V8i-cB0Hfa
  8. LV Write Access read/write
  9. LV Status available
  10. # open 0
  11. LV Size 136.73 GB
  12. Current LE 35002
  13. Segments 1
  14. Allocation inherit
  15. Read ahead sectors auto
  16. – currently set to 256
  17. Block device 253:3
  18. — Logical volume —
  19. LV Name /dev/VolGroup01/LogVol00
  20. VG Name VolGroup01
  21. LV UUID 0JbGWl-ivcx-g4WL-JHY7-RcXc-hEM5-V3htC1
  22. LV Write Access read/write
  23. LV Status available
  24. # open 1
  25. LV Size 136.72 GB
  26. Current LE 4375
  27. Segments 1
  28. Allocation inherit
  29. Read ahead sectors auto
  30. – currently set to 256
  31. Block device 253:2
  32. — Logical volume —
  33. LV Name /dev/VolGroup00/LogVol01
  34. VG Name VolGroup00
  35. LV UUID cZ3Vnw-PMIx-LUNQ-N53R-etKc-s1BS-AmQE82
  36. LV Write Access read/write
  37. LV Status available
  38. # open 1
  39. LV Size 118.53 GB
  40. Current LE 3793
  41. Segments 1
  42. Allocation inherit
  43. Read ahead sectors auto
  44. – currently set to 256
  45. Block device 253:0
  46. — Logical volume —
  47. LV Name /dev/VolGroup00/LogVol00
  48. VG Name VolGroup00
  49. LV UUID R5fS7y-9649-kyZi-VFmn-24lh-ju2w-Uk7TzY
  50. LV Write Access read/write
  51. LV Status available
  52. # open 1
  53. LV Size 10.00 GB
  54. Current LE 320
  55. Segments 1
  56. Allocation inherit
  57. Read ahead sectors auto
  58. – currently set to 256
  59. Block device 253:1

格式化分区

  1. # mkfs -t ext3 /dev/VolGroup02/LogVol00
  2. mke2fs 1.39 (29-May-2006)
  3. Filesystem label=
  4. OS type: Linux
  5. Block size=4096 (log=2)
  6. Fragment size=4096 (log=2)
  7. 17924096 inodes, 35842048 blocks
  8. 1792102 blocks (5.00%) reserved for the super user
  9. First data block=0
  10. Maximum filesystem blocks=4294967296
  11. 1094 block groups
  12. 32768 blocks per group, 32768 fragments per group
  13. 16384 inodes per group
  14. Superblock backups stored on blocks:
  15. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  16. 4096000, 7962624, 11239424, 20480000, 23887872
  17. Writing inode tables: done
  18. Creating journal (32768 blocks): done
  19. Writing superblocks and filesystem accounting information:
  20. done
  21. This filesystem will be automatically checked every 23 mounts or
  22. 180 days, whichever comes first. Use tune2fs -c or -i to override.

挂载分区

  1. # mkdir /data
  2. # mount /dev/VolGroup02/LogVol00 /data
  3. # df -h
  4. 文件系统 容量 已用 可用 已用% 挂载点
  5. /dev/mapper/VolGroup00-LogVol01
  6. 115G 12G 98G 11% /
  7. /dev/mapper/VolGroup00-LogVol00
  8. 9.7G 152M 9.1G 2% /tmp
  9. /dev/mapper/VolGroup01-LogVol00
  10. 133G 35G 91G 28% /opt
  11. /dev/sda1 190M 13M 168M 7% /boot
  12. tmpfs 7.9G 92K 7.9G 1% /dev/shm
  13. /dev/mapper/VolGroup02-LogVol00
  14. 135G 188M 128G 1% /data

启动后自动挂载

  1. vi /etc/fstab
  2. /dev/VolGroup02/LogVol00 /data ext3 defaults 1 2

测试写入

  1. #cd /data
  2. #touch testfile

转自:http://blog.c1gstudio.com/archives/1536

此条目发表在Linux分类目录,贴了, , 标签。将固定链接加入收藏夹。