[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 18.4G 0 disk
├─sda1 8:1 0 400M 0 part /boot
├─sda2 8:2 0 10G 0 part
│ └─luks-b22f30aa-72d7-4523-aa21-dc516da53fc8
253:0 0 10G 0 crypt /
├─sda3 8:3 0 4G 0 part
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 500M 0 part [SWAP]
└─sda6 8:6 0 10M 0 part
sr0 11:0 1 55.3M 0 rom
[root@localhost ~]# fdisk /dev/sda
Welcome 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): p
Disk /dev/sda: 19.8 GB, 19787972608 bytes, 38648384 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 label type: dos
Disk identifier: 0x000a6d01
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 821247 409600 83 Linux
/dev/sda2 821248 21792767 10485760 83 Linux
/dev/sda3 21792768 30181375 4194304 83 Linux
/dev/sda4 30181376 38647807 4233216 5 Extended
/dev/sda5 30183424 31207423 512000 82 Linux swap / Solaris
/dev/sda6 31209472 31229951 10240 83 Linux
Command (m for help): d
Partition number (1-6, default 6): 3
Partition 3 is deleted
Command (m for help): d
Partition number (1,2,4-6, default 6): 2
Partition 2 is deleted
Command (m for help): n
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): p
Partition number (2,3, default 2): 2
First sector (821248-38648383, default 821248):
Using default value 821248
Last sector, +sectors or +size{K,M,G} (821248-30181375, default 30181375):
Using default value 30181375
Partition 2 of type Linux and of size 14 GiB is set
Command (m for help): w
The 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 at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# reboot Connection to 127.0.0.1 closed by remote host. Connection to 127.0.0.1 closed.
[root@dyw219 ~]# ssh -o VerifyHostKeyDNS=no -l kkdd -p 5679 127.0.0.1
Verification code:
Password:
Last login: Tue Mar 20 10:10:03 2018 from gateway
[kkdd@localhost ~]$ su -
Password:
Last login: Tue Mar 20 10:10:13 CST 2018 on pts/0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 18.4G 0 disk
├─sda1 8:1 0 400M 0 part /boot
├─sda2 8:2 0 14G 0 part
│ └─luks-b22f30aa-72d7-4523-aa21-dc516da53fc8
253:0 0 14G 0 crypt /
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 500M 0 part [SWAP]
└─sda6 8:6 0 10M 0 part
sr0 11:0 1 55.3M 0 rom
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/dm-0 10G 7.2G 2.8G 73% / devtmpfs 2.1G 0 2.1G 0% /dev tmpfs 2.1G 0 2.1G 0% /dev/shm tmpfs 2.1G 8.9M 2.1G 1% /run tmpfs 2.1G 0 2.1G 0% /sys/fs/cgroup /dev/sda1 397M 248M 150M 63% /boot tmpfs 422M 12K 422M 1% /run/user/42 tmpfs 422M 0 422M 0% /run/user/1000 tmpfs 422M 0 422M 0% /run/user/0
[root@localhost ~]# cryptsetup -v resize luks-b22f30aa-72d7-4523-aa21-dc516da53fc8 Command successful.
[root@localhost ~]# resize2fs /dev/mapper/luks-b22f30aa-72d7-4523-aa21-dc516da53fc8 resize2fs 1.42.9 (28-Dec-2013) resize2fs: Bad magic number in super-block while trying to open /dev/mapper/luks-b22f30aa-72d7-4523-aa21-dc516da53fc8 Couldn't find valid filesystem superblock.
xfs_growfs 工具將檔案系統放大到 cryptsetup resize 調整的值。
[root@localhost ~]# xfs_growfs /dev/mapper/luks-b22f30aa-72d7-4523-aa21-dc516da53fc8
meta-data=/dev/mapper/luks-b22f30aa-72d7-4523-aa21-dc516da53fc8 isize=512 agcount=4, agsize=655232 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2620928, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2620928 to 3669504
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/dm-0 14G 7.2G 6.8G 52% / devtmpfs 2.1G 0 2.1G 0% /dev tmpfs 2.1G 0 2.1G 0% /dev/shm tmpfs 2.1G 8.9M 2.1G 1% /run tmpfs 2.1G 0 2.1G 0% /sys/fs/cgroup /dev/sda1 397M 248M 150M 63% /boot tmpfs 422M 12K 422M 1% /run/user/42 tmpfs 422M 0 422M 0% /run/user/1000 tmpfs 422M 0 422M 0% /run/user/0