4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Reduce disk size on Centos7

Last updated at Posted at 2015-11-26

#proc

  1. new disk (ebs/pd ...) & attach

  2. fdisk

lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   8G  0 disk
├─xvda1 202:1    0   1G  0 part /boot
├─xvda2 202:2    0   1G  0 part [SWAP]
└─xvda3 202:3    0   6G  0 part /
xvdf    202:80   0   8G  0 disk

fdisk /dev/xvdf
コマンド (m でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
パーティション番号 (1-4, default 1):
最初 sector (2048-16777215, 初期値 2048):
初期値 2048 を使います
Last sector, +sectors or +size{K,M,G} (2048-16777215, 初期値 16777215):
初期値 16777215 を使います
Partition 1 of type Linux and of size 8 GiB is set

コマンド (m でヘルプ): p

Disk /dev/xvdf: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xa9515700

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/xvdf1            2048    16777215     8387584   83  Linux

コマンド (m でヘルプ): a
Selected partition 1

コマンド (m でヘルプ): p

Disk /dev/xvdf: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0xa9515700

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/xvdf1   *        2048    16777215     8387584   83  Linux

コマンド (m でヘルプ): w
パーティションテーブルは変更されました!
  1. mount & copy data
mkfs.xfs /dev/xvdf1

mount /mnt/new /dev/xvdf1

xfsdump -J - / | xfsrestore -J -p 60 - /mnt/new
# specific proc
xfsdump -J - /boot | xfsrestore -J -p 60 - /mnt/new/boot
  1. edit fstab
# get UUID
xfs_admin -u /dev/xvdf1
UUID = c864efba-c36d-4165-a4f0-723e4fdfbe4f

# edit fstab 
UUID=c864efba-c36d-4165-a4f0-723e4fdfbe4f       /       xfs     defaults        0 0

  1. chroot
mount -t proc proc ./proc
mount -t sysfs sys ./sys
mount --bind /dev ./dev
chroot .
  1. install grub2
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-install /dev/xvdf
  1. unmount all
umount ./dev
umount ./sys
umount ./proc
umount /mnt/new
  1. set hdd label
xfs_admin -L / /dev/xvdf1
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?