반응형


1) 출처 : http://linuxro-textcube.blogspot.kr/2010/01/vmware%EC%97%90-%EC%84%A4%EC%B9%98%EB%90%9C-linux%EC%9D%98-%EB%94%94%EC%8A%A4%ED%81%AC-%EC%9A%A9%EB%9F%89-%ED%82%A4%EC%9A%B0%EA%B8%B0lvm.html



VMWare에 설치된 linux의 디스크 용량 키우기(LVM)

2년전에 VMWare에 설치하여 지금껏 사용해 오던 리눅스 가상머신의 하드디스크 용량이 이제 거의 남아 있지 않게 되었다. 주로 개발용으로 사용할 목적으로 리눅스 가상머신을 만들고, 또 처음 설치할 당시에는 이 정도 용량이면 충분하겠지 했는데, 의외로 오랜 기간 동안 가상머신이 망가지지 않고 지금까지 개발환경으로 사용해 온 것이다. 이제 처음 할당했던 디스크가 거의 다 사용되어 하드 디스크의 확장이 필요하다. 실제 컴퓨터의 경우 하드디스크 용량을 늘리고 싶으면 하드디스크를 새로 구매해서 장착하고 파티션 잡고, 포멧해서 마운트 하는 과정을 거친다. VMWare상의 가상머신에서도 비슷한 과정으로 디스크 용량을 늘려준다.


VMWare에 배포판 리눅스를 설치하면 대부분 LVM타입으로 디스크가 설정된다. 따라서 본 포스트에서는 VMWare상에서 디스크의 파티션이 LVM으로 설정된 경우 디스크 용량을 늘리는 방법을 살펴본다.

VMWare에 설치된 리눅스의 디스크 용량을 늘리는 작업의 순서는 다음과 같다.

 

1)  용량을 늘리고자 하는 가상머신에 장착된 하드디스크의 용량을 키워준다.

2)  Guest OS인 리눅스를 부팅한다.

3)  fdisk 유틸을 이용해서 PV(Physical Volume)를 설정한다.

4)  VG(Volume Group)를 확장한다

5)  LV(Logical Volume) 늘리기.

6)  파일 시스템을 조정한다.

 

  각 단계를 살펴보자. 기존에 20GBytes의 하드디스크 용량을 할당해서 설치한 리눅스에 20GBytes의 용량을 늘려 줘서 총 40GBytes의 용량을 가진 리눅스 시스템으로 업그레이드 해본다. 참고로 설치되어 있는 리눅스는 Fedora8이고, 하드디스크는 20GBytes, LVM(Logical Volume Manager) 으로 관리되고 있다.


1. 가상머신상의 하드디스크 늘리기


  가상머신에 설치되어 있는 20GBytes 짜리 하드디스크를 40GBytes 짜리 하드디스크로 용량을 늘려 준다. 가상머신의 하드디스크 용량 확장은 vmware-vdiskmanager.exe 라는 유틸을 이용한다. vmware-vdiskmanager.exe VMWare 설치시 기본 설치되는 유틸리티이며C:\Program Files\VMware\VMware Workstation에 있다. 콘솔창에서 다음과 같이 명령을 수행한다. 여기서 "Other Linux 2.6.x kernel.vmdk"는 설치되어 있는 Fedora8의 가상머신 이미지 이다. –x 옵션은 가상디스크의 용량을 지정된 크기만큼 늘리라는 명령이다. 여기서는 40Gb를 지정해 줬기 때문에 가상디스크의 크기가 40GBytes로 확장되게 된다.

 

“C:\Program Files\VMware\VMware Workstation\vmware- vdiskmanager.exe” -x 40Gb "Other Linux 2.6.x kernel.vmdk"

 
  하드디스크 증설에는 시간이 꽤 걸린다. 마치 컴퓨터 전원을 내리고, 드라이버로
나사 풀고, 하드디스크 끼워 넣는 시간 만큼은 걸리는 것 같다.(시간이 꽤 걸린다.)  

2. 이제 하드디스크를 증설했으면 리눅스를 부팅한다.

  가상머신을 부팅해서 디스크 사용량과 디스크 관리 타입을 확인해 보니, 다음 그림과 같다. 디스크는 거의 다 사용해서 이제 남은 용량이 658Mb정도 이고, VolGroup00-LogVol00 “/” (Root)에 마운트 되어 있으며, 파일 시스템은 ext3 타입이다.



3. PV(Physical Volume)를 생성한다.

 

  /dev/sda3에 파티션을 만들기 위해서는 디바이스 노드 파일이 있어야 하므로, 미리 있는지 확인해 보고 없으면 만들어 준다. 살펴 봤더니, 없어서 다음과 같이 디바이스 노드를 만들어 주고, 소유권을 root:disk로 변경해 주었다.

 

