리눅스 물리 파티션 e2fsck를 이용해 용량 증설
*e2fsck로 특정 파일시스템 점검시 오류 자동수정
e2fsck 옵션
-p |
자동으로 복구 (질문없이) |
-n |
파일 시스템 변경 |
-y |
모든 질문에 Yes라고 대답 |
-c |
Bad Block을 검사 |
-f |
파일 시스템에 문제가 없어도 강제로 검사 |
-v |
작업 내용을 상세히 출력 |
-j [유형] |
ext2, ext3, ext4 기타 등 설정하여 체크 |
주의사항
- e2fsck은 기본 ext2 대상으로 체크
- 해당장치가마운트가되어있는경우오류가발생할수있음
특정 파일 시스템 강제 점검 및 복구*** 강제점검및 복구는 불가피한 상황이 아니면 사용하지 않습니다. ***
1. on-line에서 진행불가... 데이터 보존 장담 불가...#umount /data2
2. fdisk 명령으로 추가한 1테라 디스크를 확인합니다. # fdisk -lDisk /dev/sda: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 121340 974663518+ 83 Linux/dev/sda2 121341 121601 2096482+ 82 Linux swap / SolarisDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes <---------------------- 확인255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes
3. 추가한 /dev/sdb 하드를 fdisk로 실행합니다. # fdisk /dev/sdbThe number of cylinders for this disk is set to 121601.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
4. fdisk 모드에서 p 명령어로 파티션정보를 확인합니다. Command (m for help): pDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System
6. 파티션을 생성하기 위해 n 명령어를 Command (m for help): nCommand action e extended p primary partition (1-4)
7. 프라이머리 파티션 생성을 위해 파티션 넘버 1을 적어주고 엔터, 엔터 .. Partition number (1-4): 1First cylinder (1-121601, default 1):Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-121601, default 121601):Using default value 121601
8. 파티션이 잘 생성되었는지 확인합니다. Command (m for help): pDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sdb1 1 121601 976760001 83 Linux <------------------- 확인
9. fdisk를 저장하고 나옵니다. Command (m for help): wThe partition table has been altered!
Calling ioctl() to re-read partition table.Syncing disks.
10. 디스크를 초기화시키면 안되요 바로 디스크 검사를 해줍니다.# e2fsck -f /dev/sdb1e2fsck 1.35 (28-Feb-2004)/dev/sdb1 is mounted.
WARNING!!! Running e2fsck on a mounted filesystem may causeSEVERE filesystem damage.
Do you really want to continue (y/n)? yes
Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/boot1: 34/26104 files (2.9% non-contiguous), 11778/104388 blocks
11. 디스크 검사해주고 사이즈를 조정해줍니다.# resize2fs /dev/sdb1resize2fs 1.39 (29-May-2006)Resizing the filesystem on /dev/sdb1 to 439122710 (4k) blocks.
% 추가 옵션
ext3(저널링)파일시스템의 점검 및 복구 "-j ext3" 옵션을 주면 됩니다.# e2fsck -j ext3 /dev/sdb1
특정 파일시스템 강제 점검 및 상세 작업내용보기 # e2fsck -fv /dev/sdb1
파일시스템 제약 및 데이터 손실 여부 문제로 논란이 있었던 내용인데 결론적으로 같은 디스크 영역내에 여유공간만 있다면 데이터 손실없이 리사이즈 가능합니다.
(매우 크리티컬한 작업이므로 작업 전 백업은 필수입니다)
%. 해당 내용은 "Linux native partition" 리사이즈에 대하여 언급하고 있습니다. 리눅스 LVM의 경우 당연히 리사이즈 가능합니다.
* 레드헷 자료
■ How to Resize a Partition using fdisk
https://access.redhat.com/articles/1190213
■ How to Grow an ext2/3/4 File System with resize2fs
https://access.redhat.com/articles/1196353
■ How to Shrink an ext2/3/4 File system with resize2fs
https://access.redhat.com/articles/1196333
* vmwae를 이용한 테스트
[root@RHEL5 /]# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes -> (/dev/sdb 전체 파티션 용량 2GB)
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 131 1052226 83 Linux -> (/dev/sdb1 파티션 용량 1GB)
Command (m for help): q
[root@RHEL5 /]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
131616 inodes, 263056 blocks
13152 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=272629760
9 block groups
32768 blocks per group, 32768 fragments per group
14624 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@RHEL5 /]# mount /dev/sdb1 /a
[root@RHEL5 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 3.0G 14G 18% /
/dev/sda1 289M 17M 258M 7% /boot
tmpfs 500M 0 500M 0% /dev/shm
/dev/sdb1 1012M 34M 927M 4% /a
[root@RHEL5 /]# cd /a
[root@RHEL5 a]# touch test.txt
[root@RHEL5 a]# vi test.txt
hello
[root@RHEL5 a]# cd /
[root@RHEL5 /]# umount /a
[root@RHEL5 /]# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 131 1052226 83 Linux
Command (m for help): d
Selected partition 1
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): -> (용량 증설 1GB-> 2GB)
Using default value 261
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@RHEL5 /]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 2353 18595237+ 83 Linux
/dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux
[root@RHEL5 /]# resize2fs /dev/sdb1
resize2fs 1.39 (29-May-2006)
Please run 'e2fsck -f /dev/sdb1' first.
[root@RHEL5 /]# e2fsck -f /dev/sdb1
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 12/131616 files (8.3% non-contiguous), 12671/263056 blocks
[root@RHEL5 /]# resize2fs /dev/sdb1
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/sdb1 to 524112 (4k) blocks.
The filesystem on /dev/sdb1 is now 524112 blocks long.
[root@RHEL5 /]# mount /dev/sdb1 /a
[root@RHEL5 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 3.0G 14G 18% /
/dev/sda1 289M 17M 258M 7% /boot
tmpfs 500M 0 500M 0% /dev/shm
/dev/sdb1 2.0G 34M 1.9G 2% /a
[root@RHEL5 /]# ls -al /a
total 36
drwxr-xr-x 3 root root 4096 Dec 16 16:44 .
drwxr-xr-x 25 root root 4096 Dec 16 16:20 ..
drwx------ 2 root root 16384 Dec 16 16:44 lost+found
-rw-r--r-- 1 root root 6 Dec 16 16:44 test.txt -> (데이터 손실 없음)
[root@RHEL5 /]# cat /a/test.txt
hello
[root@RHEL5 /]# blkid
/dev/sda3: TYPE="swap" LABEL="SWAP-sda3"
/dev/sda2: LABEL="/" UUID="d9d4e8ba-9744-4369-a05c-52c705a814a3" TYPE="ext3" SEC_TYPE="ext2"
/dev/sda1: LABEL="/boot" UUID="f9497f4e-0d2e-42ff-8ea7-bab1ffb551d8" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdb1: UUID="90bcf8ea-3a9c-4091-8de7-2373c10f3912" SEC_TYPE="ext2" TYPE="ext3"
* Dell R710 서버를 이용한 테스트
vmware 결과와 동일합니다.