- 积分
- 16843
在线时间 小时
最后登录1970-1-1
|

楼主 |
发表于 2022-9-27 17:33:54
|
显示全部楼层
使用xshell登录虚拟机,按以下步骤执行:: I% }' I9 l2 _4 ~% ^8 s: b$ A
8 d: x) K% y, U( c; C7 S
[root@localhost ~]# df -hT8 a2 O9 ]" J- T% N9 p$ P
Filesystem Type Size Used Avail Use% Mounted on& L: I* o/ r/ b+ t
/dev/vda3 ext4 36G 34G 16M 100% /5 a8 k: \3 t# f: \' v% L
tmpfs tmpfs 99G 23G 77G 23% /dev/shm
9 `9 R6 P. I, d) u5 j/dev/vda1 ext4 190M 39M 141M 22% /boot
% Z% v& w# X3 P# D% i" Z% u/dev/vdb1 ext4 2.0T 1.7T 244G 88% /mnt/db1
0 C y) h# ?1 R2 D& c) o3 ?
+ v3 j5 A- F) z[root@localhost ~]# fdisk -l9 L/ Q9 `3 X( c
Disk /dev/vda: 42.9 GB, 42949672960 bytes
@* O# e x$ w7 L9 u16 heads, 63 sectors/track, 83220 cylinders
0 O. K7 }6 B. q) P& I3 a# WUnits = cylinders of 1008 * 512 = 516096 bytes
) X+ |3 c/ r0 q( pSector size (logical/physical): 512 bytes / 512 bytes% \$ K/ _4 R! z* M0 i- G; ]
I/O size (minimum/optimal): 512 bytes / 512 bytes1 I- A- Q5 V& B9 ]# F- N
Disk identifier: 0x0008e937
" n( i6 J4 @6 f
5 r0 W$ L3 ^' W+ q& m Device Boot Start End Blocks Id System: `0 @& ^, z) O8 B/ n* n. d* J# S
/dev/vda1 * 3 409 204800 83 Linux: a5 a( F" j+ D
Partition 1 does not end on cylinder boundary.) X' W0 Z! H. ?- j# e) Q
/dev/vda2 409 8731 4194304 82 Linux swap / Solaris" S9 R/ ]: O' Z5 N1 f
Partition 2 does not end on cylinder boundary.
& C, N2 K( `2 ]/dev/vda3 8731 83221 37542912 83 Linux f! j; q6 j" i
Partition 3 does not end on cylinder boundary.
, U3 L/ L7 y6 o! g3 J+ F5 l }# R4 Q
Disk /dev/vdb: 2199.0 GB, 2199023255552 bytes" [0 ?% k% q8 j+ Y* H2 }; G& J3 ]
16 heads, 63 sectors/track, 4260880 cylinders+ e( O8 Y* F, f9 t" c1 g
Units = cylinders of 1008 * 512 = 516096 bytes
# h$ O8 J% S. D P5 a NSector size (logical/physical): 512 bytes / 512 bytes
& P3 p% s: K# vI/O size (minimum/optimal): 512 bytes / 512 bytes8 L& @0 M8 S: w% N
Disk identifier: 0x97b5a27a% Z, h4 f) l- [- C8 W) {3 L
1 T- l F* {1 v Device Boot Start End Blocks Id System, J9 L2 I! {; Q
/dev/vdb1 1 4260880 2147483488+ 83 Linux
3 \+ k( G" u! u8 H* v% X2 z. s
+ x7 R' }& M! d+ u7 Y$ l3 M1 Q/ c
! ]+ c% B5 ^2 H$ J$ B& n- q! J由上可以发现,根目录上挂载的是/dev/vda3 这个分区,而且这个系统里的分区id为83,因此不能通过LVM进行逻辑卷管理。" m# S. b$ P6 P8 l$ e: g
/ ]% @: F5 Z7 u
[root@localhost ~]# lsblk( K9 X8 j$ G. m/ E
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT# Z0 x6 b0 V; P4 {+ N; h
sr0 11:0 1 1024M 0 rom 4 W3 i( M2 d6 b! @8 L# e. w7 j3 O
vda 252:0 0 40G 0 disk : b5 U) o$ [8 x4 x. {' e
├─vda1 252:1 0 200M 0 part /boot1 m7 Y. J. `9 m$ a* m% q
├─vda2 252:2 0 4G 0 part [SWAP]
- n" K. M+ C- J└─vda3 252:3 0 35.8G 0 part /
# t& X$ D3 K s9 T0 x; L" gvdb 252:16 0 2T 0 disk ; u e q& L* Y- L+ I3 M
└─vdb1 252:17 0 2T 0 part /mnt/db1
! |/ R2 w+ F4 r# I
; A- N( S, s( ]; j* D% Y0 R, D* V6 k! O( n" @2 F$ ]
通过这个命令可以知道,vda确实是已经加了容量了,之前的vda只有40G的。
+ U" R' P# r9 j8 p7 S. \% I
* l) ~+ z5 u6 ?6 k' g) e0 D4 ^& p(1) 现在我们就要把加了的容量添加到vda3并同步到根目录的文件系统中。3 j% e# X2 F( w1 h1 q9 q: v) y
根据提示,先删除vda3根分区,然后重新创建vda3根分区6 `4 J3 Y9 h# W1 r7 j5 {
& H- m! c# V1 o' b5 w+ {3 o
[root@localhost ~]# fdisk /dev/vda
) ~0 |3 B4 W! DWelcome to fdisk (util-linux 2.23.2).
, e- o0 g7 e6 ?8 V6 o: _8 I' |6 o# U5 g" W4 \% j" q
Changes will remain in memory only, until you decide to write them.
' X' l% |$ r$ T# _0 ^Be careful before using the write command.1 ] l* q" z6 N
/ U1 M& {% h- o1 z( U% O5 F0 l
Command (m for help): p //这里输入p,列出分区列表,记住下面的start和end,后续操作才能保证数据不会丢失。
( d" r( f+ e6 P* |* _- }3 ^/ [5 N9 d6 G7 u9 i- {5 @; v
Disk /dev/sda: 51.5 GB, 51539607552 bytes, 100663296 sectors ]. c; X0 y& [2 w
Units = sectors of 1 * 512 = 512 bytes
# d8 @, @( U J/ c4 ~Sector size (logical/physical): 512 bytes / 512 bytes" S. x, w; z& O: d( k, Z
I/O size (minimum/optimal): 512 bytes / 512 bytes
- `6 e) h; T$ y+ ZDisk label type: dos
" G: \* h! I! j3 }9 TDisk identifier: 0x000e780b
. Q. O, i( D, ^- B6 O2 \- K2 X' e* q- G2 C$ k
Device Boot Start End Blocks Id System6 I/ @6 q& G) X9 ^& t! z1 [. L
/dev/vda1 * 3 409 204800 83 Linux$ z( A1 W$ Y; g6 \! f W
Partition 1 does not end on cylinder boundary.+ l: ^/ h% p. n K
/dev/vda2 409 8731 4194304 82 Linux swap / Solaris4 V' `) v2 k. X6 ?/ @/ L) Y0 R1 W
Partition 2 does not end on cylinder boundary.
* I. E0 }2 `* ^* b/dev/vda3 8731 83221 37542912 83 Linux
: _1 ^' Z5 d5 d( L9 } [$ T8 o2 O
) I1 p! W5 R7 ]% }Command (m for help): d //这里输入d,表示删除一个分区7 A/ Z0 |2 k9 z8 ~3 {7 ]
Partition number (1-3, default 3): 3 //这里输入3,是因为之前的分区是/dev/sda3: h' U; I f& P
Partition 3 is deleted
& |5 f, d+ a H W H& ]) [+ l
, r- S# d' w, z0 n2 ZCommand (m for help): n //删除完,输入n新建一个分区* f7 B. B9 |: A( @1 s
Partition type:$ ?6 z" Q. O# g+ P
p primary (2 primary, 0 extended, 2 free). m: g$ [! K1 `' k/ n
e extended1 B$ o% @" W8 r/ B+ H' C2 {& N
Select (default p): p //选择主分区3 A- ]: d( V7 I8 q: O7 j
Partition number (3,4, default 3): 3 //还是/dev/sda3
4 A( V1 G1 g; H+ M5 Z+ lFirst sector (3762176-100663295, default 3762176): //这里直接回车9 |: l7 r( `: ^
Using default value 3762176 - w0 \ k( E# _7 v1 i5 D* a
Last sector, +sectors or +size{K,M,G} (3762176-100663295, default 100663295): //这里明显可以看到,不仅包含了之前的sda3的start和end,而且远大于了,使用默认的将剩余的空间都给这个新建的分区。9 d+ Q7 R; {' L! P
Using default value 100663295
6 O3 I$ q2 ~/ J& i* l5 nPartition 3 of type Linux and of size 46.2 GiB is set% I2 H5 g6 g2 y# ?
: p: b3 L3 i( j% A8 VCommand (m for help): w //最后写入保存8 _5 O1 V I6 i+ S7 z
The partition table has been altered!# M! Y& I2 G( g0 } `
2 H1 b1 L' C' g% VCalling ioctl() to re-read partition table.* Y3 {, Z1 k7 I; h1 F2 Z q" a
2 {1 R( L/ V+ C; W
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
9 g9 R9 U' D% a6 {8 g% U' Z, CThe kernel still uses the old table. The new table will be used at
3 I1 ?/ B' V- m( b! U5 ?% l* bthe next reboot or after you run partprobe(8) or kpartx(8)- q0 V5 \- E) p5 s0 X
Syncing disks.
# n1 k6 _ a# v2 dYou have new mail in /var/spool/mail/root
" q W# T: u1 N- J [
) c" [8 b9 x7 P(2)重启系统9 g# I2 h: P0 e2 W* o& V
重启当前系统,可以选择 reboot 或者 init 6来执行。8 E5 }2 P/ n5 N
//先重启,必须6 i* ^& i: j5 Y5 x# z
2 s& e7 `9 g% j: ^
[root@localhost ~]# reboot% X0 F9 L& C+ X E, D% r4 Q% t
3 g+ Q3 @: E- b; \, Z" J6 w; o! [: @# K(3)扩容文件系统
6 h! d& W& Z/ k) q* D我们使用一下命令查看vda3的文件格式:
0 `, Q& \" G% k8 U; W! ?" l8 U, M) D5 W* M, {6 f# [
[root@db-phis01 ~]# df -Th /dev/vda3
: u8 g- G* w$ x# O& f' O+ {/ m7 D7 HFilesystem Type Size Used Avail Use% Mounted on
9 ^: x2 ~, A7 O: A) n/dev/vda3 ext4 36G 34G 16M 100% /4 f# o) Q/ s" e7 M) G
# E0 J: U4 W; }/ d2 i; f: {! z
它的格式是ext4的,使用resize2fs命令,如果是xfs的,就要用xfs_growfs命令进行刷新文件系统容量
3 J+ K; X. V+ q, c2 n* ]0 _7 {
* V' s9 ]# v4 d8 R[root@localhost ~]# resize2fs /dev/vda3
$ J5 s4 e& i' W
3 v+ Z5 h" M6 E1 t5 X然后我们再看根目录的大小:
2 m6 t+ w- f/ K: H% E6 a
; ]6 j9 C# l0 u q" x& K[root@localhost ~]# df -hT5 i! v! T+ }/ F3 U5 O' u
Filesystem Size Used Avail Use% Mounted on
- s( ?* ? U9 c/dev/sda3 47G 13G 34G 27% /
! f3 J7 f$ {+ @1 _devtmpfs 899M 0 899M 0% /dev
0 V7 U" N, z2 wtmpfs 913M 0 913M 0% /dev/shm" T3 C( i. {! v: b
tmpfs 913M 8.9M 904M 1% /run5 Q2 T8 n4 r* ^1 a4 R* E3 b
tmpfs 913M 0 913M 0% /sys/fs/cgroup; T$ F4 I, q; m, E! R& k
/dev/sda1 297M 195M 103M 66% /boot
& F& \9 E+ u" n* j: z5 Gtmpfs 183M 0 183M 0% /run/user/0
4 W T1 i0 @% o" A/ Z, N7 p1 [' Y9 f) y, W3 D/ C; p( m
; n, I4 y' H% ^8 L+ j |
|