Linux
디스크 파티션의 크기 조정(확장)
magnon
2018. 1. 30. 15:39
가상하드디스크의 크기 변경 또는 Disk 2 Disk 복사를 한 경우
물리디스크의 크기만 변경되고, 파티션 정보는 그대로 유지되어 있기 때문에,
변경된 디스크의 크기를 인식시키기 위한 일련의 작업이 필요함.
파티션 테이블 갱신 (-> LVM 크기 조정) -> 파일 시스템 인식의 순서로 진행됨.
fdisk를 이용한 파티션 테이블의 갱신
아래는 물리디스크(xvda)가 50GB에서 500GB로 확장하였으나,
파티션 xvda1, xvda2 의 크기가 총 50GB로 450GB 가량이 낭비되고 있는 상태.
# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 1024M 0 rom xvda 202:0 0 500G 0 disk├─xvda1 202:1 0 1G 0 part /boot└─xvda2 202:2 0 49G 0 part ├─centos_test--m2-root 253:0 0 45.1G 0 lvm / └─centos_test--m2-swap 253:1 0 3.9G 0 lvm [SWAP] |
아래와 같이 fdisk를 이용해 파티션 삭제 후 동일한 시작 위치(First Sector)에 파티션을 재생성함.
파티션 타입이 Linux가 아닌 경우에는 파티션의 ID도 변경해야 함. (LVM을 사용하고 있다면 8e 로 변경해야 함.)
언마운트가 불가능한 경우 재부팅이 필요할 수 있음.
# fdisk /dev/xvdaWelcome 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): pDisk /dev/xvda: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00099585 Device Boot Start End Blocks Id System/dev/xvda1 * 2048 2099199 1048576 83 Linux/dev/xvda2 2099200 104857599 51379200 8e Linux LVMCommand (m for help): dPartition number (1,2, default 2): 2Partition 2 is deletedCommand (m for help): nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): Partition number (2-4, default 2): First sector (2099200-1048575999, default 2099200):Using default value 2099200Last sector, +sectors or +size{K,M,G} (2099200-1048575999, default 1048575999):Using default value 1048575999Partition 2 of type Linux and of size 499 GiB is setCommand (m for help): pDisk /dev/xvda: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00099585 Device Boot Start End Blocks Id System/dev/xvda1 * 2048 2099199 1048576 83 Linux/dev/xvda2 2099200 1048575999 523238400 83 LinuxCommand (m for help): tPartition number (1,2, default 2):Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'Command (m for help): pDisk /dev/xvda: 536.9 GB, 536870912000 bytes, 1048576000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00099585 Device Boot Start End Blocks Id System/dev/xvda1 * 2048 2099199 1048576 83 Linux/dev/xvda2 2099200 1048575999 523238400 8e Linux LVMCommand (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks. |
LVM을 사용중인 경우 PV, LV의 크기 조정
아래는 파티션에서는 용량을 제대로 인식하지만, LVM에서 인식하지 못하는 상태
# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 1024M 0 rom xvda 202:0 0 500G 0 disk├─xvda1 202:1 0 1G 0 part /boot└─xvda2 202:2 0 499G 0 part ├─centos_test--m2-root 253:0 0 45.1G 0 lvm / └─centos_test--m2-swap 253:1 0 3.9G 0 lvm [SWAP]# pvdisplay --- Physical volume --- PV Name /dev/xvda2 VG Name centos_test-m2 PV Size <49.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 12543 Free PE 1 Allocated PE 12542 PV UUID rAvse3-V0JT-xVG9-mrA3-dNFg-psfk-ujpwuC |
우선 PV의 크기를 파티션의 크기에 맞게 재조정함.
# pvresize /dev/xvda2 Physical volume "/dev/xvda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized# pvdisplay --- Physical volume --- PV Name /dev/xvda2 VG Name centos_test-m2 PV Size <499.00 GiB / not usable 2.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 127743 Free PE 115201 Allocated PE 12542 PV UUID rAvse3-V0JT-xVG9-mrA3-dNFg-psfk-ujpwuC |
할당 전 LV 정보
# lvdisplay --- Logical volume --- LV Path /dev/centos_test-m2/swap LV Name swap VG Name centos_test-m2 LV UUID t519rK-T0eS-eZp3-cQmx-pvvN-CZMu-O0cwq7 LV Write Access read/write LV Creation host, time test-m2, 2018-01-26 13:15:24 +0900 LV Status available # open 2 LV Size <3.88 GiB Current LE 992 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos_test-m2/root LV Name root VG Name centos_test-m2 LV UUID Lgj2WQ-CiRZ-ende-npXd-mFZd-h8kV-zglFR3 LV Write Access read/write LV Creation host, time test-m2, 2018-01-26 13:15:25 +0900 LV Status available # open 1 LV Size <45.12 GiB Current LE 11550 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 |
PV의 여유공간을 LV에 할당
# lvextend -l +100%Free /dev/mapper/centos_test--m2-root Size of logical volume centos_test-m2/root changed from <45.12 GiB (11550 extents) to 495.12 GiB (126751 extents). Logical volume centos_test-m2/root successfully resized. |
할당 후 PV 및 LV 정보
# pvdisplay --- Physical volume --- PV Name /dev/xvda2 VG Name centos_test-m2 PV Size <499.00 GiB / not usable 2.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 127743 Free PE 0 Allocated PE 127743 PV UUID rAvse3-V0JT-xVG9-mrA3-dNFg-psfk-ujpwuC # lvdisplay --- Logical volume --- LV Path /dev/centos_test-m2/swap LV Name swap VG Name centos_test-m2 LV UUID t519rK-T0eS-eZp3-cQmx-pvvN-CZMu-O0cwq7 LV Write Access read/write LV Creation host, time test-m2, 2018-01-26 13:15:24 +0900 LV Status available # open 2 LV Size <3.88 GiB Current LE 992 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos_test-m2/root LV Name root VG Name centos_test-m2 LV UUID Lgj2WQ-CiRZ-ende-npXd-mFZd-h8kV-zglFR3 LV Write Access read/write LV Creation host, time test-m2, 2018-01-26 13:15:25 +0900 LV Status available # open 1 LV Size 495.12 GiB Current LE 126751 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 |
파일시스템이 늘어난 크기를 인식하지 못하는 경우
아래는 여유공간을 모두 LV에 할당했으나, 늘어난 공간을 파일시스템에서 인식하지 못하는 상태.
# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 1024M 0 rom xvda 202:0 0 500G 0 disk├─xvda1 202:1 0 1G 0 part /boot└─xvda2 202:2 0 499G 0 part ├─centos_test--m2-root 253:0 0 495.1G 0 lvm / └─centos_test--m2-swap 253:1 0 3.9G 0 lvm [SWAP]# df -hTFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/centos_test--m2-root xfs 46G 1.1G 45G 3% /devtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfs tmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs tmpfs 1.9G 8.4M 1.9G 1% /runtmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/xvda1 xfs 1014M 143M 872M 15% /boottmpfs tmpfs 379M 0 379M 0% /run/user/1000 |
파일 시스템 타입이 xfs인 경우(CentOS 7의 기본 파일시스템) xfs_growfs를 이용해 인식시킴
# xfs_growfs /dev/mapper/centos_test--m2-rootmeta-data=/dev/mapper/centos_test--m2-root isize=512 agcount=4, agsize=2956800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0data = bsize=4096 blocks=11827200, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=5775, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 11827200 to 129793024# df -hTFilesystem Type Size Used Avail Use% Mounted on/dev/mapper/centos_test--m2-root xfs 496G 1.1G 495G 1% /devtmpfs devtmpfs 1.9G 0 1.9G 0% /devtmpfs tmpfs 1.9G 0 1.9G 0% /dev/shmtmpfs tmpfs 1.9G 8.4M 1.9G 1% /runtmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup/dev/xvda1 xfs 1014M 143M 872M 15% /boottmpfs tmpfs 379M 0 379M 0% /run/user/1000 |
ext3 또는 ext4인 경우 resize2fs를 사용
# resize2fs /dev/mapper/centos_test--m2-root |
반응형