提示:Ubuntu Server大部分分区的缩减需要挂载到另一个Ubuntu。
一、Boot或EFI盘的扩容与缩减
挂载到另一个Ubuntu,使用工具gparted对Boot或EFI盘进行操作。
二、LVM逻辑盘扩张与缩减(LVM一般包括"根目录"与"swap"逻辑)
1、扩张
不需要挂载到另一个Ubuntu;详见:或
2、缩减(这里介绍最难的根分区的缩减)
挂载到另一个Ubuntu,再缩减分区
apt install lvm2
sudo pvs
#1.
root@ubuntu:/# apt install lvm2
正在读取软件包列表... 完成
。。。
将会同时安装下列软件:
dmeventd libaio1 libdevmapper-event1.02.1 liblvm2cmd2.03 libreadline5
thin-provisioning-tools
下列【新】软件包将被安装:
dmeventd libaio1 libdevmapper-event1.02.1 liblvm2cmd2.03 libreadline5 lvm2
thin-provisioning-tools
。。。
您希望继续执行吗? [Y/n] y
获取:1 http://mirrors.aliyun.com/ubuntu focal/main amd64 libdevmapper-event1.02.1 amd64 2:1.02.167-1ubuntu1 [11.9 kB]
。。。
正在处理用于 initramfs-tools (0.136ubuntu6.2) 的触发器 ...
update-initramfs: Generating /boot/initrd.img-5.4.0-42-generic
-----
#2.
root@ubuntu:/# sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 0
-----
#3.
root@ubuntu:/# sudo lvdisplay XiakeAdbServer-vg或
直接lvdisplay就行。
--- Logical volume ---
LV Path /dev/XiakeAdbServer-vg/root
LV Name root
VG Name XiakeAdbServer-vg
LV UUID VBfWqs-QHyx-4xT5-YwCk-rzxC-7BZK-5pmeKu
LV Write Access read/write
LV Creation host, time XiakeAdbServer, 2016-02-21 02:39:48 -0800
LV Status NOT available
LV Size 107.35 GiB
Current LE 27482
Segments 1
Allocation inherit
Read ahead sectors auto
--- Logical volume ---
LV Path /dev/XiakeAdbServer-vg/swap_1
LV Name swap_1
VG Name XiakeAdbServer-vg
LV UUID 8z2RRy-vsKL-ZUxN-KUq1-yCNj-9dM9-VA0fJm
LV Write Access read/write
LV Creation host, time XiakeAdbServer, 2016-02-21 02:39:48 -0800
LV Status NOT available
LV Size 3.66 GiB
Current LE 937
Segments 1
Allocation inherit
Read ahead sectors auto
-----
#4.
root@ubuntu:/#
1 sudo mkdir /home/cdrom
2 sudo mount /dev/XiakeAdbServer-vg/root /home/cdrom
mount /home/root1/cdrom: 特殊设备 /dev/XiakeAdbServer-vg/root 不存在.
(我怎么挂上他的lv盘)
fdisk -l
设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/sdb1 2048 1101037 1098990 536.6M b W95 FAT32
/dev/sdb2 1101824 1601535 499712 244M 1 FAT12
/dev/sdb3 1603584 234418175 232814592 111G 1 FAT12
root@ubuntu:/# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 55M 1 loop /snap/core18/1880
loop1 7:1 0 255.6M 1 loop /snap/gnome-3-34-1804/36
loop2 7:2 0 49.8M 1 loop /snap/snap-store/467
loop3 7:3 0 62.1M 1 loop /snap/gtk-common-themes/1506
loop4 7:4 0 29.9M 1 loop /snap/snapd/8542
loop5 7:5 0 55.4M 1 loop /snap/core18/1944
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 19.5G 0 part /
sdb 8:16 0 121G 0 disk
├─sdb1 8:17 0 536.6M 0 part
├─sdb2 8:18 0 244M 0 part
└─sdb3 8:19 0 111G 0 part
sr0 11:0 1 1024M 0 rom
-----
root@ubuntu:/# find / -name XiakeAdbServer-vg
/etc/lvm/backup/XiakeAdbServer-vg
find: ‘/run/user/1000/doc’: 权限不够
find: ‘/run/user/1000/gvfs’: 权限不够
-----
root@zhang-MS-7B79:/etc# vgchange -a y XiakeAdbServer-vg
2 logical volume(s) in volume group "XiakeAdbServer-vg" now active
-----
root@zhang-MS-7B79:/etc# find / -name XiakeAdbServer-vg
find: ‘/run/user/1000/doc’: 权限不够
find: ‘/run/user/1000/gvfs’: 权限不够
/run/lvm/vgs_online/XiakeAdbServer-vg
/dev/XiakeAdbServer-vg
/etc/lvm/backup/XiakeAdbServer-vg
-----
sudo mount /dev/XiakeAdbServer-vg/root /home/cdrom
-----
确认加载正常
root@ubuntu:/home/cdrom# ls
bin data etc lib lost+found mnt opt root sbin sys usr
boot dev home lib64 media nohup.out proc run srv tmp var
-----
6.确认硬盘信息
root@ubuntu:/home/cdrom# df -h
文件系统 容量 已用 可用 已用% 挂载点
udev 1.9G 0 1.9G 0% /dev
tmpfs 391M 1.9M 389M 1% /run
/dev/sda5 20G 7.4G 11G 41% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/loop0 55M 55M 0 100% /snap/core18/1880
/dev/loop1 256M 256M 0 100% /snap/gnome-3-34-1804/36
/dev/loop2 50M 50M 0 100% /snap/snap-store/467
/dev/loop3 63M 63M 0 100% /snap/gtk-common-themes/1506
/dev/loop4 30M 30M 0 100% /snap/snapd/8542
/dev/sda1 511M 4.0K 511M 1% /boot/efi
tmpfs 391M 44K 391M 1% /run/user/1000
/dev/loop5 56M 56M 0 100% /snap/core18/1944
/dev/mapper/XiakeAdbServer--vg-root 106G 1.8G 99G 2% /home/cdrom
7.卸载/home/cdrom(root用户下)
sudo umount /home/cdrom
umount target is busy对策:
终止占用进程
root@ubuntu:/home/cdrom# fuser -mv /home/cdrom
用户 进程号 权限 命令
/home/cdrom: root kernel mount /home/cdrom
root 3921 ..c.. bash
kill -9 3921
-----
8.检查文件系统( e2fsck )
root@ubuntu:/home/root1# e2fsck -f /dev/mapper/XiakeAdbServer--vg-root
e2fsck 1.45.5 (07-Jan-2020)
第 1 步:检查inode、块和大小
第 2 步:检查目录结构
第 3 步:检查目录连接性
第 4 步:检查引用计数
第 5 步:检查组概要信息
/dev/mapper/XiakeAdbServer--vg-root:69604/7036928 文件(0.2% 为非连续的), 945517/28141568 块
-----
9.缩小文件系统 ( resize2fs )
resize2fs -p /dev/mapper/XiakeAdbServer--vg-root 4G(打印已完成的百分比进度条)或者
resize2fs -f /dev/mapper/XiakeAdbServer--vg-root 4G(强制执行)
root@ubuntu:/home/root1# resize2fs -p /dev/mapper/XiakeAdbServer--vg-root 4G
resize2fs 1.45.5 (07-Jan-2020)
将 /dev/mapper/XiakeAdbServer--vg-root 上的文件系统调整为 1048576 个块(每块 4k)。
开始第 2 步(共 192630 步)
正在重定位块 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
开始第 3 步(共 859 步)
正在扫描inode表 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
开始第 4 步(共 10332 步)
正在更新inode引用 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/dev/mapper/XiakeAdbServer--vg-root 上的文件系统现在为 1048576 个块(每块 4k)。
-----
10.缩小LV大小( lvreduce )
lvreduce -L 4G /dev/mapper/XiakeAdbServer--vg-root
root@ubuntu:/home/root1# lvreduce -L 4G /dev/mapper/XiakeAdbServer--vg-root
WARNING: Reducing active logical volume to 4.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce XiakeAdbServer-vg/root? [y/n]: y
Size of logical volume XiakeAdbServer-vg/root changed from 107.35 GiB (27482 extents) to 4.00 GiB (1024 extents).
Logical volume XiakeAdbServer-vg/root successfully resized.
11.查看当前 LV 大小-lvs
root@ubuntu:/home/root1# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root XiakeAdbServer-vg -wi-a----- 4.00g
swap_1 XiakeAdbServer-vg -wi-a----- 3.66g
12. 重新挂载文件系统,查看
sudo mount /dev/XiakeAdbServer-vg/root /home/cdrom
df -h
oot@ubuntu:/home/root1# df -h
文件系统 容量 已用 可用 已用% 挂载点
udev 1.9G 0 1.9G 0% /dev
tmpfs 391M 1.9M 389M 1% /run
/dev/sda5 20G 7.4G 11G 41% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/loop0 55M 55M 0 100% /snap/core18/1880
/dev/loop1 256M 256M 0 100% /snap/gnome-3-34-1804/36
/dev/loop2 50M 50M 0 100% /snap/snap-store/467
/dev/loop3 63M 63M 0 100% /snap/gtk-common-themes/1506
/dev/loop4 30M 30M 0 100% /snap/snapd/8542
/dev/sda1 511M 4.0K 511M 1% /boot/efi
tmpfs 391M 48K 391M 1% /run/user/1000
/dev/loop5 56M 56M 0 100% /snap/core18/1944
/dev/mapper/XiakeAdbServer--vg-root 3.9G 1.8G 1.9G 50% /home/cdrom
root@ubuntu:/home/root1# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 55M 1 loop /snap/core18/1880
loop1 7:1 0 255.6M 1 loop /snap/gnome-3-34-1804/36
loop2 7:2 0 49.8M 1 loop /snap/snap-store/467
loop3 7:3 0 62.1M 1 loop /snap/gtk-common-themes/1506
loop4 7:4 0 29.9M 1 loop /snap/snapd/8542
loop5 7:5 0 55.4M 1 loop /snap/core18/1944
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 19.5G 0 part /
sdb 8:16 0 121G 0 disk
├─sdb1 8:17 0 536.6M 0 part
├─sdb2 8:18 0 244M 0 part
└─sdb3 8:19 0 111G 0 part
├─XiakeAdbServer--vg-root
│ 253:0 0 4G 0 lvm /home/cdrom
└─XiakeAdbServer--vg-swap_1
253:1 0 3.7G 0 lvm
sr0 11:0 1 1024M 0 rom
13.卸载 XiakeAdbServer--vg-root
sudo umount /home/cdrom
- 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.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
- 111.
- 112.
- 113.
- 114.
- 115.
- 116.
- 117.
- 118.
- 119.
- 120.
- 121.
- 122.
- 123.
- 124.
- 125.
- 126.
- 127.
- 128.
- 129.
- 130.
- 131.
- 132.
- 133.
- 134.
- 135.
- 136.
- 137.
- 138.
- 139.
- 140.
- 141.
- 142.
- 143.
- 144.
- 145.
- 146.
- 147.
- 148.
- 149.
- 150.
- 151.
- 152.
- 153.
- 154.
- 155.
- 156.
- 157.
- 158.
- 159.
- 160.
- 161.
- 162.
- 163.
- 164.
- 165.
- 166.
- 167.
- 168.
- 169.
- 170.
- 171.
- 172.
- 173.
- 174.
- 175.
- 176.
- 177.
- 178.
- 179.
- 180.
- 181.
- 182.
- 183.
- 184.
- 185.
- 186.
- 187.
- 188.
- 189.
- 190.
- 191.
- 192.
- 193.
- 194.
- 195.
- 196.
- 197.
- 198.
- 199.
- 200.
- 201.
- 202.
- 203.
- 204.
- 205.
- 206.
- 207.
- 208.
- 209.
- 210.
- 211.
- 212.
- 213.
- 214.
- 215.
- 216.
- 217.
- 218.
- 219.
- 220.
- 221.
- 222.
- 223.
- 224.
- 225.
14.调整物理分区
1)安装sudo apt-get install gparted
,调整物理分区
2)拖动调整后,报错:
错误信息:cannot resize to 1962 extents as later ones are allocated.
说明我们去掉的分区里有数据
root@ubuntu:/home/root1# sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g
root@ubuntu:/home/root1# sudo pvs -v --segments /dev/sdb3
PV VG Fmt Attr PSize PFree Start SSize LV Start Type PE Ranges
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g 0 1024 root 0 linear /dev/sdb3:0-1023
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g 1024 26458 0 free
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g 27482 937 swap_1 0 linear /dev/sdb3:27482-28418
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
可以看出:free空闲分区在root与swap_1之间,我们需要swap_1移到前面去:
sudo pvmove --alloc anywhere /dev/sdb3:27482-28418
等半分钟,sudo pvs -v --segments /dev/sdb3
如果是下面的情况
oot@ubuntu:/home/root1# sudo pvs -v --segments /dev/sdb3
PV VG Fmt Attr PSize PFree Start SSize LV Start Type PE Ranges
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 99.69g 0 1024 root 0 linear /dev/sdb3:0-1023
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 99.69g 1024 937 [pvmove0] 0 mirror /dev/sdb3:27482-28418 /dev/sdb3:1024-1960
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 99.69g 1961 25521 0 free
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 99.69g 27482 937 [pvmove0] 0 mirror /dev/sdb3:27482-28418 /dev/sdb3:1024-1960
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
找不到swap_1,但是出现了两个[pvmove0]的盘,说明还在移动。当出现:
root@ubuntu:/home/root1# sudo pvs -v --segments /dev/sdb3
PV VG Fmt Attr PSize PFree Start SSize LV Start Type PE Ranges
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g 0 1024 root 0 linear /dev/sdb3:0-1023
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g 1024 937 swap_1 0 linear /dev/sdb3:1024-1960
/dev/sdb3 XiakeAdbServer-vg lvm2 a-- 111.01g 103.35g 1961 26458 0 free
- 1.
- 2.
- 3.
- 4.
- 5.
说明移动完成。
3)再次执行‘1)’
4)完成
三、参照:
https://jingyan.baidu.com/article/eb9f7b6d801daf869364e83a.html
等文章
四、补充:
原
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-27-generic x86_64)
启动项root@XServer:~# sudo ls -al /sbin | grep init
-rwxr-xr-x 1 root root 265848 7月 18 2014 init
-rwxr-xr-x 1 root root 193512 7月 18 2014 initctl
lrwxrwxrwx 1 root root 7 7月 18 2014 reload -> initctl
lrwxrwxrwx 1 root root 7 7月 18 2014 restart -> initctl
lrwxrwxrwx 1 root root 7 7月 18 2014 start -> initctl
lrwxrwxrwx 1 root root 7 7月 18 2014 status -> initctl
lrwxrwxrwx 1 root root 7 7月 18 2014 stop -> initctl
-rwxr-xr-x 1 root root 104728 7月 18 2014 telinit
硬盘:
fd -h
udev 1.9G 4.0K 1.9G 1% /dev
tmpfs 383M 648K 382M 1% /run
/dev/dm-0 106G 2.3G 98G 3% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 4.0K 1.9G 1% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda2 237M 49M 177M 22% /boot
/dev/sda1 536M 3.4M 533M 1% /boot/efi
- 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.
作者:꧁执笔小白꧂