|
|
楼主 |
发表于 2022-9-27 17:33:54
|
显示全部楼层
使用xshell登录虚拟机,按以下步骤执行:
( J$ k4 u9 ?. @, g% v; r) _* a# ~' I
[root@localhost ~]# df -hT) N1 Y% l5 ~% H' U
Filesystem Type Size Used Avail Use% Mounted on
b, R: O6 ^: J/dev/vda3 ext4 36G 34G 16M 100% /
4 m) N g/ N( C. {8 ltmpfs tmpfs 99G 23G 77G 23% /dev/shm l# @% V( {5 g6 t5 g9 U
/dev/vda1 ext4 190M 39M 141M 22% /boot7 Z& R& A* \. ^: i
/dev/vdb1 ext4 2.0T 1.7T 244G 88% /mnt/db1( X F0 U$ {$ v, m1 k8 E9 n4 L" L
( V2 \& |# M. b% A: u/ q& q
[root@localhost ~]# fdisk -l
& n7 Y% j" | O( L: c2 S" o, ~2 RDisk /dev/vda: 42.9 GB, 42949672960 bytes
5 B. B6 W+ a1 ~3 x16 heads, 63 sectors/track, 83220 cylinders
, Z" B! _' ]- ?. V" I: y( b" LUnits = cylinders of 1008 * 512 = 516096 bytes
6 [( @; S, d$ `' N0 k# S5 RSector size (logical/physical): 512 bytes / 512 bytes% z) i; p/ V+ J/ r5 }
I/O size (minimum/optimal): 512 bytes / 512 bytes
8 G4 t: a# }8 h! Q g: [Disk identifier: 0x0008e937# u, D' w1 ~+ l# K. u8 s
) D! X5 t( i, y. E7 b7 P$ ~/ E
Device Boot Start End Blocks Id System
3 ~9 \' W; n. `9 J7 L6 `6 L/dev/vda1 * 3 409 204800 83 Linux
, r; K8 p" k7 l. V$ M9 R3 j4 vPartition 1 does not end on cylinder boundary.
4 G8 ^( N$ ~( o/dev/vda2 409 8731 4194304 82 Linux swap / Solaris
. n+ T0 N4 u8 HPartition 2 does not end on cylinder boundary.
) `1 g% c4 s M/dev/vda3 8731 83221 37542912 83 Linux3 i- H3 Q, j: N1 W
Partition 3 does not end on cylinder boundary.
/ D; o7 m8 O0 r* u# K! d, |
7 l8 @" Z9 m Z |* @# w2 tDisk /dev/vdb: 2199.0 GB, 2199023255552 bytes
. P0 k4 R" _7 n( I, }16 heads, 63 sectors/track, 4260880 cylinders
2 ~. d# o8 K7 P. E/ w V: q1 gUnits = cylinders of 1008 * 512 = 516096 bytes
0 f: ~7 \# k+ J. y6 C4 dSector size (logical/physical): 512 bytes / 512 bytes7 X; G9 X* M7 `2 |
I/O size (minimum/optimal): 512 bytes / 512 bytes
6 b! Z) q3 e* c5 M9 a$ A6 JDisk identifier: 0x97b5a27a( S8 R" h# H C9 X; j
+ W% a0 y5 ? k, v. M7 V
Device Boot Start End Blocks Id System
5 V3 y. p9 N( J u% |+ H" p+ G/dev/vdb1 1 4260880 2147483488+ 83 Linux
?3 } R* o. B8 A2 }' @5 V+ a( R' ]) }: r3 c) K
8 L& L( |, U; q+ {7 l! `. k8 D0 f由上可以发现,根目录上挂载的是/dev/vda3 这个分区,而且这个系统里的分区id为83,因此不能通过LVM进行逻辑卷管理。
* |. i7 i' D. J! _7 M% u9 y
+ c. B8 c" J1 ]( L; Y[root@localhost ~]# lsblk
' j6 _' f. Y* e( z! eNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
; y! U+ d: i# |: L7 |sr0 11:0 1 1024M 0 rom + b- i! ~( I- D8 o
vda 252:0 0 40G 0 disk 4 z7 c+ c7 [' G: X1 i
├─vda1 252:1 0 200M 0 part /boot: ?# I/ _- n/ z& q. h
├─vda2 252:2 0 4G 0 part [SWAP]
% N3 x7 H. c k└─vda3 252:3 0 35.8G 0 part /+ h: T5 y- ?. |6 _$ A1 r
vdb 252:16 0 2T 0 disk 4 C' v$ t% ~- ~1 n Q5 z( F1 R
└─vdb1 252:17 0 2T 0 part /mnt/db1 - g* I ?1 j: L- t1 u! I
; X# |) C, I4 o) k; w- ]( B
5 |0 a% Q G) {: D& t
通过这个命令可以知道,vda确实是已经加了容量了,之前的vda只有40G的。
! y0 v6 u% f$ ^6 x
- D1 |$ e# Y4 Y0 L5 a8 n(1) 现在我们就要把加了的容量添加到vda3并同步到根目录的文件系统中。
! m6 N; y: l6 s/ Q0 c+ V5 v根据提示,先删除vda3根分区,然后重新创建vda3根分区" _1 @6 r# X( Z- s! r, Y# }
6 ^% O) |7 i- J4 _% G+ y9 z- R[root@localhost ~]# fdisk /dev/vda
6 R$ W6 R" h6 A( T5 m" TWelcome to fdisk (util-linux 2.23.2).
8 d" G8 a; R- d }$ `) M2 d! z
1 ^+ |# o: |5 u' m3 j% H I$ RChanges will remain in memory only, until you decide to write them.; q( `4 i5 s" r1 E X. ~
Be careful before using the write command.2 T" t5 @ O$ ]
2 G' ~1 U" J9 i" h( q/ _* `+ fCommand (m for help): p //这里输入p,列出分区列表,记住下面的start和end,后续操作才能保证数据不会丢失。
+ ?( G' i2 S$ L; i- s7 A- z
g+ K3 H4 ]6 d( S" wDisk /dev/sda: 51.5 GB, 51539607552 bytes, 100663296 sectors2 `0 L* q1 H7 b9 z' W
Units = sectors of 1 * 512 = 512 bytes
# |4 C3 t) Y4 b. y2 VSector size (logical/physical): 512 bytes / 512 bytes: e. F& h' ?( a
I/O size (minimum/optimal): 512 bytes / 512 bytes# @# Q( H1 B( K) b+ h3 j# B; t1 H
Disk label type: dos& c1 N5 s2 G1 J; J
Disk identifier: 0x000e780b& Y. }9 o# Q; B9 h
5 b- l+ w5 m$ I/ Y
Device Boot Start End Blocks Id System
r, K1 ?5 }2 e: [& U ^% k8 E/dev/vda1 * 3 409 204800 83 Linux1 j, @( E( r# ^% u
Partition 1 does not end on cylinder boundary.( u: j& i% _& a" m( J2 i B
/dev/vda2 409 8731 4194304 82 Linux swap / Solaris
+ b, R3 H3 n% q, r4 g5 fPartition 2 does not end on cylinder boundary.
/ h0 _# `. p+ {. A4 x/dev/vda3 8731 83221 37542912 83 Linux
7 |5 _4 S2 D0 z. i) \" m' F: a: w/ @9 d: X" a8 E& k
Command (m for help): d //这里输入d,表示删除一个分区# e+ `' t7 o% R& ^
Partition number (1-3, default 3): 3 //这里输入3,是因为之前的分区是/dev/sda36 n% ~9 q# ]; {# k2 K* ^: [# m# o/ m
Partition 3 is deleted2 T3 D5 N9 ?6 A7 ?' M& q
/ M6 d4 K* W9 U |! {, `& N
Command (m for help): n //删除完,输入n新建一个分区
) D. k1 I& x H* z, W) rPartition type:0 Z( _( b3 |) e1 m0 I) {0 \4 M
p primary (2 primary, 0 extended, 2 free)
2 R# U. V3 P/ q e extended
+ Y' ^+ A2 n- ?9 P0 G" |: U* BSelect (default p): p //选择主分区6 J+ H7 z) H; k. y. g6 c" F0 I
Partition number (3,4, default 3): 3 //还是/dev/sda3
+ a; ^4 |5 K# z; B- vFirst sector (3762176-100663295, default 3762176): //这里直接回车0 h- E! U: R& |* n
Using default value 3762176
1 ~' E! L5 c2 q N# D# h& C5 ULast sector, +sectors or +size{K,M,G} (3762176-100663295, default 100663295): //这里明显可以看到,不仅包含了之前的sda3的start和end,而且远大于了,使用默认的将剩余的空间都给这个新建的分区。" g: d8 d1 x" G- r
Using default value 100663295
# ^) w* g* }) \; BPartition 3 of type Linux and of size 46.2 GiB is set
G( j7 r7 }. A8 b+ W7 K4 p7 | r: ]( a0 B3 |9 A
Command (m for help): w //最后写入保存
6 O1 ?. N! @8 Y# D4 v7 _* q5 YThe partition table has been altered!, f( Z) C0 w0 g, O9 o: Y# g( R+ ?
3 U5 f9 d$ p3 Y, z% a2 h
Calling ioctl() to re-read partition table.8 c$ m; U5 e1 Y! [
& X% q1 ^2 a; t( `
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.( m- ~9 d! F; r! |
The kernel still uses the old table. The new table will be used at
1 g- t0 y. b5 w5 Uthe next reboot or after you run partprobe(8) or kpartx(8)
# t* m) V/ t5 y. d2 ySyncing disks.- `3 v. Z9 n7 u8 c4 v# T: e. G/ y
You have new mail in /var/spool/mail/root
* b! L; a8 j0 N" Z9 |
% Y& o' r5 w4 L; s(2)重启系统- s, v" {, @; J5 t0 L" ]
重启当前系统,可以选择 reboot 或者 init 6来执行。) |3 w. X. n6 `) ?" y! u: M* q
//先重启,必须
# y2 O% z6 g( i$ ~1 R- S1 V/ T% s8 H* ~' M- N! y
[root@localhost ~]# reboot
, g R" Q( A+ i% B6 z, e3 G; L/ g( A e* o& m [* J$ L) c( b/ N# u
(3)扩容文件系统* S" j' q7 b$ Q4 f, X% ?
我们使用一下命令查看vda3的文件格式: `# Y7 g6 P, I1 l
, b+ }: x& p2 Z/ C
[root@db-phis01 ~]# df -Th /dev/vda3
! J- i. }6 l0 P/ z8 M6 N. jFilesystem Type Size Used Avail Use% Mounted on
( ~) s2 @/ U: ?- N6 Z/ R/dev/vda3 ext4 36G 34G 16M 100% /9 T6 e& B, S# I
: x7 u: b6 ~' P& l) t, G2 T它的格式是ext4的,使用resize2fs命令,如果是xfs的,就要用xfs_growfs命令进行刷新文件系统容量 i6 X# V) o6 \6 H
2 x5 I, V4 \6 h; s- m" Y% N! ^[root@localhost ~]# resize2fs /dev/vda3+ S( }, r( L" E$ i
/ k1 }0 h9 a8 c1 L& h
然后我们再看根目录的大小:$ G4 Q* b1 Y/ R7 z) N
* f2 f: Z% F2 q- X* e[root@localhost ~]# df -hT! F' e0 u& j' Q( {
Filesystem Size Used Avail Use% Mounted on
2 P t1 J. g: n/dev/sda3 47G 13G 34G 27% / h, t0 X3 x6 `9 e O; o
devtmpfs 899M 0 899M 0% /dev6 q- r* h/ a; Z: w ` o7 F
tmpfs 913M 0 913M 0% /dev/shm
/ Y9 J1 ^ x1 S, {' T& btmpfs 913M 8.9M 904M 1% /run$ X k3 b2 Y: G' i: s: v, k& W
tmpfs 913M 0 913M 0% /sys/fs/cgroup
$ X: Z O7 y4 b: F: H, _( l/dev/sda1 297M 195M 103M 66% /boot7 t9 h# W; M' i: z/ y
tmpfs 183M 0 183M 0% /run/user/0: S( ^2 n( n K" q" q: T- N* Z
6 n( C( x7 v9 z
1 ?$ t w3 _8 \8 C j0 h/ o* A |
|