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

楼主 |
发表于 2022-9-27 17:33:54
|
显示全部楼层
使用xshell登录虚拟机,按以下步骤执行:
2 s; r" u( g Z2 t6 a" z# K8 b2 M( ]# v3 L( `) Z% G
[root@localhost ~]# df -hT3 [, y2 u( m* P/ U0 C
Filesystem Type Size Used Avail Use% Mounted on
L& _3 H9 ?+ J% z4 l0 y( M/dev/vda3 ext4 36G 34G 16M 100% /+ F: T3 X9 A e! L4 u! Y& K
tmpfs tmpfs 99G 23G 77G 23% /dev/shm" f& S4 G4 S+ q
/dev/vda1 ext4 190M 39M 141M 22% /boot
) b( D! P& n0 D0 h D9 S/dev/vdb1 ext4 2.0T 1.7T 244G 88% /mnt/db1
3 P+ Z( I+ @5 v. C+ `
) r; c5 |: W1 T3 Z( }[root@localhost ~]# fdisk -l, O7 b0 p7 D0 W8 C# Z
Disk /dev/vda: 42.9 GB, 42949672960 bytes' z% E4 i: R! ]. [0 ^7 n$ e
16 heads, 63 sectors/track, 83220 cylinders5 Y4 E- K9 ^1 d; t
Units = cylinders of 1008 * 512 = 516096 bytes# w' p7 s+ r0 n2 c
Sector size (logical/physical): 512 bytes / 512 bytes
% _$ z) e; l7 C+ N& RI/O size (minimum/optimal): 512 bytes / 512 bytes% P& m' t/ h- a+ l
Disk identifier: 0x0008e937
! e) J3 x6 E( y. g* @+ V
! }. N/ a: h: ]' x4 p8 K Device Boot Start End Blocks Id System1 {6 j+ K K" G6 T
/dev/vda1 * 3 409 204800 83 Linux8 C# a% g1 f1 I2 X, q3 a- X. w
Partition 1 does not end on cylinder boundary.
' ~5 Y- \# [/ D3 d( [/dev/vda2 409 8731 4194304 82 Linux swap / Solaris
+ \# ` c! _# p" Z4 rPartition 2 does not end on cylinder boundary.
! G+ V2 j% J! c/ p2 d/dev/vda3 8731 83221 37542912 83 Linux
! L" E9 H- G' B/ x" v; BPartition 3 does not end on cylinder boundary.
& X! V& z" X* H& d5 K
0 B4 ^5 Q8 }: ]. {6 FDisk /dev/vdb: 2199.0 GB, 2199023255552 bytes
& V6 A" z& R4 }$ ]16 heads, 63 sectors/track, 4260880 cylinders
" m0 } v; n" y/ t3 k' y; ]# `Units = cylinders of 1008 * 512 = 516096 bytes
+ f) W8 w8 G% D) mSector size (logical/physical): 512 bytes / 512 bytes0 k0 F( i, h" N
I/O size (minimum/optimal): 512 bytes / 512 bytes7 z' X4 L3 _( K; G* c3 D3 y8 }
Disk identifier: 0x97b5a27a
9 ~2 t& L# X* G
& A. A/ M! R1 a/ \1 r Device Boot Start End Blocks Id System9 l- Z" B9 y5 K1 ? b7 M# w
/dev/vdb1 1 4260880 2147483488+ 83 Linux
3 e' U% \ l- k6 S# c
. f6 C' H! Q; D5 O% u
. R8 v8 [5 ]% {0 V- ]由上可以发现,根目录上挂载的是/dev/vda3 这个分区,而且这个系统里的分区id为83,因此不能通过LVM进行逻辑卷管理。9 i7 i% N* ` F: I$ y/ t
4 T! f! N% p+ W+ E[root@localhost ~]# lsblk
/ u4 l2 m* a* V, NNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT2 _; Z: z+ H1 p4 @' A* Q/ p
sr0 11:0 1 1024M 0 rom 1 ]& e; V4 x. T) {6 G i
vda 252:0 0 40G 0 disk
0 ` _1 m: F! k# c# \- Z+ Z" S% L├─vda1 252:1 0 200M 0 part /boot$ D7 Y r2 K( o& C' i6 S' `0 y
├─vda2 252:2 0 4G 0 part [SWAP]
! n) _' I) Z; Q9 ?$ Z; g+ `! o└─vda3 252:3 0 35.8G 0 part /1 J) t( N8 Z0 T# N+ [
vdb 252:16 0 2T 0 disk
5 l* V" ~1 R5 M( N% G└─vdb1 252:17 0 2T 0 part /mnt/db1
, }3 e6 p/ F3 V# d: X5 P7 D7 ?
( k5 Y* `1 s# a2 t9 c( g. Q5 [3 }5 ~( T( H
通过这个命令可以知道,vda确实是已经加了容量了,之前的vda只有40G的。
& l, [$ d& C- J& l: k- b& t/ R( K S0 P$ F
(1) 现在我们就要把加了的容量添加到vda3并同步到根目录的文件系统中。' ]% u* P% [) }* l" Q
根据提示,先删除vda3根分区,然后重新创建vda3根分区
, l# O/ I* W7 C+ n: C* s3 j0 E& B. j
: C) R0 }( ^. B* k2 u& H[root@localhost ~]# fdisk /dev/vda% u; Z% A D# b; J, @
Welcome to fdisk (util-linux 2.23.2).
1 }1 x) C& r: G6 n: |% K
) v% M `& X5 y' XChanges will remain in memory only, until you decide to write them.
0 |3 f( m$ V( \$ e1 }Be careful before using the write command.8 u* [/ U# \/ z& a: f/ r! S9 [
: _- y0 Z0 N j# W
Command (m for help): p //这里输入p,列出分区列表,记住下面的start和end,后续操作才能保证数据不会丢失。
2 D" W. B2 {( t) D8 A1 A% g. O, k/ u' M- ?& ]; W0 f( W
Disk /dev/sda: 51.5 GB, 51539607552 bytes, 100663296 sectors) d c6 C$ \ M1 A" p3 Q
Units = sectors of 1 * 512 = 512 bytes
+ a/ S; E ~* `/ C1 sSector size (logical/physical): 512 bytes / 512 bytes
7 l1 [2 _# h! h0 S4 @# a' gI/O size (minimum/optimal): 512 bytes / 512 bytes
) V/ I0 @: g: l5 F; c( o9 _3 kDisk label type: dos
2 E& K* F3 C( P+ V, `8 ]Disk identifier: 0x000e780b# M1 b o, H7 ~4 p, `
K8 i, I) j# N& q. }2 ? Device Boot Start End Blocks Id System$ h! [( k; p! j4 _2 K
/dev/vda1 * 3 409 204800 83 Linux* p3 y1 i6 F9 w3 @) q; A- u
Partition 1 does not end on cylinder boundary.
5 _; F7 r4 B) U- r2 s/dev/vda2 409 8731 4194304 82 Linux swap / Solaris
& g. _* C$ a" ZPartition 2 does not end on cylinder boundary.
2 ^" u. @: H) Z7 q8 N t/dev/vda3 8731 83221 37542912 83 Linux8 d$ }/ Z: ]% M" j; V$ ]& f% R
8 S5 C% a6 o; R3 l- a# f$ ~/ A. U
Command (m for help): d //这里输入d,表示删除一个分区
+ X5 j, I5 C* h5 V _% Y9 iPartition number (1-3, default 3): 3 //这里输入3,是因为之前的分区是/dev/sda3. {7 @) E2 C% _- C6 s3 C+ p$ \
Partition 3 is deleted; g. r8 Y3 e6 T1 Z7 b
; [, T& v Y+ e F0 F1 K3 |4 [6 d
Command (m for help): n //删除完,输入n新建一个分区
+ g0 Z! r( V# yPartition type:9 ~4 Q* q9 X4 {* d
p primary (2 primary, 0 extended, 2 free)
3 Y1 p* c7 }' c# ~+ f, ]# H e extended
e* F9 M% Q2 O8 WSelect (default p): p //选择主分区
6 P, R* H' y& v! q9 bPartition number (3,4, default 3): 3 //还是/dev/sda37 ~, k1 X- M" y( M
First sector (3762176-100663295, default 3762176): //这里直接回车 v9 g' w. g( [/ x8 G/ b3 }9 s
Using default value 3762176 2 Y, m! {! B, b! b5 g
Last sector, +sectors or +size{K,M,G} (3762176-100663295, default 100663295): //这里明显可以看到,不仅包含了之前的sda3的start和end,而且远大于了,使用默认的将剩余的空间都给这个新建的分区。: ^" S1 u3 p1 }% Q! @+ g4 {4 o$ s% A
Using default value 100663295
+ x6 m/ P3 V. d7 Q/ hPartition 3 of type Linux and of size 46.2 GiB is set5 @* [ n: k0 q2 \( F0 V
! u9 b6 \# t! F/ U
Command (m for help): w //最后写入保存: o+ X& K) M9 S _
The partition table has been altered!
2 @1 s3 D9 b4 r( c1 z- _3 D' s% ?6 h
Calling ioctl() to re-read partition table.
+ z( H G8 T6 }1 g% p4 W+ }6 [) K. w2 P* t" b+ Q& M9 Y, @
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
0 O% D! {3 B5 K" V9 ]) O6 CThe kernel still uses the old table. The new table will be used at
/ w0 N l9 i% y) t# I) Q7 K9 nthe next reboot or after you run partprobe(8) or kpartx(8)# n$ n9 A5 e) e2 R, _' ^( w4 T5 O
Syncing disks.
+ @- ~* m; J# s8 c3 i3 F! y9 FYou have new mail in /var/spool/mail/root$ {8 w/ R: w/ E; O5 T; w
, M- B: Z+ S% b& w
(2)重启系统. d0 c' l' H/ {7 c
重启当前系统,可以选择 reboot 或者 init 6来执行。! l# _; e) z: y* D6 G% R
//先重启,必须
: f) d' ?9 u' K
$ i! S& E9 |5 S+ Z[root@localhost ~]# reboot
4 ? D3 X3 O. f/ b; @
/ U r' Q9 h! N; A4 t4 Q(3)扩容文件系统7 I+ ^+ A; q9 A, l1 D' Z" o; G) w
我们使用一下命令查看vda3的文件格式:
" U: W0 A/ V; k/ ^9 V8 \
3 a @/ l/ b) V! ]- f" q1 E[root@db-phis01 ~]# df -Th /dev/vda3
& O4 Z. X% `6 U- PFilesystem Type Size Used Avail Use% Mounted on1 T( C3 k6 @/ t1 l# q6 l9 ^
/dev/vda3 ext4 36G 34G 16M 100% /
* R2 ?. n) I5 q; ~( ]/ a/ d" q* s: ~; E; [+ M; X7 T
它的格式是ext4的,使用resize2fs命令,如果是xfs的,就要用xfs_growfs命令进行刷新文件系统容量
) ~6 A8 U ~/ y# t- g' P$ h
8 ]( j2 O7 ]4 V' {: z* r. l9 \[root@localhost ~]# resize2fs /dev/vda32 e2 ]% Q, t* y& y7 `/ S
* i0 S6 p& Y3 e5 z然后我们再看根目录的大小:
W; z W' Q, B' }* A
& p/ j M3 P) z# t% \+ z0 g[root@localhost ~]# df -hT
" _9 g0 [7 f2 j# xFilesystem Size Used Avail Use% Mounted on
$ w* u9 K* O4 y6 Y% t$ R: f/dev/sda3 47G 13G 34G 27% // Q* ^" J/ J# P- c5 `
devtmpfs 899M 0 899M 0% /dev
# y: I3 G$ s; |# Xtmpfs 913M 0 913M 0% /dev/shm4 m* _* G# @, l$ z. i) ?9 v! L
tmpfs 913M 8.9M 904M 1% /run1 R2 K, D6 _1 X* n
tmpfs 913M 0 913M 0% /sys/fs/cgroup
+ W0 o' R+ s; M* K, [/dev/sda1 297M 195M 103M 66% /boot
( R/ i* N+ B7 ~' b8 b( Q$ Wtmpfs 183M 0 183M 0% /run/user/0$ G% q, V, a3 c1 N- U4 Y
( U8 s- T- P' I2 ^9 f1 `
1 D2 M1 g( X+ R" G; @8 c |
|