mknod /dev/sda3 b 8 3

chown root:disk /dev/sda3


  fdisk를 이용해서 늘어난 디스크의 크기와 각 파티션별 디스크 타입을 확인해 보면 다음 그림과 같다. 기존에 20GBytes였는데, 42.9GBytes로 늘어 났고, /dev/sda2 Linux LVM 타입으로 파티션이 설정되어 있으며, 확장된20GBytes의 디스크 용량은 아직 파티션으로는 잡혀 있지 않은 상태임을 알 수 있다. 그림에서 처럼 새로운 파티션을 Primary partition 3로 추가 하고, 파티션 타입을 LinuxLVM타입(8e)으로 설정해 준다.



 파티션을 만들고 나서는 반드시 재부팅을 해 줘야 한다.

 

시스템 재부팅 후 /dev/sda3 PV(Physical Volume)를 생성해 준다.

pvcreate /dev/sda3

 PV 생성 명령의 수행 화면은 다음과 같다.


4. VG(Volume Group) 확장


  다음 명령을 수행하여 VG를 확장한다.

vgextend VolGroup00 /dev/sda3


  위의 명령은 VolGroup00 dev/sda3를 추가하라는 명령이다. pvscan명령을 이용하여 /dev/sda3VolGroup00에 제대로 추가되었는지 확인한다. vgdisplay VolGroup00 명령을 이용해 Volume group 00의 내용을 보면 다음과 같다.


5. LV(Logical Volume) 늘리기.

 

  LV의 확장은 lvextend 명령을 이용하여 수행한다. 기존의 LV에 새로 추가된 20GBytesPV를 확장하자.

lvextend –L +20g /dev/VolGroup00/LogVol00


 

6. 파일 시스템 크기 조정

 

  다음 명령어를 이용하여 변경된 LV를 파일 시스템에 반영한다.

resize2fs /dev/VolGroup00/LogVol00

 

  이제 하드디스크의 용량을 확인해 보면, 새로 추가한 20GBytes의 용량이 새로 확보되었음을 알 수 있다.

 

  지금까지 VMWare에 설치된 리눅스의 디스크 파티션 타입이 LVM으로 설정되어 있는 경우 디스크 용량을 확장하는 방법에 대해 간략히 살펴 보았으며, 쉽게 확장할 수 있음을 알 수 있다.


 

참조)

   1. vmware-vdiskmanager 사용법
    2. LVM 소개

    3. Logical Volume Manager(Linux)









2) 출처 : http://blueray21.tistory.com/31

------------------------------------------------------------------------------



1. 시스템 디스크 용량 확인 및 LVM(Logical Volume Manager) 설정 내용 확인

1.1 df

[root@centos ~]# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on /dev/mapper/vg_centos-lv_root
                      18102140  15189340   1993248  89% /
tmpfs                   515440    258020    257420  51% /dev/shm
/dev/sda1               495844     31202    439042   7% /boot

  • /dev/mapper/vg_centos-lv_root가 18G 중 현재 용량 89% 사용 중
1.2 fdisk

[root@centos ~]# 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): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000644ee

   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        2611    20458496   8e  Linux LVM

Command (m for help): q

  • /dev/sda 디스크 전체 용량은 21.5 G 
  • p : print the partition table

1.3 pvscan

[root@centos ~]# pvscan
  PV /dev/sda2   VG vg_centos   lvm2 [19.51 GiB / 0    free]
  Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0   ]

  • Physical Volume Name : /dev/sda2
  • Volume Group Name : vg_centos

1.4 pvdisplay

