DISK 추가, LVM 늘리기
작성자 : Kei
// DISK 추가
// 1. 스캔
# echo "- - -" > /sys/class/scsi_host/host0/scan
# fdisk -l
-- /dev/sdb 찾을 수 있음
/dev/sdb (SCSI 하드) /dev/hdb (IDE 하드)
// 2. fdisk로 파티션 잡기
2-1. fdisk 실행
# fdisk /dev/sdb
2-2. p로 기존 파티션 확인
2-2. d로 기존 파티션이 잡혀있으면 삭제
2-4. n으로 파티션 추가 - > p(primary로) -> (크기지정 Full로 잡을시) 엔터 -> 엔터 -> 엔터
2-5. w로 쓰기
// 3. Format
3-1. 파티션 형식 확인
# blkid
# vi /etc/fstab
3-2 A. parted 하고 포멧
==============================================================================================
# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart primary 0 215G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 215GB 215GB xfs primary
(parted) quit
Information: You may need to update /etc/fstab.
==============================================================================================
# mkfs.xfs -f /dev/sdb1
3-2 B.파티션 형식에 맞게 전체 포맷
ext3 : mke2fs -j /dev/hdb
ext2 : mkfs -t ext2 /dev/hdb
xfs : mkfs.xfs -f /dev/sdb
// 4. Mount
-- 마운트할 디렉토리 생성
# mkdir /home2 등등
-- mount
ext3 : mount -t ext3 /dev/hdb1 /home2
ext2 : mount -t ext2 /dev/hdb1 /home2
xfs : mount -t xfs /dev/sdb1 /home2
-- umount (실수시 umount)
# umount /home2
// 5. fstab 수정
# vi /etc/fstab
-- 부팅 시 자동으로 마운트되도록 하려면 fstab에 추가
/dev/sdb1 /home2 xfs defaults 0 0
// 6. 확인
-- df -h로 마운트 확인
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 14G 1.6G 13G 12% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.5M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 181M 317M 37% /boot
/dev/sdb1 200G 33M 200G 1% /home2
-- 재부팅후 이상없이 올라온후 마운트 되었는지 확인
// LVM 늘리기
// 시스템 디스크 확인
-- 시스템 용량 확인
# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 14530560 1128296 13402264 8% /
devtmpfs 1931420 0 1931420 0% /dev
tmpfs 1941352 0 1941352 0% /dev/shm
tmpfs 1941352 8640 1932712 1% /run
tmpfs 1941352 0 1941352 0% /sys/fs/cgroup
/dev/sda1 508588 184832 323756 37% /boot
tmpfs 388272 0 388272 0% /run/user/0
-- fdisk로 물리 디스크 확인
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009127b
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 33554431 16264192 8e Linux LVM
/dev/sda3 33554432 104857599 35651584 8e Linux LVM (아래는 parted.sh로 추가시 생성)
Command (m for help): q
-- 물리/논리 디스크 파일 시스템 확인
# pvscan
PV /dev/sda2 VG centos lvm2 [15.51 GiB / 40.00 MiB free]
Total: 1 [15.51 GiB] / in use: 1 [15.51 GiB] / in no VG: 0 [0 ]
-- Disk 확인
# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 15.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 3970
Free PE 0
Allocated PE 3970
PV UUID R2wxNt-cs4b-3WbR-7MQu-Q2Ug-l4ew-3fSTIz
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 34.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 8703
Free PE 0
Allocated PE 8703
PV UUID iLQSVd-1gbC-M67o-937g-Cl5Z-OlVk-HARKDC
# pvscan
PV /dev/sda2 VG centos lvm2 [15.51 GiB / 0 free]
PV /dev/sda3 VG centos lvm2 [34.00 GiB / 0 free]
Total: 2 [49.50 GiB] / in use: 2 [49.50 GiB] / in no VG: 0 [0 ]
# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID xYfKTt-eMYp-udma-3NWw-Lmfd-a7rD-JlqNMc
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-03-09 14:48:37 +0900
LV Status available
# open 2
LV Size 1.60 GiB
Current LE 410
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID EM2Wjt-O9GC-mZeo-rQ2L-bVlL-nigd-uXZiRr
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-03-09 14:48:37 +0900
LV Status available
# open 1
LV Size 47.90 GiB
Current LE 12263
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@controller ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 6
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 49.50 GiB
PE Size 4.00 MiB
Total PE 12673
Alloc PE / Size 12673 / 49.50 GiB
Free PE / Size 0 / 0
VG UUID dM3XLX-UsZd-8dlj-dho1-DljA-NaIF-NNP7Bc
* Volume Group Name : centos가 Volume Group Name (pvscan을 통해)
* Physical Volume Name : /dev/sda3 (pvdisplay를 통해)
// 스크립트로 확장
// 1. LVM 확장 스크립트
-- parted 설치
# yum install parted -y
-- parted 스크립트 작성
# vi parted.sh
-- CentOS 7.X Default
#! /bin/bash
START=`parted -s /dev/sda print free | grep Free | grep GB | awk '{print $1}'`
END=`parted -s /dev/sda print free | grep Free | grep GB | awk '{print $2}'`
parted /dev/sda -s mkpart primary $START $END
parted /dev/sda -s set 3 lvm
-- CentOS 6.X 예제
#! /bin/bash
START=`parted -s /dev/xvda print free | grep Free | grep GB | awk '{print $1}'`
END=`parted -s /dev/xvda print free | grep Free | grep GB | awk '{print $2}'`
parted /dev/xvda -s mkpart primary $START $END
parted /dev/xvda -s set 3 lvm
// 2. expand.sh 스크립트 작성
// 확장 스크립트 생성
CentOS7 부터 XFS를 디폴트 파일 시스템으로 사용하기 때문에 resize2fs는 를 사용할 수 없다.
# vi expand.sh
#! /bin/bash
pvcreate <<PV Name>> pvdisplay로 PV Name확인
vgextend <<VG Name>> <<PV Name>> vgdisplay로 VG Name확인
lvextend -l +100%FREE /dev/mapper/centos-root df -k로 Filesystem 확인
xfs_growfs << LV Path >> lvdisplay로 LV Path확인
-- CentOS 7.X Default (xfs 일 경우)
#! /bin/bash
# centos 7.X
pvcreate /dev/sda3
vgextend centos /dev/sda3
lvextend -l +100%FREE /dev/mapper/centos-root
xfs_growfs /dev/centos/root
-- CentOS 6.X 예제
#! /bin/bash
# centos 6.X
pvcreate /dev/xvda3
vgextend VolGroup /dev/xvda3
lvextend -l +50%FREE /dev/mapper/VolGroup-lv_root
resize2fs /dev/mapper/VolGroup-lv_root
-- Ubuntu 14 예제
#! /bin/bash
# ubuntu14
pvcreate /dev/sda6
vgextend ubuntu14-vg /dev/sda6
lvextend -l +100%FREE /dev/mapper/ubuntu14--vg-root
resize2fs /dev/mapper/ubuntu14--vg-root
// 3. parted.sh 실행
# ./parted.sh
// 5. expand.sh 실행
#./expand.sh
'IT > linux' 카테고리의 다른 글
[X][CentOS] NginX 설치 및 Tomcat연동 (1) | 2015.06.11 |
---|---|
[X][CentOS] netstat, nmap (0) | 2015.06.11 |
[bak][CentOS] fdisk, du, mount, swap (0) | 2015.06.11 |
[X][CentOS] YUM, RPM, EPEL 설치 (0) | 2015.06.11 |
[X][Linux] user, group, sudo (0) | 2015.06.11 |