Skip to content


linux下为新硬盘创建lvm分区

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

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

chkconfig haldaemon on chkconfig messagebus on #centos6 没有kudzu服务改用udev chkconfig kudzu on

认出了新硬盘/dev/sdc

fdisk -l

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

查看现有pv

pvdisplay

— Physical volume — PV Name /dev/sdb1 VG Name VolGroup01 PV Size 136.73 GB / not usable 11.78 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 4375 Free PE 0 Allocated PE 4375 PV UUID p2QSKt-hLuG-xGF5-Cj8t-9IxX-cKCf-hP7hIu — Physical volume — PV Name /dev/sda3 VG Name VolGroup00 PV Size 128.54 GB / not usable 10.32 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 4113 Free PE 0 Allocated PE 4113 PV UUID wdCg83-8jEM-XQtP-gmuX-lYor-IpWn-Hve2mr

对新硬盘分区,lvm的id为8e

fdisk /dev/sdc

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 17849. 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/sdc: 146.8 GB, 146815737856 bytes 255 heads, 63 sectors/track, 17849 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-17849, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-17849, default 17849): Using default value 17849 Command (m for help): p Disk /dev/sdc: 146.8 GB, 146815737856 bytes 255 heads, 63 sectors/track, 17849 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 17849 143372061 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdc: 146.8 GB, 146815737856 bytes 255 heads, 63 sectors/track, 17849 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdc1 1 17849 143372061 8e Linux LVM Command (m for help): w

创建pv

# pvcreate /dev/sdc1 Physical volume “/dev/sdc1” successfully created # pvdisplay — Physical volume — PV Name /dev/sdb1 VG Name VolGroup01 PV Size 136.73 GB / not usable 11.78 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 4375 Free PE 0 Allocated PE 4375 PV UUID p2QSKt-hLuG-xGF5-Cj8t-9IxX-cKCf-hP7hIu — Physical volume — PV Name /dev/sda3 VG Name VolGroup00 PV Size 128.54 GB / not usable 10.32 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 4113 Free PE 0 Allocated PE 4113 PV UUID wdCg83-8jEM-XQtP-gmuX-lYor-IpWn-Hve2mr “/dev/sdc1” is a new physical volume of “136.73 GB” — NEW Physical volume — PV Name /dev/sdc1 VG Name PV Size 136.73 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID rifdUK-ACXa-hGlM-L5iD-UkZ5-p4It-pshfwd

创建vg

# vgcreate VolGroup02 /dev/sdc1 Volume group “VolGroup02” successfully created # vgdisplay — Volume group — VG Name VolGroup02 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 136.73 GB PE Size 4.00 MB Total PE 35002 Alloc PE / Size 0 / 0 Free PE / Size 35002 / 136.73 GB VG UUID YLvkVA-OZQJ-p3yZ-5fEg-4xmH-dXMF-6ZcqTY — Volume group — VG Name VolGroup01 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 136.72 GB PE Size 32.00 MB Total PE 4375 Alloc PE / Size 4375 / 136.72 GB Free PE / Size 0 / 0 VG UUID bTRPY7-sETF-7yrw-8Iaa-jgMp-msLb-VFf9Pv — Volume group — VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 128.53 GB PE Size 32.00 MB Total PE 4113 Alloc PE / Size 4113 / 128.53 GB Free PE / Size 0 / 0 VG UUID dZu73K-djmf-Qqes-7Bl2-NcGr-12cx-2ygDPt

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

# lvcreate -l 100%FREE -n /dev/VolGroup02/LogVol00 VolGroup02 Logical volume “LogVol00” created # lvdisplay — Logical volume — LV Name /dev/VolGroup02/LogVol00 VG Name VolGroup02 LV UUID TThlLG-BUNw-smr9-Cv1d-cv8D-1V8i-cB0Hfa LV Write Access read/write LV Status available # open 0 LV Size 136.73 GB Current LE 35002 Segments 1 Allocation inherit Read ahead sectors auto – currently set to 256 Block device 253:3 — Logical volume — LV Name /dev/VolGroup01/LogVol00 VG Name VolGroup01 LV UUID 0JbGWl-ivcx-g4WL-JHY7-RcXc-hEM5-V3htC1 LV Write Access read/write LV Status available # open 1 LV Size 136.72 GB Current LE 4375 Segments 1 Allocation inherit Read ahead sectors auto – currently set to 256 Block device 253:2 — Logical volume — LV Name /dev/VolGroup00/LogVol01 VG Name VolGroup00 LV UUID cZ3Vnw-PMIx-LUNQ-N53R-etKc-s1BS-AmQE82 LV Write Access read/write LV Status available # open 1 LV Size 118.53 GB Current LE 3793 Segments 1 Allocation inherit Read ahead sectors auto – currently set to 256 Block device 253:0 — Logical volume — LV Name /dev/VolGroup00/LogVol00 VG Name VolGroup00 LV UUID R5fS7y-9649-kyZi-VFmn-24lh-ju2w-Uk7TzY LV Write Access read/write LV Status available # open 1 LV Size 10.00 GB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto – currently set to 256 Block device 253:1

格式化分区 linux的硬盘分区程序会自动为root或指定的用户保留一定的磁盘空间默认是5%,利用mke2fs的-m reserved-percentage选项可以调整这个设置来获得更多的磁盘空间且不影响性能。而在创建了文件系统之后,用户可以用tune2fs来修 改这个设置比如tune2fs -m 1 /dev/sdc1 可以将保留的空间设置为1% 1792102 blocks (5.00%) reserved for the super user

# mkfs -t ext3 /dev/VolGroup02/LogVol00 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 17924096 inodes, 35842048 blocks 1792102 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 1094 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, 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 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

挂载分区

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

启动后自动挂载

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

测试写入

#cd /data #touch testfile

===================== 2012-12-14更新 释放Linux系统预留的硬盘空间,增加-m 1 可以增加空间

mkfs -t ext3 -m 1 /dev/VolGroup02/LogVol00

Posted in linux 维护优化.

Tagged with , , .


No Responses (yet)

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.