[root@centos ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_centos
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               LwySgs-zNx3-auDL-l5h0-hzCU-OXiC-iihaws

1.5 lvdisplay

[root@centos ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg_centos/lv_root
  VG Name                vg_centos
  LV UUID                zhE2Ty-1NPU-QrAT-x7H9-65mY-tC3D-L2YJXt
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                17.54 GiB
  Current LE             4490
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/vg_centos/lv_swap
  VG Name                vg_centos
  LV UUID                DWSUev-UlpF-O4Zf-lpu5-G6uo-fpDY-14yxU5
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.97 GiB
  Current LE             504
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  • LV_NAME : /dev/vg_centos/lv_root
1.6 vgdisplay

[root@centos ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_centos
  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               19.51 GiB
  PE Size               4.00 MiB
  Total PE              4994
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               NoIptA-3L3H-VRXx-rNo8-3HJy-2niS-2sxPZh

  • Free PE가 0

2. VMWare에서 디스크 용량 늘이기

2.1 VMWare Disk 파일 확인

2.2 vmware-vdiskmanager.exe 실행

  • 시스템 Shutdown 및 VMWare 종료

cd "C:\Program Files\VMware\VMware Workstation"
vmware-vdiskmanager.exe -x 30GB -t 1 "C:\vmware\centos\CentOS.vmdk"

  • - x : 추가하고 싶은 용량이 아니라 늘이고 나서의 디스크 전체 용량
  • - t : virtual disk type
  •   Disk types:
  •       0                   : single growable virtual disk
  •       1                   : growable virtual disk split in 2GB files
  •       2                   : preallocated virtual disk      
  •       3                   : preallocated virtual disk split in 2GB files
  •       4                   : preallocated ESX-type virtual disk
  •       5                   : compressed disk optimized for streaming
  •       6                   : thin provisioned virtual disk - ESX 3.x and above

2.3 늘어난 용량 VMWare에서 확인

  • VMWare 재 실행


3. CentOS 시스템에서 용량 늘이기

3.1 늘어난 DISK 용량 확인 - fdisk

[root@centos ~]# 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): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000644ee

   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        2611    20458496   8e  Linux LVM

  • /dev/sda 디스크 전체 용량이 32.2 G 로 증가
3.2 파티션 생성 - fdisk

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-3916, default 2611): 
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-3916, default 3916): 
Using default value 3916

Command (m for help): p

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000644ee

   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        2611    20458496   8e  Linux LVM
/dev/sda3            2611        3916    10483750   83  Linux

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): 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.
[root@centos ~]# shutdown -r now

  • 작업 후 재부팅

3.3 Pysical Volume  생성 - pvcreate

[root@centos ~]# pvscan
  PV /dev/sda2   VG vg_centos   lvm2 [19.51 GiB / 0    free]
  Total: 1 [19.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 0 [0   ]  
[root@centos ~]# 
pvcreate /dev/sda3
[root@centos ~]# pvscan
  PV /dev/sda2   VG vg_centos   lvm2 [19.51 GiB / 0    free]
  PV /dev/sda3                      lvm2 [10.00 GiB]
  Total: 2 [29.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [10.00 GiB]
[root@centos ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg_centos
  PV Size               19.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4994
  Free PE               0
  Allocated PE          4994
  PV UUID               LwySgs-zNx3-auDL-l5h0-hzCU-OXiC-iihaws

  "/dev/sda3" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---

  PV Name               /dev/sda3
  VG Name               
  PV Size               10.00 GiB
  Allocatable           No
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               arlrZ3-JGKi-1meJ-blcj-AaVj-QNTH-84RcQy

3.4 Volume Group 확장 - vgextend

  • vgextend VG_NAME PV_NAME
  • VG_NAME과 PV_NMAE은 위 1.3 pvscan에서 확인

[root@centos ~]# vgextend vg_centos /dev/sda3
  Volume group "vg_centos" successfully extended
[root@centos ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_centos
  System ID     
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               29.50 GiB
  PE Size               4.00 MiB
  Total PE              7553
  Alloc PE / Size       4994 / 19.51 GiB
  Free  PE / Size       2559 / 10.00 GiB   
  VG UUID               NoIptA-3L3H-VRXx-rNo8-3HJy-2niS-2sxPZh

  • Free PE 생김

3.5 물리적인 파티션 용량 증가

  • lvextend LV_NAME -l +LogicalExtentsNumber
  • LV_NAME은 위 1.5 lvdisplay에서 확인
  • LogicalExtentsNumber은 위 3.4 vgdisplay에서 Free PE 크기 내에서

[root@centos ~]# lvextend /dev/vg_centos/lv_root -l +2559
  Extending logical volume lv_root to 27.54 GiB
  Logical volume lv_root successfully resized
[root@centos ~]# vgdisplay
  --- Volume group ---
  VG Name               vg_centos
  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               29.50 GiB
  PE Size               4.00 MiB
  Total PE              7553
  Alloc PE / Size       7553 / 29.50 GiB
  Free  PE / Size       0 / 0 GiB   
  VG UUID               NoIptA-3L3H-VRXx-rNo8-3HJy-2niS-2sxPZh

  • Free PE가 다시 0으로 되고 Alloc PE가 늘어남
3.6 파일시스템 반영 - resize

[root@centos ~]# resize2fs /dev/vg_centos/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_centos/lv_root is mounted on /; on-line resizing required

old desc_blocks = 2, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_centos/lv_root to 7218176 (4k) blocks.

The filesystem on /dev/vg_centos/lv_root is now 7218176 blocks long.

[root@centos ~]# 
df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_centos-lv_root
                      28419964  15189140  11791824  57% /
tmpfs                   515440    258032    257408  51% /dev/shm
/dev/sda1               495844     31202    439042   7% /boot



해당 에러가 발생하면 resize2fs 가 아니라 다르게 진행.
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

xfs_growfs /dev/vg_centos/lv_root


반응형

+ Recent posts