天天看点

openfiler里用到的linux命令parted,iscsi target,lvm

parted

随着单块硬盘容量的增大和硬盘价格的下降,2TB的磁盘使用将很快会普及,由于传统的MBR方式存储分区表的方 式缺陷,将可能导致很多分区工具不能正确地读取大于2TB容量的硬盘而无法正常分区大容量硬盘。其实linux在很早就已经有相关的工具来化解这个困境 了,那就是parted。

parted是类似fdisk的命令行分区软件,假设我们在linux系统中有一块未分区的硬盘挂载为/dev/hdd,下面以实例的方式来讲解如何使用 parted:

注意:parted的操作都是实时的,也就是说你执行了一个分区的命令,他就实实在在地分区了,而不是像fdisk那样,需要执行w命令写入所做的修改, 所以进行parted的测试千万注意不能在生产环境中!!

标记:#开始表示在shell的root下输入的命令,(parted)表示在parted中输入的命令,其他为自动打印的信

iscsi target

http://wenku.baidu.com/view/b2c816ed856a561252d36ff1.html

LVM 转自http://www.litvip.com/351/

删除硬盘的过程简单如下:

从VG删除PV->删除PV->删除该硬盘上的LVM分区->拔掉硬盘

第一步,从VG删除PV

1.删除前,先确认要删除的PV所在的VG情况:

?

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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

[[email protected]

test

~]

# vgdisplay -v

Finding all volume

groups

Finding volume group

"VolGroup00"

--- Volume group ---

VG Name               VolGroup00

System ID

Format                lvm2

Metadata Areas        2

Metadata Sequence No  7

VG Access            

read

/write

VG Status             resizable

MAX LV                0

Cur LV                2

Open LV               2

Max PV                0

Cur PV                2

Act PV                2

VG Size               390.53 GB

PE Size               32.00 MB

Total PE              12497

Alloc PE / Size       653 / 20.41 GB

Free  PE / Size       11844 / 370.12 GB

VG UUID               0UvEJz-rfLm-MVDb-20uW-JMCa-T14K-wCmyLO

--- Logical volume ---

LV Name               

/dev/VolGroup00/LogVol00

VG Name                VolGroup00

LV UUID                fDHwa0-IUZV-no5O-RRJB-4N9o-U2MV-TAqucp

LV Write Access       

read

/write

LV Status              available

# open                 1

LV Size                15.00 GB

Current LE             480

Segments               1

Allocation             inherit

Read ahead sectors     auto

- currently

set

to     256

Block device           253:0

--- Logical volume ---

LV Name               

/dev/VolGroup00/LogVol01

VG Name                VolGroup00

LV UUID                cUjKA9-bI60-6R05-K0jS-MdXi-r26d-mfwU8X

LV Write Access       

read

/write

LV Status              available

# open                 1

LV Size                5.41 GB

Current LE             173

Segments               1

Allocation             inherit

Read ahead sectors     auto

- currently

set

to     256

Block device           253:1

--- Physical volumes ---

PV Name              

/dev/cciss/c0d0p3

PV UUID               6K7yBW-NuRf-3Quv-LU8U-6N1S-DmzG-ccCmbx

PV Status             allocatable

Total PE / Free PE    8122 / 7469

PV Name              

/dev/cciss/c0d1p1

<--要从VG里移除的PV

PV UUID               TWzjBK-0N5x-1A6c-wht3-n4l1-7gFp-m24iy3

PV Status             allocatable

Total PE / Free PE    4375 / 4375

可以看到VG名为VolGroup00的最后那一段PV名字是/dev/cciss/c0d1p1就是我要从VG里删除的PV。

2.从VG删除PV

?

1 2

[[email protected]

test

~]

#  vgreduce VolGroup00 /dev/cciss/c0d1p1

Removed

"/dev/cciss/c0d1p1"

from volume group

"VolGroup00"

3.确认是否已经删除

?

1 2 3

[[email protected]

test

~]

# vgdisplay -v VolGroup00 | grep "/dev/cciss/c0d1p1"

Using volume group(s) on

command

line

Finding volume group

"VolGroup00"

可以看到,VolGroup00里已经不包含名为/dev/cciss/c0d1p1的PV了。

第二步,删除PV

1.确认PV信息:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

[[email protected]

test

~]

# pvdisplay

--- Physical volume ---

PV Name              

/dev/cciss/c0d0p3

VG Name               VolGroup00

PV Size               253.82 GB / not usable 6.99 MB

Allocatable          

yes

PE Size (KByte)       32768

Total PE              8122

Free PE               7469

Allocated PE          653

PV UUID               6K7yBW-NuRf-3Quv-LU8U-6N1S-DmzG-ccCmbx

"/dev/cciss/c0d1p1"

is a new physical volume of

"136.73 GB"

--- NEW Physical volume ---

PV Name              

/dev/cciss/c0d1p1

<--我们要删除的PV

VG Name

PV Size               136.73 GB

Allocatable           NO

PE Size (KByte)       0

Total PE              0

Free PE               0

Allocated PE          0

PV UUID               TWzjBK-0N5x-1A6c-wht3-n4l1-7gFp-m24iy3

名为/dev/cciss/c0d1p1的就是我们要删除的PV。

2.删除PV

?

1 2

[[email protected]

test

~]

# pvremove /dev/cciss/c0d1p1

Labels on physical volume

"/dev/cciss/c0d1p1"

successfully wiped

3.确认PV是否删除成功

?

1 2

[[email protected]

test

~]

# pvdisplay | grep "/dev/cciss/c0d1p1"

[[email protected]

test

~]

#

可见,已经删除成功。

第三步,删除该硬盘(/dev/cciss/c0d1)上的LVM分区(/dev/cciss/c0d1p1)

?

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

[[email protected]

test

~]

# fdisk /dev/cciss/c0d1

The number of cylinders

for

this disk is

set

to 35139.

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)

Command (m

for

help): p <--显示分区情况

Disk

/dev/cciss/c0d1

: 146.8 GB, 146807930880 bytes

255 heads, 32 sectors

/track

, 35139 cylinders

Units = cylinders of 8160 * 512 = 4177920 bytes

Device Boot      Start         End      Blocks   Id  System

/dev/cciss/c0d1p1

1       35139   143367104   8e  Linux LVM

Command (m

for

help): d <--删除分区

Selected partition 1

Command (m

for

help): p <--在显示分区情况,发现已经没了

Disk

/dev/cciss/c0d1

: 146.8 GB, 146807930880 bytes

255 heads, 32 sectors

/track

, 35139 cylinders

Units = cylinders of 8160 * 512 = 4177920 bytes

Device Boot      Start         End      Blocks   Id  System

Command (m

for

help): w <--保存退出

The partition table has been altered!

Calling ioctl() to re-

read

partition table.

Syncing disks.