🧱 LVM 디스크 리사이징 실전기: Vagrant에서 디스크가 안 늘어난다고?
들어가며 🙃
개발용 환경을 Mac mini 위에 Vagrant로 꾸미고 있었는데, 사진 저장, Docker Registry, Jenkins까지 올릴 생각이니 용량이 여유 있어야 하잖아요? 그래서 VM 기본 디스크(30GB)를 VirtualBox 설정에서 128GB로 확장했어요. 그런데…
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 30G 6.7G 22G 24% /
❓ 어라…? 디스크가 안 늘어난 것 같은데…?
1. 왜 디스크가 안 늘어났을까? 🔍
먼저 디스크 구조를 확인해봅니다.
lsblk
sda 128G
├─sda1 1G /boot/efi
├─sda2 2G /boot
└─sda3 60G
└─ubuntu--vg-ubuntu--lv 30G /
정리해 보면…
- VirtualBox 상에서는 128GB 디스크로 확장됨 ✅
/dev/sda3
파티션은 60GB까지만 사용 중 ❗- LVM 위의 루트 볼륨은 여전히 30GB ❗
2. 구조 이해부터: LVM이 뭐냐면 📦
일반적인 디스크는 파티션을 직접 마운트하지만, LVM (Logical Volume Manager) 은 다음처럼 구성돼 있어요:
Physical Disk (/dev/sda)
└── Partition (/dev/sda3)
└── PV (Physical Volume)
└── VG (Volume Group)
└── LV (Logical Volume)
└── FileSystem (ext4, mounted on /)
즉, sda3
는 그냥 파티션이고, 실제 /
는 LVM의 LV(Logical Volume) 위에 있는 거예요. 그래서 단순히 파티션만 커져서는 끝이 아님❗
3. 리사이징 과정 전부 🌱
📌 Step 1. 파티션이 충분한지 확인
이미 sda
는 128GB고, sda3
는 60GB라 여유가 있음. 그럼 이걸 LVM 쪽으로 전달해줘야겠죠?
📌 Step 2. Physical Volume 리사이즈
sudo pvresize /dev/sda3
출력:
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
→ LVM이 파티션의 여유 공간을 인식하게 해줍니다 ✅
📌 Step 3. Logical Volume 리사이즈
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
출력:
Size of logical volume ubuntu-vg/ubuntu-lv changed from 30.47 GiB to 60.95 GiB
→ 이제 루트 볼륨이 남은 공간까지 전부 사용하게 확장됨 🎉
📌 Step 4. 파일시스템 확장
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
출력:
Filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 15976448 (4k) blocks long.
→ 확장 완료!
📌 Step 5. 결과 확인
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 60G 6.7G 51G 12% /
✅ 30GB → 60GB로 늘어난 게 명확히 보이죠?
4. 실패했던 방법들 🧨
❌ parted로 직접 늘려보려던 시도
sudo parted --pretend-input-tty /dev/sda resizepart 1
→ parted는 입력이 복잡하고 대화식이라 자동화 실패 😞
❌ growpart로 시도
sudo growpart /dev/sda 1
→ 결과:
NOCHANGE: partition 1 is size 2201600. it cannot be grown
→ LVM을 인식하지 못해서 실패 😑
5. 자동화하려면? Ansible 예시 🧰
- name: LVM PV 리사이즈
shell: pvresize /dev/sda3
- name: LV 리사이즈
shell: lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
- name: EXT4 파일시스템 리사이즈
shell: resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
- name: 결과 확인
shell: df -h
register: disk_check
- name: 디스크 사용량 출력
debug:
var: disk_check.stdout_lines
정리 ✨
LVM 구조에서 디스크 확장은 여러 단계가 필요합니다:
- 물리 디스크 확장 (VirtualBox에서)
- 파티션 확장 (필요시)
- PV 리사이징 (
pvresize
) - LV 확장 (
lvextend
) - 파일시스템 확장 (
resize2fs
)
이 모든 과정을 Ansible로 자동화하면 클릭 한 번으로 쉽게 해결! 👍
이제 넉넉한 디스크 공간으로 Kubernetes 클러스터에 필요한 모든 것들을 설치해볼 시간입니다! 💪
🧱 LVM Disk Resizing Guide: When Your Vagrant VM Disk Doesn’t Grow
Introduction 🙃
I was setting up a development environment on my Mac mini using Vagrant, and since I planned to host image storage, Docker Registry, and Jenkins, I needed plenty of disk space. So I expanded the VM’s default disk (30GB) to 128GB in VirtualBox settings. But then…
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 30G 6.7G 22G 24% /
❓ Wait… why hasn’t the disk size increased?
1. Why Didn’t the Disk Grow? 🔍
First, let’s check the disk structure.
lsblk
sda 128G
├─sda1 1G /boot/efi
├─sda2 2G /boot
└─sda3 60G
└─ubuntu--vg-ubuntu--lv 30G /
To summarize…
- In VirtualBox, the disk is expanded to 128GB ✅
- The
/dev/sda3
partition is only using 60GB ❗ - The LVM root volume is still 30GB ❗
2. Understanding the Structure: What’s LVM? 📦
Unlike regular disks where partitions are mounted directly, LVM (Logical Volume Manager) is structured like this:
Physical Disk (/dev/sda)
└── Partition (/dev/sda3)
└── PV (Physical Volume)
└── VG (Volume Group)
└── LV (Logical Volume)
└── FileSystem (ext4, mounted on /)
So sda3
is just a partition, and the actual /
is on an LV (Logical Volume) within LVM. That’s why simply growing the partition isn’t enough❗
3. The Complete Resizing Process 🌱
📌 Step 1. Verify Partition Size
The sda
disk is already 128GB, and sda3
is 60GB, so there’s free space. Now we need to pass this to the LVM layer.
📌 Step 2. Resize the Physical Volume
sudo pvresize /dev/sda3
Output:
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
→ This lets LVM recognize the free space in the partition ✅
📌 Step 3. Resize the Logical Volume
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
Output:
Size of logical volume ubuntu-vg/ubuntu-lv changed from 30.47 GiB to 60.95 GiB
→ Now the root volume is expanded to use all available space 🎉
📌 Step 4. Expand the Filesystem
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Output:
Filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 15976448 (4k) blocks long.
→ Expansion complete!
📌 Step 5. Verify the Results
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ubuntu--vg-ubuntu--lv 60G 6.7G 51G 12% /
✅ You can clearly see it grew from 30GB to 60GB!
4. Failed Approaches 🧨
❌ Trying with parted directly
sudo parted --pretend-input-tty /dev/sda resizepart 1
→ parted is interactive and complex, making automation difficult 😞
❌ Attempting with growpart
sudo growpart /dev/sda 1
→ Result:
NOCHANGE: partition 1 is size 2201600. it cannot be grown
→ Failed because it doesn’t properly handle LVM 😑
5. How to Automate? Ansible Example 🧰
- name: Resize LVM PV
shell: pvresize /dev/sda3
- name: Resize LV
shell: lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
- name: Resize EXT4 filesystem
shell: resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
- name: Check results
shell: df -h
register: disk_check
- name: Display disk usage
debug:
var: disk_check.stdout_lines
Summary ✨
Disk expansion in an LVM structure requires multiple steps:
- Expand physical disk (in VirtualBox)
- Expand partition (if needed)
- Resize PV (
pvresize
) - Extend LV (
lvextend
) - Expand filesystem (
resize2fs
)
Automating all these steps with Ansible makes it easy to solve with a single click! 👍
Now it’s time to install everything needed for our Kubernetes cluster with plenty of disk space! 💪