|
|
楼主 |
发表于 2022-9-27 17:33:54
|
显示全部楼层
使用xshell登录虚拟机,按以下步骤执行:+ l( ?0 F: c9 e4 J+ ]4 F
1 O/ R4 ?6 O% R, B( T F' ?
[root@localhost ~]# df -hT
8 q, R: G: ^6 N5 L& g' d$ y P& F8 T: JFilesystem Type Size Used Avail Use% Mounted on
; u( V. f4 b6 Z. [# }/dev/vda3 ext4 36G 34G 16M 100% /
. n" B. v# z1 Q2 w0 n' d( f# `tmpfs tmpfs 99G 23G 77G 23% /dev/shm
* l E% V5 s9 o4 E! C/dev/vda1 ext4 190M 39M 141M 22% /boot% i! h5 }# R5 m" j1 y: i
/dev/vdb1 ext4 2.0T 1.7T 244G 88% /mnt/db1
4 A3 q q" l$ a1 y3 N* J% E2 P) ^6 R$ y0 L8 ?
[root@localhost ~]# fdisk -l
2 E9 b* M/ }" ]6 Z4 EDisk /dev/vda: 42.9 GB, 42949672960 bytes
5 Q2 r$ R3 C1 L( C! y5 i- h16 heads, 63 sectors/track, 83220 cylinders
g- N# _9 z- H6 S1 N* qUnits = cylinders of 1008 * 512 = 516096 bytes
( v: X8 T; ~' J5 c" d7 @Sector size (logical/physical): 512 bytes / 512 bytes6 q' U' W; o6 a
I/O size (minimum/optimal): 512 bytes / 512 bytes9 w4 r( R5 \2 s" s# e/ | T& ?
Disk identifier: 0x0008e937
0 a6 H/ v' H k) ]# L6 R" a9 k( c/ y2 E
Device Boot Start End Blocks Id System" |( s3 n5 O9 N% g/ R
/dev/vda1 * 3 409 204800 83 Linux8 ^% n1 D- g0 |( J
Partition 1 does not end on cylinder boundary.4 _0 r5 Y: F# w$ U" Y) v, R, s* s: k
/dev/vda2 409 8731 4194304 82 Linux swap / Solaris0 k" N) b! Y* q. j, E% C
Partition 2 does not end on cylinder boundary.+ z! r0 B" |1 A$ Y
/dev/vda3 8731 83221 37542912 83 Linux
t7 D! V7 v; v3 ?Partition 3 does not end on cylinder boundary.1 s9 q9 q p) O, F+ o4 t3 M& [
- ]; x- F/ R+ h
Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes" _6 X( T- f7 L# C7 e2 {, S y
16 heads, 63 sectors/track, 4260880 cylinders
$ n! c9 v O3 G# W6 KUnits = cylinders of 1008 * 512 = 516096 bytes
5 r$ o" f! B% b3 DSector size (logical/physical): 512 bytes / 512 bytes
1 P: I* l% r o7 n, I, ^I/O size (minimum/optimal): 512 bytes / 512 bytes# H/ n+ p$ O) F) o( u- n
Disk identifier: 0x97b5a27a3 o' {0 r) m4 J; g& N
: b8 \3 p: U8 Y3 M. D3 I
Device Boot Start End Blocks Id System
" K; z9 `5 c0 R- K) z/dev/vdb1 1 4260880 2147483488+ 83 Linux4 u; ]# V" d8 E+ @ W
2 H! v" @ i' o* h
. ^' Q% T! W3 W+ s$ |+ f6 f由上可以发现,根目录上挂载的是/dev/vda3 这个分区,而且这个系统里的分区id为83,因此不能通过LVM进行逻辑卷管理。; O4 G% T" v3 V2 W3 l
- ?1 e7 |, v/ i6 O[root@localhost ~]# lsblk
Q2 _2 W& i$ O% L8 p9 nNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
6 B, ?8 I( ~# w7 F, M% f zsr0 11:0 1 1024M 0 rom
3 ^" F2 H( d! m3 jvda 252:0 0 40G 0 disk ' \, Y, d) J. O) A$ p# Q
├─vda1 252:1 0 200M 0 part /boot
9 f3 t7 m% l0 Z! s├─vda2 252:2 0 4G 0 part [SWAP]! I! |- D: Z: H% R6 }- a I
└─vda3 252:3 0 35.8G 0 part /
5 |' m2 m% [! gvdb 252:16 0 2T 0 disk # h6 \) Y3 H( ^. v0 A
└─vdb1 252:17 0 2T 0 part /mnt/db1
$ N% a- t9 q( W. V. b" D! t+ K8 F2 {. m( R. e
8 `% \% w- e, G2 `" `1 a1 Q
通过这个命令可以知道,vda确实是已经加了容量了,之前的vda只有40G的。- z) }# E w0 R R `# D
4 ]* `+ X' b% p4 p* s
(1) 现在我们就要把加了的容量添加到vda3并同步到根目录的文件系统中。8 t/ s4 D% G' m# _% h1 t
根据提示,先删除vda3根分区,然后重新创建vda3根分区
! T; l' g( O# ~( x; z4 E) J; r0 u6 u0 u$ t5 y6 B8 }9 X
[root@localhost ~]# fdisk /dev/vda9 d7 i9 h( m8 e& ^6 U! J% @; }3 g
Welcome to fdisk (util-linux 2.23.2).
5 Z4 r+ u: @: Y% T7 @- p5 w7 `9 A, [) q6 X9 Y- d5 w( Q8 r- H0 [
Changes will remain in memory only, until you decide to write them.
( W5 K0 i2 b, r t3 VBe careful before using the write command.8 S( T% r' i; V# o0 [' C
) b+ W2 Y6 F% c& P m
Command (m for help): p //这里输入p,列出分区列表,记住下面的start和end,后续操作才能保证数据不会丢失。: n* m% |& F, g/ K5 t
1 _( _. e% D p8 k1 G
Disk /dev/sda: 51.5 GB, 51539607552 bytes, 100663296 sectors
# C" b; R# b3 J$ h8 F$ BUnits = sectors of 1 * 512 = 512 bytes- v7 ?) F, o& e
Sector size (logical/physical): 512 bytes / 512 bytes
0 w- H7 o/ a& x tI/O size (minimum/optimal): 512 bytes / 512 bytes6 w- t8 t0 t' i2 A
Disk label type: dos$ Y% x: a' b- S" E9 ~; }, H+ E
Disk identifier: 0x000e780b \6 {# u. c1 ^9 I. @: A
) L- V) H% d3 e. i
Device Boot Start End Blocks Id System& G7 k0 G$ I3 V+ k
/dev/vda1 * 3 409 204800 83 Linux
. C* o0 \0 H0 e& XPartition 1 does not end on cylinder boundary.
! e% S1 C( ^% _/dev/vda2 409 8731 4194304 82 Linux swap / Solaris
, _2 Y, X$ }3 M$ W* MPartition 2 does not end on cylinder boundary.
5 A" n" q- U; k1 c9 |% z/dev/vda3 8731 83221 37542912 83 Linux
! t, f( M3 L6 U1 f: {' C, O' z( i7 C" P
Command (m for help): d //这里输入d,表示删除一个分区# _3 U& S" o; {& r4 \* O
Partition number (1-3, default 3): 3 //这里输入3,是因为之前的分区是/dev/sda33 m- k/ Y* { S5 g
Partition 3 is deleted
2 J( A2 \. g+ n9 v- X( B2 \% O# `5 n1 p
Command (m for help): n //删除完,输入n新建一个分区
& @9 A/ m0 J6 Q) k4 ?! C# APartition type:
) l' V/ _3 d [5 M p primary (2 primary, 0 extended, 2 free)
. x) X" Z3 a# L; N, r0 i- z) f! Y e extended4 G% x+ g6 r( X4 z
Select (default p): p //选择主分区# m$ m7 g0 ~% }% q9 {, b# l- h: b
Partition number (3,4, default 3): 3 //还是/dev/sda31 r# G' g$ `+ n* v
First sector (3762176-100663295, default 3762176): //这里直接回车9 f: y. J6 g! Y# d
Using default value 3762176 ( e V. k# A" E2 H
Last sector, +sectors or +size{K,M,G} (3762176-100663295, default 100663295): //这里明显可以看到,不仅包含了之前的sda3的start和end,而且远大于了,使用默认的将剩余的空间都给这个新建的分区。. n' S4 {0 \* r3 ] b' B
Using default value 100663295
1 O# ?: r$ m" ePartition 3 of type Linux and of size 46.2 GiB is set
8 h# {: G* v. v4 x
6 l; s8 B' a9 _5 ^Command (m for help): w //最后写入保存0 d/ o( t( W5 d; }, u7 m
The partition table has been altered!+ a0 N9 W: B# R) {+ H
$ m! v! d8 I6 O3 fCalling ioctl() to re-read partition table.
) V& j% s9 T5 J/ @( `. I: T) o/ w; d
3 X1 {! f2 X4 e0 z5 vWARNING: Re-reading the partition table failed with error 16: Device or resource busy.3 r; q ~( u" c% G) S
The kernel still uses the old table. The new table will be used at
9 E N/ e' R0 f: {the next reboot or after you run partprobe(8) or kpartx(8): J1 l0 j, w; S6 y. }* ^4 |
Syncing disks.7 Z0 q J3 v! a7 n9 e
You have new mail in /var/spool/mail/root, ^. \8 d. ]9 a. I! |
$ L) D$ {& T& L8 a4 S/ c! g. N(2)重启系统$ B+ n1 i& O$ y' ^/ z" Y
重启当前系统,可以选择 reboot 或者 init 6来执行。
/ T" r! S0 p0 y' M//先重启,必须6 Z1 [+ Z% W% K. g9 I% b; w3 Q
: |' D: a- W2 v# x
[root@localhost ~]# reboot
) r# s1 y! V9 P/ \
2 L# H _/ O5 r(3)扩容文件系统" j% H( u# N1 P! e* `" D
我们使用一下命令查看vda3的文件格式:
* T, Q+ O. F- I6 f
$ j" e7 |& s, L! z" W[root@db-phis01 ~]# df -Th /dev/vda3
' o7 Y! o: j6 g1 D) ]& B5 s9 ]* QFilesystem Type Size Used Avail Use% Mounted on
5 K" w( n5 ^! I- {. i/dev/vda3 ext4 36G 34G 16M 100% /
+ P2 i* Q: x7 r: n# H+ ]# k( U0 \3 }6 [+ W$ L; T, D2 r
它的格式是ext4的,使用resize2fs命令,如果是xfs的,就要用xfs_growfs命令进行刷新文件系统容量
6 K1 N% q4 }8 E+ Z* G; f7 e! S/ C# i* U4 l2 g5 E
[root@localhost ~]# resize2fs /dev/vda3) F! y: |+ _1 j9 B: b
$ M: A5 ~' R( i% a: z
然后我们再看根目录的大小:# p% ^! q' c) E$ Y
/ M( |* L+ c6 m3 p/ ?& P$ d
[root@localhost ~]# df -hT
) u3 Y* `8 E$ r! wFilesystem Size Used Avail Use% Mounted on6 K6 V3 a- v( v m+ E
/dev/sda3 47G 13G 34G 27% / }7 c' X4 l8 R
devtmpfs 899M 0 899M 0% /dev
( l5 u* Y% g2 Dtmpfs 913M 0 913M 0% /dev/shm
/ v& Q+ M, N7 s b9 Rtmpfs 913M 8.9M 904M 1% /run' @8 R6 K# d) v5 U9 m5 M4 u
tmpfs 913M 0 913M 0% /sys/fs/cgroup
# K2 ]5 y( E# [+ k( F6 W/dev/sda1 297M 195M 103M 66% /boot1 m. |) F. U: z
tmpfs 183M 0 183M 0% /run/user/0, h; H# w' I% o& F, i9 \3 m
, S. f5 I5 U2 F- U9 x0 @& T$ ]; O6 ?% |( F1 E& o; D7 V6 d
|
|