歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 新磁盤如何做LVM

新磁盤如何做LVM

日期:2017/3/3 15:55:56   编辑:關於Linux

一個新的磁盤,如何去做LVM?

一、格式化磁盤

[root@localhost ~]# fdisk -l #查看當前的設備有哪些

Disk /dev/sda: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

……此處省略部分輸出內容……

/dev/sda3 153 2610 19743885 83 Linux

Disk /dev/sdb: 42.9 GB, 42949672960 bytes

……此處省略部分輸出內容……

Disk /dev/sdb doesn't contain a valid partition table

……此處省略部分輸出內容……

Disk /dev/sdc doesn't contain a valid partition table

從格式化磁盤開始

[root@localhost ~]# fdisk /dev/sdb ##對第二塊磁盤進行分區

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

此處省………………略若干字

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): n ##n表示new,建立新的分區

p primary partition (1-4)

p ###代表主分區

Partition number (1-4): 1 ##主分區號

First cylinder (1-5221, default 1): 1##磁盤分區起始點

Last cylinder or +size or +sizeM or +sizeK (1-5221, default 5221): +10000M ##指定第一個分區大小為10G

Command (m for help): n #繼續新建分區

Command action

e extended

p primary partition (1-4)

p ##依舊是主分區

Partition number (1-4): 2 ##編號為2

First cylinder (1218-5221, default 1218):

Using default value 1218 ##起始點直接回車表示默認

Last cylinder or +size or +sizeM or +sizeK (1218-5221, default 5221): +20000M ###指定大小為20G

Command (m for help): n ##新建分區

Command action

e extended

p primary partition (1-4)

p ##選擇主分區

Partition number (1-4): 3 ##主分區編號為3

First cylinder (3651-5221, default 3651):

Using default value 3651 ###直接回車默認

Last cylinder or +size or +sizeM or +sizeK (3651-5221, default 5221):

Using default value 5221 ####回車默認

Command (m for help): t ###使用t表示轉換分區類型

Partition number (1-4): 1 ###輸入分區號

Hex code (type L to list codes): 8e ###輸入分區類型代碼

Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): t

Partition number (1-4): 2

Hex code (type L to list codes): 8e

Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): 8e

Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p ###列出所有分區

Disk /dev/sdb: 42.9 GB, 42949672960 bytes

……

Device Boot Start End Blocks Id System

/dev/sdb1 1 1217 9775521 8e Linux LVM

/dev/sdb2 1218 2434 9775552+ 8e Linux LVM

/dev/sdb3 2435 5221 22386577+ 8e Linux LVM

…………此處省略部分輸出內容……

Command (m for help): w ###保存退出

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]# partprobe /dev/sdb /dev/sdc

二、建立PV(物理卷)

[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3

/dev/cdrom: open failed: Read-only file system

Physical volume "/dev/sdb1" successfully created

Attempt to close device '/dev/cdrom' which is not open.

Physical volume "/dev/sdb3" successfully created

[root@localhost ~]# pvdisplay ###展示物理卷

"/dev/sdb1" is a new physical volume of "9.32 GB"

--- NEW Physical volume ---

PV Name /dev/sdb1

VG Name

PV Size 9.32 GB

……此處省略……部分顯示結果

PV Size 21.35 GB

Allocatable NO

…………

PV UUID rdfuEk-FUli-Iyks-sGrO-1bco-G7ND-NYyrjM

三、建立VG卷組

[root@localhost ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3 ####建立名稱為vg1的卷組

Volume group "vg1" successfully created

[root@localhost ~]# vgdisplay ###列出卷組

--- Volume group ---

VG Name vg1

System ID

Format lvm2

Metadata Areas 3

Metadata Sequence No 1

VG Access read/write

………………………………

Free PE / Size 10237 / 39.99 GB

VG UUID sgtFaV-Hd31-dCag-jPbq-50Ia-WOQa-Ccwo3x

更多精彩內容:http://www.bianceng.cn/OS/Linux/

四、建立LV邏輯卷

[root@localhost ~]# lvcreate -L 15000M -n lv1 vg1 ###創建名為lv1,大小為15G的邏輯卷

/dev/cdrom: open failed: Read-only file system

Logical volume "lv1" created

[root@localhost ~]# lvdisplay ###展示邏輯卷

--- Logical volume ---

LV Name /dev/vg1/lv1

VG Name vg1

LV UUID fPAVct-8lZ2-Nvs6-KK2n-IMqo-1enG-hHt2tN

LV Write Access read/write

LV Status available

# open 0

LV Size 14.65 GB

Current LE 3750

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:0

格式化LV1並掛載

[root@localhost ~]# mkfs.ext3 /dev/vg1/lv1 ###將lv1格式化成ext3格式

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

1921984 inodes, 3840000 blocks

192000 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=3934257152

118 block groups

32768 blocks per group, 32768 fragments per group

16288 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@localhost ~]# mount /dev/vg1/lv1 /mnt/ ####將邏輯卷掛載到/mnt

[root@localhost ~]# mount ###查看當前的掛在情況

/dev/sda3 on / type ext3 (rw)

proc on /proc type proc (rw)

sysfs on /sys type sysfs (rw)

devpts on /dev/pts type devpts (rw,gid=5,mode=620)

/dev/sda1 on /boot type ext3 (rw)

tmpfs on /dev/shm type tmpfs (rw)

none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

/dev/mapper/vg1-lv1 on /mnt type ext3 (rw)

擴大LV

[root@localhost ~]# df -Th ####查看當前的分區掛載

Filesystem Type Size Used Avail Use% Mounted on

/dev/sda3 ext3 19G 4.1G 14G 24% /

/dev/sda1 ext3 190M 12M 169M 7% /boot

tmpfs tmpfs 125M 0 125M 0% /dev/shm

/dev/mapper/vg1-lv1

ext3 15G 165M 14G 2% /mnt

Disk /dev/sdc: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

/dev/sdc1 1 366 2939863+ 8e Linux LVM

[root@localhost ~]# vgdisplay #####查看卷組的狀態

--- Volume group ---

VG Name vg1

System ID

……

Alloc PE / Size 3750 / 14.65 GB

Free PE / Size 6487 / 25.34 GB

VG UUID sgtFaV-Hd31-dCag-jPbq-50Ia-WOQa-Ccwo3x

[root@localhost ~]# vgextend vg1 /dev/sdc1 #####將/dev/sdc1擴到卷組vg1中

/dev/cdrom: open failed: Read-only file system

No physical volume label read from /dev/sdc1

Physical volume "/dev/sdc1" successfully created

Volume group "vg1" successfully extended

[root@localhost ~]# vgdisplay

--- Volume group ---

VG Name vg1

System ID

Format lvm2

Metadata Areas 4

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 4

Act PV 4

VG Size 42.79 GB

PE Size 4.00 MB

Total PE 10954

Alloc PE / Size 3750 / 14.65 GB

Free PE / Size 7204 / 28.14 GB

VG UUID sgtFaV-Hd31-dCag-jPbq-50Ia-WOQa-Ccwo3x

[root@localhost ~]# lvextend -L +2000M /dev/vg1/lv1 ####對lv進行擴容

/dev/cdrom: open failed: Read-only file system

Extending logical volume lv1 to 16.60 GB

Logical volume lv1 successfully resized

Copyright © Linux教程網 All Rights Reserved