激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

Linux|Centos|Ubuntu|系統進程|Fedora|注冊表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服務器之家 - 服務器系統 - Ubuntu - Ubuntu系統下擴展LVM根目錄的方法

Ubuntu系統下擴展LVM根目錄的方法

2022-03-09 17:02洋子 Ubuntu

這篇文章主要給大家介紹了關于Ubuntu系統下擴展LVM根目錄的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧

前言

最近手頭一臺運行在 Hyper-V 下面抓數據的服務器 (Ubuntu 16.04) 磁盤空間不夠了,之前也沒有把數據單獨放到一個分區,所以只能想辦法把根目錄給搞大一點。之前沒有處理過這樣的問題,網上搜了很多資料,現在把拓展方法記錄,分享出來。

建議在操作之前做好備份工作

步驟概覽

  1. 調大物理磁盤
  2. 確定要操作的磁盤
  3. 擴展 LVM 邏輯分區所在的物理拓展分區
  4. 新增 LVM 邏輯分區
  5. 新分區合并到相應 Volumn Group
  6. 更新文件系統

調大物理磁盤

虛擬機關機,然后直接在虛擬機管理里面操作。

Ubuntu系統下擴展LVM根目錄的方法

現在把磁盤從 100G 調整到了 300G

確定要操作的磁盤

先看下磁盤使用情況,運行命令

?
1
2
3
4
5
6
7
8
9
10
11
root@vm003:~# df -h
Filesystem  Size Used Avail Use% Mounted on
udev   3.9G 0 3.9G 0% /dev
tmpfs   798M 8.6M 789M 2% /run
/dev/mapper/Ubuntu-root 94G 88G 1.9G 98% /
tmpfs   3.9G 0 3.9G 0% /dev/shm
tmpfs   5.0M 0 5.0M 0% /run/lock
tmpfs   3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1  472M 382M 66M 86% /boot
tmpfs   100K 0 100K 0% /run/lxcfs/controllers
tmpfs   798M 0 798M 0% /run/user/0

雖然我們已經把物理磁盤調整到了 300G,但是根目錄還是100G的樣子,已用 98%

運行命令

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
root@vm003:~# fdisk -l
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xa88f1366
 
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 209713151 208711682 99.5G 5 Extended
/dev/sda5 1001472 209713151 208711680 99.5G 8e Linux LVM
 
Partition 2 does not start on physical sector boundary.
 
 
Disk /dev/mapper/Ubuntu-root: 95.5 GiB, 102563315712 bytes, 200318976 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
 
 
Disk /dev/mapper/Ubuntu-swap_1: 4 GiB, 4294967296 bytes, 8388608 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

可以看到 /dev/sda 已經確實被調整到了300GiB,只是系統還沒用到。

也知道了我們要操作 /dev/sda

擴大 LVM 邏輯分區所在的物理分區

運行命令

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
root@vm003:~# parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print # 查看分區
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 322GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
 
Number Start End Size Type File system Flags
 1 1049kB 512MB 511MB primary ext2  boot
 2 513MB 107GB 107GB extended
 5 513MB 107GB 107GB logical  lvm
 
(parted) resizepart 2 # 調整 sda2 分區大小
End? [107GB]? -0 # 直接充滿
(parted) print # 再次查看
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 322GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
 
Number Start End Size Type File system Flags
 1 1049kB 512MB 511MB primary ext2  boot
 2 513MB 322GB 322GB extended
 5 513MB 107GB 107GB logical  lvm
 
(parted) q # 完成退出
Information: You may need to update /etc/fstab.

現在我們已經把 /dev/sda2 給拓展出來了

新增 LVM 邏輯分區

運行命令

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
root@vm003:~# fdisk /dev/sda
 
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
 
Command (m for help): p # 查看現在的分區情況
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xa88f1366
 
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 629145599 628144130 299.5G 5 Extended
/dev/sda5 1001472 209713151 208711680 99.5G 8e Linux LVM
 
Partition 2 does not start on physical sector boundary.
 
Command (m for help): n # 新增分區,選擇邏輯分區,起止點看情況輸入,默認值是填充滿整個磁盤
 
All space for primary partitions is in use.
Adding logical partition 6
First sector (209715200-629145599, default 209715200):
Last sector, +sectors or +size{K,M,G,T,P} (209715200-629145599, default 629145599):
 
Created a new partition 6 of type 'Linux' and of size 200 GiB.
 
Command (m for help): p # 查看新增的分區
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xa88f1366
 
Device Boot Start End Sectors Size Id Type
/dev/sda1 *  2048 999423 997376 487M 83 Linux
/dev/sda2  1001470 629145599 628144130 299.5G 5 Extended
/dev/sda5  1001472 209713151 208711680 99.5G 8e Linux LVM
/dev/sda6 209715200 629145599 419430400 200G 83 Linux
 
Partition 2 does not start on physical sector boundary.
 
Command (m for help): t # 改變分區類型為 Linux LVM
Partition number (1,2,5,6, default 6): 6 # sda6
Partition type (type L to list all types): 8e # LVM 類型的 Id 代碼
 
Changed type of partition 'Linux' to 'Linux LVM'.
 
Command (m for help): p # 再次查看分區情況
Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xa88f1366
 
