|
|
楼主 |
发表于 2022-9-27 17:33:54
|
显示全部楼层
使用xshell登录虚拟机,按以下步骤执行:' v: b, B3 w. y
, g9 T7 Y3 k) H& X: D1 W[root@localhost ~]# df -hT, h# J9 E" \% g
Filesystem Type Size Used Avail Use% Mounted on$ {) U* ]8 a) q6 X
/dev/vda3 ext4 36G 34G 16M 100% /
- [' C. g2 Z! ^. O! M! C2 z4 Ttmpfs tmpfs 99G 23G 77G 23% /dev/shm2 D4 \* V2 Y n( V' S
/dev/vda1 ext4 190M 39M 141M 22% /boot
$ [& v1 I- |4 [, E9 a+ L/dev/vdb1 ext4 2.0T 1.7T 244G 88% /mnt/db10 S- c5 Y' ~( R1 s0 T$ \3 c4 ~: C. E/ y
6 p. j0 Y1 @2 _[root@localhost ~]# fdisk -l
" p( s/ S* t( e2 O" o% U. eDisk /dev/vda: 42.9 GB, 42949672960 bytes
5 Q. z- g8 e. W- {' `16 heads, 63 sectors/track, 83220 cylinders
, b4 @8 Y$ l9 L: B7 w9 r0 tUnits = cylinders of 1008 * 512 = 516096 bytes5 e" ?" Z5 S; p0 Y" n7 [. o' T
Sector size (logical/physical): 512 bytes / 512 bytes
% X6 u0 G" Z# v- [' S/ VI/O size (minimum/optimal): 512 bytes / 512 bytes; ^4 p* u6 b2 l9 B* g4 p B
Disk identifier: 0x0008e937
$ ~4 ]+ \) J* C) u* n
- f1 Y! k# z+ \. Q Device Boot Start End Blocks Id System {$ T% `/ x9 C- E+ F# H0 B
/dev/vda1 * 3 409 204800 83 Linux
* S7 p& O7 l/ w0 X6 E9 bPartition 1 does not end on cylinder boundary.
\& n9 Y& n4 Q3 }1 ]' [0 E- i% U/dev/vda2 409 8731 4194304 82 Linux swap / Solaris7 U! Q% L# Q( w2 G
Partition 2 does not end on cylinder boundary.
, N# ~$ u$ ?1 Q/dev/vda3 8731 83221 37542912 83 Linux& S" R& t5 U7 w: ?# H
Partition 3 does not end on cylinder boundary.
9 t& L" L0 g4 I9 ?9 E" g$ L& J( W+ X
& r0 K( u& W1 {% w) X- j! gDisk /dev/vdb: 2199.0 GB, 2199023255552 bytes
8 Z" g5 t9 q- _6 r& b2 r4 ~16 heads, 63 sectors/track, 4260880 cylinders. J% k8 W' y+ e. S
Units = cylinders of 1008 * 512 = 516096 bytes4 V9 @& u4 M9 U! b
Sector size (logical/physical): 512 bytes / 512 bytes
0 q7 H a; `* K1 aI/O size (minimum/optimal): 512 bytes / 512 bytes3 h+ @' E/ A2 F3 a1 \
Disk identifier: 0x97b5a27a7 d( z8 B: G3 m n4 r6 A% K* B
) H5 H0 P T+ P% c' Z! _- @ Device Boot Start End Blocks Id System
; j* X$ r' p! h: n6 I/dev/vdb1 1 4260880 2147483488+ 83 Linux. Z8 x5 C* a/ u) J
" U/ f6 S4 K1 B
* F6 b" b# F* v8 D由上可以发现,根目录上挂载的是/dev/vda3 这个分区,而且这个系统里的分区id为83,因此不能通过LVM进行逻辑卷管理。
- c, c2 h _: [ }% t, A+ S3 j
: j1 G! D, T- L# B. F- w7 o$ B[root@localhost ~]# lsblk
3 B4 { C3 Z$ B; k6 z: vNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT X l; _9 A8 R& ?
sr0 11:0 1 1024M 0 rom
" q* I" a9 |" X% p6 ~. ivda 252:0 0 40G 0 disk
+ x4 s _& E! o# e( R+ ~├─vda1 252:1 0 200M 0 part /boot
+ Y C, A, L% C" V) l* Z$ [├─vda2 252:2 0 4G 0 part [SWAP]
) k; @' v$ K* W* ]└─vda3 252:3 0 35.8G 0 part /5 ]& J$ ^$ i9 u" Y, I3 _
vdb 252:16 0 2T 0 disk
- E; s; l4 ]; {9 j+ l& c6 q└─vdb1 252:17 0 2T 0 part /mnt/db1
/ r `4 H' g8 y; }7 Y. K# M9 |: Z5 l3 w( {' m5 G
/ f5 |6 L7 s% z9 o1 F
通过这个命令可以知道,vda确实是已经加了容量了,之前的vda只有40G的。: j9 d( H1 r/ v! k' i
' X8 c6 N( }5 q) l+ `& P `(1) 现在我们就要把加了的容量添加到vda3并同步到根目录的文件系统中。
: \& @7 |# O. p0 p1 g根据提示,先删除vda3根分区,然后重新创建vda3根分区, H% Q& O4 v6 G4 i3 N
: X1 ` [( f, W+ H[root@localhost ~]# fdisk /dev/vda, A1 R0 z. x `. N, h
Welcome to fdisk (util-linux 2.23.2).! I J2 M: S" y0 N0 b9 _4 l! c2 r
8 y& i* c# S3 [: w- c* d
Changes will remain in memory only, until you decide to write them.
* H }1 P2 a# `4 @& xBe careful before using the write command.2 B) o+ c/ U; u: E7 Y* [: |2 y
) M; P/ Y. x# v7 p v4 J: g2 kCommand (m for help): p //这里输入p,列出分区列表,记住下面的start和end,后续操作才能保证数据不会丢失。6 F7 h6 x# @" l; t' n9 Q* O8 D& q
3 G; i5 a' A, M7 ^4 k4 R
Disk /dev/sda: 51.5 GB, 51539607552 bytes, 100663296 sectors
M* r. R- q% G" ^Units = sectors of 1 * 512 = 512 bytes
G& [% A% n# M9 N4 ESector size (logical/physical): 512 bytes / 512 bytes# W7 q( M! [! E* E
I/O size (minimum/optimal): 512 bytes / 512 bytes
6 Y: T( g) R! t7 i( x1 K/ n& [( zDisk label type: dos2 _9 F' ?' ]- {: T1 c( l
Disk identifier: 0x000e780b: n% d8 o. K c0 f7 ~5 @
" D! _7 P$ G9 N# E5 t% D# s
Device Boot Start End Blocks Id System
$ A' c+ m/ ~3 t; v- q/dev/vda1 * 3 409 204800 83 Linux
, c9 x+ i& J7 j' y# IPartition 1 does not end on cylinder boundary.
0 d* x8 G2 @/ d' O6 l8 P& f1 \/dev/vda2 409 8731 4194304 82 Linux swap / Solaris& t2 m; E7 N2 S3 a' E
Partition 2 does not end on cylinder boundary.( S" _: L9 a1 x: L
/dev/vda3 8731 83221 37542912 83 Linux
) S+ N: v0 c: S1 E: s" l" c( f0 ~, @ _! e+ j, c) W
Command (m for help): d //这里输入d,表示删除一个分区$ u* a. t9 S# J% a
Partition number (1-3, default 3): 3 //这里输入3,是因为之前的分区是/dev/sda3
y$ ?: J$ H% Z1 d: R5 W% ?Partition 3 is deleted
7 K9 [3 o4 X% \' \" r2 g7 u/ M+ W8 u& E! h3 b* M
Command (m for help): n //删除完,输入n新建一个分区
' c1 i1 P# @/ N/ ]- UPartition type:7 e0 ~: R6 j) C) y- u. @: r. F& I
p primary (2 primary, 0 extended, 2 free), J% L# {1 P3 Y7 b ]
e extended
5 z" X- ~" Z" u6 m/ ?Select (default p): p //选择主分区9 G% Q( a1 ^/ a. ]9 k9 X
Partition number (3,4, default 3): 3 //还是/dev/sda3( [" |& f6 q! `
First sector (3762176-100663295, default 3762176): //这里直接回车0 M8 c* l- V. z* d/ z6 Z
Using default value 3762176 9 |4 W/ s; l% D7 d6 @
Last sector, +sectors or +size{K,M,G} (3762176-100663295, default 100663295): //这里明显可以看到,不仅包含了之前的sda3的start和end,而且远大于了,使用默认的将剩余的空间都给这个新建的分区。
+ G: ~$ ~, q* q6 W6 m: E nUsing default value 1006632951 N. [7 u7 n& g" w5 B( j- p
Partition 3 of type Linux and of size 46.2 GiB is set
% Z6 |3 f+ ^* S! t! r; G2 ~/ y5 l' ^, e y0 V9 m3 J" d
Command (m for help): w //最后写入保存
+ U7 P' f7 [* v# zThe partition table has been altered!
( g5 F0 H- j. h6 w" z- [0 }: h$ N, ]! O# L
Calling ioctl() to re-read partition table.4 c, F* C. G5 Y/ e4 E4 S/ V
B$ y' V9 y5 r$ R* n" [8 l5 U
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
1 U8 z6 s3 g# TThe kernel still uses the old table. The new table will be used at
5 b/ k4 H3 P0 _5 R. Ethe next reboot or after you run partprobe(8) or kpartx(8)* f5 f B% m9 ?* |8 e. A, J9 d
Syncing disks.
2 ~2 }- b- n2 c4 }7 K q# jYou have new mail in /var/spool/mail/root
+ B; p! J% ~8 D7 {$ j* W: z- a4 n) B0 _) X# [
(2)重启系统$ h1 ?1 z- D6 J3 f& T) D: @
重启当前系统,可以选择 reboot 或者 init 6来执行。* E9 Y3 p5 @9 e) |) C% T
//先重启,必须
3 }( z2 i5 n1 I" V5 u
8 F( I$ f" o; Q5 {9 b3 h[root@localhost ~]# reboot
+ f% r$ d+ K3 b" P0 t4 u3 g; _6 V+ x) p* z2 z3 d3 o, c" P* {& I3 k
(3)扩容文件系统8 O; \9 Q& w8 m; ^& d4 P& f6 V
我们使用一下命令查看vda3的文件格式:
' w( q" m) r7 t2 m
5 e7 u) T0 h& m[root@db-phis01 ~]# df -Th /dev/vda3
$ r# M5 X8 G/ Z* l( H$ Z- GFilesystem Type Size Used Avail Use% Mounted on
; b9 C+ O& Y/ D! F/dev/vda3 ext4 36G 34G 16M 100% /
: Z' K% ^* y! ^6 A+ f; l" e, b4 [6 ]
它的格式是ext4的,使用resize2fs命令,如果是xfs的,就要用xfs_growfs命令进行刷新文件系统容量; K9 \8 t$ _& L8 N$ t3 p
) T' _" M% u! i m: l' a[root@localhost ~]# resize2fs /dev/vda3' _! m3 c( x+ y3 { n1 P
) j. i. n* a0 H; a7 ~
然后我们再看根目录的大小:
2 t. O, n2 n6 D) m) g% ]6 Y: e% u1 q! |5 d
[root@localhost ~]# df -hT5 N+ G$ H! d9 ?+ N/ D+ `
Filesystem Size Used Avail Use% Mounted on
M- A; ^, p+ R# V* L/dev/sda3 47G 13G 34G 27% /
! P& J0 F' z, c4 _5 b) R* Q8 _: tdevtmpfs 899M 0 899M 0% /dev
+ j+ _8 K1 C' b( M# o, i; Y. \9 Ytmpfs 913M 0 913M 0% /dev/shm
, ~! ]! F1 w3 J8 O% gtmpfs 913M 8.9M 904M 1% /run' k4 C4 o2 L9 ~% a* X
tmpfs 913M 0 913M 0% /sys/fs/cgroup, T: C4 O( P3 t- I# `% p) l6 v% e" m
/dev/sda1 297M 195M 103M 66% /boot
2 V8 |) Z0 t/ ?! g# Vtmpfs 183M 0 183M 0% /run/user/0+ T8 p, s$ {6 O8 Y4 u7 {, p/ O" _
" O; ^* j" e8 |5 M# ]" T- p# n1 {% z I
|
|