2013-09-05

CentOS - 그래픽 없이 명령으로 볼륭 디스크 공간 추가하기

최초 OS 설치후 여러 프로그램을 /opt 에 설치하기위해, 디스크를 추가하고 /opt에 추가된 공간을 할당하는 예



1.추가된 디스크 확인 (sdb가 추가 디스크임)
# ls -l /dev | grep "^brw" | grep " [hs]d"
brw-rw----. 1 root disk      8,   0 Sep  5 11:27 sda
brw-rw----. 1 root disk      8,   1 Sep  5 11:27 sda1
brw-rw----. 1 root disk      8,   2 Sep  5 11:27 sda2
brw-rw----. 1 root disk      8,  16 Sep  5 11:27 sdb

 
2. 파티션 생성
# fdisk -l /dev/sdb


Disk /dev/sdb: 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: 0x00000000

# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x698cd53a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


# fdisk -l /dev/sdb

Disk /dev/sdb: 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: 0x698cd53a

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        2610    20964793+  8e  Linux LVM

3. Physical volume 생성
# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

4. Volume 확인
# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VolGroup" using metadata type lvm2

5. Logical Volume 확인
# lvscan
  ACTIVE            '/dev/VolGroup/lv_root' [8.54 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_swap' [992.00 MiB] inherit


6. Physical volume 확인
# pvscan
  PV /dev/sda2   VG VolGroup        lvm2 [9.51 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [19.99 GiB]
  Total: 2 [29.50 GiB] / in use: 1 [9.51 GiB] / in no VG: 1 [19.99 GiB]


7. Volume 신규 생성
# vgcreate VolData /dev/sdb1
  Volume group "VolData" successfully created

8. Logical Volume 추가 (15GB)
# lvcreate -L 15G -n lv_data VolData
  Logical volume "lv_data" created


# lvscan
  ACTIVE            '/dev/VolData/lv_data' [15.00 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_root' [8.54 GiB] inherit
  ACTIVE            '/dev/VolGroup/lv_swap' [992.00 MiB] inherit

9. 파일시스템 생성 (ext4)
# mkfs.ext4 /dev/VolData/lv_data
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
983040 inodes, 3932160 blocks
196608 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4026531840
120 block groups
32768 blocks per group, 32768 fragments per group
8192 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 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

10. mount 정보 추가
* /etc/fstab 에 아래 한줄 추가

/dev/mapper/VolData-lv_data /opt               ext4    defaults        1 1


# mount -a

# df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       8813300   1558824   6806784  19% /
tmpfs                   771484         0    771484   0% /dev/shm
/dev/sda1               495844     97423    372821  21% /boot
/dev/mapper/VolData-lv_data
                      15481840    169456  14525952   2% /opt

댓글 없음:

댓글 쓰기