Device Boot Start End Sectors Size Id Type
/dev/sda1 *  2048 999423 997376 487M 83 Linux
/dev/sda2  1001470 629145599 628144130 299.5G 5 Extended
/dev/sda5  1001472 209713151 208711680 99.5G 8e Linux LVM
/dev/sda6 209715200 629145599 419430400 200G 8e Linux LVM
 
Partition 2 does not start on physical sector boundary.
 
Command (m for help): wq # 確認沒有問題,保存退出
 
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
 
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).

新分區合并到相應 Volumn Group

運行命令

?
1
2
3
4
5
root@vm003:~# vgdisplay
 --- Volume group ---
 VG Name  Ubuntu
 System ID
 Format  lvm2

可以看出我們要操作的VG Name 為 Ubuntu,記錄下來。

接著運行命令

?
1
2
3
root@vm003:~# vgextend Ubuntu /dev/sda6 # /dev/sda6 是剛剛增加的 LVM 分區
 Device /dev/sda6 not found (or ignored by filtering).
 Unable to add physical volume '/dev/sda6' to volume group 'Ubuntu'.

呃,,,提示沒有找到 /dev/sda6 這個設備,還是重啟一下好了。

?
1
root@vm003:~# reboot

重啟后再次執行

?
1
2
3
root@vm003:~# vgextend Ubuntu /dev/sda6 # /dev/sda6 是剛剛增加的 LVM 分區
 Physical volume "/dev/sda6" successfully created
 Volume group "Ubuntu" successfully extended

再查看一下 Volumn Group 的狀態,運行命令

?
1
2
3
root@vm003:~# vgs
 VG #PV #LV #SN Attr VSize VFree
 Ubuntu 2 2 0 wz--n- 299.52g 200.00g

確實加進去了。

然后運行

?
1
2
3
4
5
root@vm003:~# lvdisplay
 --- Logical volume ---
 LV Path  /dev/Ubuntu/root
 LV Name  root
 VG Name  Ubuntu

我們知道了 Ubuntu VG 的 LV Path 是 /dev/Ubuntu/root,記錄下來。

然后運行

?
1
2
3
root@vm003:~# lvresize -l +100%FREE /dev/Ubuntu/root # /dev/Ubuntu/root 是 LV Path
 Size of logical volume Ubuntu/root changed from 95.52 GiB (24453 extents) to 295.52 GiB (75652 extents).
 Logical volume root successfully resized.

這就成功啦。

警告: 如果操作時出現下面這樣的 warning,就說明現在 logic volumn 的總大小還不對,resize 不但不增加空間,反而在縮小空間,如果繼續操作下去,必將丟失數據。應立即停止!按 n 取消。

WARNING: Reducing active and open logical volume to 32.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce root? [y/n]*

更新文件系統

最后一步,運行命令

?
1
2
3
4
5
6
root@vm003:~# resize2fs -p /dev/mapper/Ubuntu-root # /dev/mapper/Ubuntu-root 是從 df 命令看到的文件系統信息
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/Ubuntu-root is mounted on /; on-line resizing required
old_desc_blocks = 6, new_desc_blocks = 19
 
The filesystem on /dev/mapper/Ubuntu-root is now 77467648 (4k) blocks long.

這個過程可能會花幾分鐘時間,耐心等待就好了。

然后運行 df 命令查看磁盤使用

?
1
2
3
4
5
6
7
8
9
10
11
root@vm003:~# df -h
Filesystem  Size Used Avail Use% Mounted on
udev   3.9G 0 3.9G 0% /dev
tmpfs   798M 8.6M 789M 2% /run
/dev/mapper/Ubuntu-root 291G 88G 191G 32% /
tmpfs   3.9G 0 3.9G 0% /dev/shm
tmpfs   5.0M 0 5.0M 0% /run/lock
tmpfs   3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1  472M 382M 66M 86% /boot
tmpfs   100K 0 100K 0% /run/lxcfs/controllers
tmpfs   798M 0 798M 0% /run/user/0

大功告成!

參考:

http://www.zmynmublwnt.cn/article/230466.html

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。

原文鏈接:https://juejin.im/post/5aed09c46fb9a07a9f016dd9

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 蜜桃麻豆视频 | 国产亚洲精品久久 | 日本一区二区不卡在线 | 毛片a区| 法国极品成人h版 | 亚洲性夜色噜噜噜7777 | 国产女厕所 | 伊人午夜视频 | 亚洲国产精品99 | 亚洲操比视频 | 亚洲视频在线网 | 国产99久久精品 | av电影直播| 欧美顶级毛片在线播放小说 | 深夜小视频在线观看 | 久久久线视频 | 精品国产高清一区二区三区 | 中文字幕在线成人 | 成人午夜免费看 | 国产视频精品在线 | 久久久www成人免费精品 | 91精品国产777在线观看 | 亚洲精品tv久久久久久久久久 | 免费a级网站 | 亚洲二区不卡 | 午夜在线小视频 | 日韩黄色免费观看 | 久久久一区二区三区视频 | 99精品视频在线免费观看 | 中文字幕 亚洲一区 | 成人国产精品久久久 | 亚州综合图片 | 精品一二三区视频 | 黄色网在线播放 | hd日本xxxx| 久草在线综合 | 国产精品伦视频看免费三 | 国产一国产一级毛片视频 | 成人一级在线 | 精品视频 久久久 | 国产日韩a|