天天看點

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.