메뉴 닫기

CentOS 6 OS 디스크 보다 적은 사이즈로 디스크 교체하기

요즘에는 디스크 교체시에 디스크 copy하는 장치를 많이 사용합니다.
하지만 디스크 사이즈가 큰거에서 작은 거로는 카피가 안됩니다.
수동으로 작업하는 방법에 대해 적을 것이며 가상 머신에서 테스트 하였습니다.

  • 현재 디스크 확인

[root@jyh-server ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/vda1 ext4 99G 2.6G 91G 3% /
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
 # 현재 100G로 운영중이다.

  • 교체할 디스크 장착후 포멧 마운트

[root@jyh-server ~]# fdisk -u /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6af0de1e.
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').

Command (m for help):  p

Disk /dev/vdb: 26.8 GB, 26843545600 bytes
16 heads, 63 sectors/track, 52012 cylinders, total 52428800 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 identifier: 0x6af0de1e

   Device Boot      Start         End      Blocks   Id  System

Command (m for help):  n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4):  1
First sector (63-52428799, default 63): 
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-52428799, default 52428799): 
Using default value 52428799

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

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

[root@jyh-server ~]# mkfs.ext4 /dev/vdb1
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
1638400 inodes, 6553592 blocks
327679 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
200 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, 
	4096000

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@jyh-server ~]# mkdir /test
[root@jyh-server ~]# mount /dev/vdb1 /test

[root@jyh-server ~]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/vda1      ext4    99G  2.6G   91G   3% /
tmpfs          tmpfs  1.9G     0  1.9G   0% /dev/shm
/dev/vdb1      ext4    25G   44M   24G   1% /test

  • 데이터 복사

[root@jyh-server ~]# rsync -ahPHAXx --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/mnt/*,/media/*,/lost+found} / /test
sending incremental file list
./
.autofsck
           0 100%    0.00kB/s    0:00:00 (xfer#1, to-check=1057/1059)
.autorelabel
           0 100%    0.00kB/s    0:00:00 (xfer#2, to-check=1056/1059)
bin/
bin/alsaunmute
         123 100%    0.00kB/s    0:00:00 (xfer#3, to-check=1119/1144)
bin/arch
      24.23K 100%   23.11MB/s    0:00:00 (xfer#4, to-check=1118/1144)
bin/awk -> gawk
bin/basename
      23.72K 100%   11.31MB/s    0:00:00 (xfer#5, to-check=1116/1144)
bin/bash
...
...
...
var/spool/postfix/private/virtual
var/spool/postfix/public/
var/spool/postfix/public/cleanup
var/spool/postfix/public/flush
var/spool/postfix/public/pickup
var/spool/postfix/public/qmgr
var/spool/postfix/public/showq
var/tmp/
var/yp/

sent 2.35G bytes  received 2.78M bytes  32.90M bytes/sec
total size is 2.53G  speedup is 1.07

  • grub 설치

[root@jyh-server ~]# grub-install --root-directory=/test --recheck /dev/vdb
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /test/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(fd0)	/dev/fd0
(hd0)	/dev/vda
(hd1)	/dev/vdb

  • grub.cfg, fstab 파일 수정

[root@jyh-server ~]# blkid
/dev/vda1: UUID="4f6b4c0c-e807-4f6d-9ad5-67f182f84b05" TYPE="ext4"      --> 교체전 디스크 uuid 
/dev/vdb1: UUID="df62cccf-7fef-455a-8fa9-d8a5b31bb0f4" TYPE="ext4"          --> 교체할 디스크 uuid  


[root@jyh-server ~]# cat /test/etc/grub.conf 
...
...
        kernel /boot/vmlinuz-2.6.32-642.6.2.el6.x86_64 ro root=UUID=df62cccf-7fef-455a-8fa9-d8a5b31bb0f4 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
...
...

[root@jyh-server ~]# cat /test/etc/fstab 
...
...
UUID=df62cccf-7fef-455a-8fa9-d8a5b31bb0f4 /                       ext4    defaults        1 1
...
...

[root@jyh-server ~]# umount /test

  • 디스크 교체 후 부팅 확인

[root@jyh-server ~]# df -Th
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/vda1      ext4    25G  2.5G   21G  11% /
tmpfs          tmpfs  939M     0  939M   0% /dev/shm
# 정상적으로 부팅 되었으며 디스크 사이즈가 25G로 줄었다.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x