본문 바로가기

SERVER/Centos

[Centos] centos6에서 reboot없이 lvm 디스크 추가 방법 (online)

centos6에서 reboot없이 lvm 디스크 추가 방법 (online)


logical volume manager를 이용해서 volume을 생성하고, 재부팅 없이 디스크를 확장해보려고 한다.

여러 개의 partition을 한 개의 디스크에 사용하기 위한 디스크 관리 기능이다.


df-h로 생성되어 있는 lvm볼륨을 확인 


# df -h

Filesystem                             Size  Used Avail Use% Mounted on

/dev/mapper/vg_svmotpcent654-LogVol01   83G  5.8G   73G   8% /

tmpfs                                  3.9G     0  3.9G   0% /dev/shm

/dev/sda1                              485M   39M  421M   9% /boot



fdisk 파티션 관리 프로그램을 이용해서 세밀한 파티션 설정을 해보자 .


# fdisk -l


Disk /dev/sda: 161.1 GB, 161061273600 bytes

255 heads, 63 sectors/track, 19581 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00025219


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64       13055   104344576   8e  Linux LVM


Disk /dev/mapper/vg_svmotpcent654-LogVol01: 90.1 GB, 90068484096 bytes

255 heads, 63 sectors/track, 10950 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000



Disk /dev/mapper/vg_svmotpcent654-LogVol00: 16.8 GB, 16777216000 bytes

255 heads, 63 sectors/track, 2039 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000



Disk /dev/sdb: 6442 MB, 6442450944 bytes

199 heads, 62 sectors/track, 1019 cylinders

Units = cylinders of 12338 * 512 = 6317056 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000



디스크 리스캔을 위한 작업 

# ls /sys/class/scsi_device/

1:0:0:0  2:0:0:0  2:0:1:0

# echo 1 > /sys/class/scsi_device/1\:0\:0\:0/device/rescan

# echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan

# echo 1 > /sys/class/scsi_device/2\:0\:1\:0/device/rescan


리눅스가 SCSI 장치를 rescan하도록 요청

# ls  /sys/class/scsi_host/

host0  host1  host2

# echo "- - -" > /sys/class/scsi_host/host0/scan

# echo "- - -" > /sys/class/scsi_host/host1/scan

# echo "- - -" > /sys/class/scsi_host/host2/scan


디스크 확인

# fdisk -l


Disk /dev/sda: 161.1 GB, 161061273600 bytes

255 heads, 63 sectors/track, 19581 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00025219


   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              64       13055   104344576   8e  Linux LVM


Disk /dev/mapper/vg_svmotpcent654-LogVol01: 96.5 GB, 96502546432 bytes

255 heads, 63 sectors/track, 11732 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000



Disk /dev/mapper/vg_svmotpcent654-LogVol00: 16.8 GB, 16777216000 bytes

255 heads, 63 sectors/track, 2039 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000



Disk /dev/sdb: 6442 MB, 6442450944 bytes

199 heads, 62 sectors/track, 1019 cylinders

Units = cylinders of 12338 * 512 = 6317056 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x332b7419


   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1019     6286180   8e  Linux LVM





# fdisk /dev/sda


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

         switch off the mode (command 'c') and change display units to

         sectors (command 'u').


Command (m for help): n    << 파티션 생성 

Command action               << Primary 파티션을 만들어야 하므로 p 

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 3      << 파티션 번호를 선택 (1~4를 순차적으로 선택 가능. 이미 2번째까지 partition이 있기 때문에 3 선택 )

First cylinder (13055-19581, default 13055):

Using default value 13055

Last cylinder, +cylinders or +size{K,M,G} (13055-19581, default 19581):   << +10GB와 같이 디스크 할당을 지정해서 설정도 가능 (모든 공간을 사용하려면 그냥 enter)

Using default value 19581


Command (m for help): t

Partition number (1-4): 3

Hex code (type L to list codes): 8e                             << 파티션 시스템 타입을 linux LVM(8e)타입으로 변경 

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


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.



리부팅 없이 사용중인 파티션 재인식(partprobe command shows error but it works)


# partprobe -s

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.


# partx -v -a /dev/sda

device /dev/sda: start 0 size 314572800

gpt: 0 slices

dos: 4 slices

# 1:      2048-  1026047 (  1024000 sectors,    524 MB)

# 2:   1026048-209715199 (208689152 sectors, 106848 MB)

# 3: 209715200-314568764 (104853565 sectors,  53685 MB)

# 4:         0-       -1 (        0 sectors,      0 MB)

BLKPG: Device or resource busy

error adding partition 1

BLKPG: Device or resource busy

error adding partition 2

added partition 3



lvm에서 사용할 수 있게 피지컬 볼륨을 생성하는 작업.



# pvcreate /dev/sda3                                        << 추가된 디스크 파티션을 LVM pv로 등록 

  dev_is_mpath: failed to get device for 8:3

  Physical volume "/dev/sda3" successfully created



생성되어 있는 볼륨 그룹을 확인 


# vgdisplay

  --- Volume group ---

  VG Name               vg_svmotpcent654          << 볼륨 그룹

  System ID

  Format                lvm2

  Metadata Areas        2

  Metadata Sequence No  5

  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               105.50 GiB

  PE Size               4.00 MiB

  Total PE              27008

  Alloc PE / Size       27008 / 105.50 GiB

  Free  PE / Size       0 / 0


볼률그룸에 물리 볼륨 추가

# vgextend vg_svmotpcent654 /dev/sda3


확장된 볼륨 그룹의 나머지 사이즈를 로지컬 볼륨에 확장하여 준다.

# lvextend /dev/vg_svmotpcent654/LogVol01 /dev/sda3

  Extending logical volume LogVol01 to 139.87 GiB

  Logical volume LogVol01 successfully resized


하지만 그 대로이다. 

# df -h

Filesystem                             Size  Used Avail Use% Mounted on

/dev/mapper/vg_svmotpcent654-LogVol01   83G  5.8G   73G   8% /

tmpfs                                  3.9G     0  3.9G   0% /dev/shm

/dev/sda1                              485M   39M  421M   9% /boot



os는 볼륨이 확장되었지만 다시 명시해 주지 않으면 알지 못한다 .

볼륨의 사이즈가 변경되어 있다는 것을 수동으로 알리면 볼륨 확장이 가능하다 . 

# resize2fs /dev/vg_svmotpcent654/LogVol01

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_svmotpcent654/LogVol01 is mounted on /; on-line resizing required

old desc_blocks = 6, new_desc_blocks = 9

Performing an on-line resize of /dev/vg_svmotpcent654/LogVol01 to 36666368 (4k) blocks.

The filesystem on /dev/vg_svmotpcent654/LogVol01 is now 36666368 blocks long.



확인 : 


# df -h

Filesystem                             Size  Used Avail Use% Mounted on

/dev/mapper/vg_svmotpcent654-LogVol01  138G  5.8G  125G   5% /

tmpfs                                  3.9G     0  3.9G   0% /dev/shm

/dev/sda1                              485M   39M  421M   9% /boot



주의 : rhel6환경에서 최적화 된 방법이다. 

resize2fs 는 rhel4에서는 지원하지 않는다고 한다. (온라인 확장 불가)