1、申请公网IP
2、光猫设置桥接模式
3、设置地址转换(路由器当网关,公网代理到内网)
4、下载ubuntu镜像,清华大学源
5、通过UltraISO制作启动盘
ubuntu首次进入设置root用户密码
sudo passwd root
概念
新增硬盘进行分区
在虚拟机上新增一块5G的硬盘,通过fdisk -l发现未分区
注意,对于比较大的硬盘要使用GPT分区表格式,具体操作如下
root@wxserver:~ ============= fdisk /dev/sdb #对磁盘/dev/sdb进行分区
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x2785301c.
Command (m for help): ============= n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): ============ p
Partition number (1-4, default 1): ==============
First sector (2048-10485759, default 2048): ===================
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759):
Created a new partition 1 of type 'Linux' and of size 5 GiB.
Command (m for help): =================== wp
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@wxserver:~ ================ pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 18.22 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4665
Free PE 0
Allocated PE 4665
PV UUID eA30ga-5pez-3qLl-jjJJ-9zy5-ZFPz-PXGp6A
root@wxserver:~ ================== pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
root@wxserver:~ ===================== pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 18.22 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4665
Free PE 0
Allocated PE 4665
PV UUID eA30ga-5pez-3qLl-jjJJ-9zy5-ZFPz-PXGp6A
"/dev/sdb1" is a new physical volume of "<10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID yntEDg-zNsQ-rB1E-7Uxt-zBxP-ep8N-GNGiru
root@wxserver:~ ==================== pvresize /dev/sdb1
Physical volume "/dev/sdb1" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
root@wxserver:~ ========================== vgdisplay 查看vg名称
--- Volume group ---
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 18.22 GiB
PE Size 4.00 MiB
Total PE 4665
Alloc PE / Size 4665 / 18.22 GiB
Free PE / Size 0 / 0
VG UUID Ypjgyk-qPe9-K6f0-Pr14-AnCZ-f5lW-8swMgw
root@wxserver:~ ====================== lvdisplay 查看lv名称
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID jRI8Np-ylL9-1wGW-3rv9-f2c2-6bJS-B8Mwf1
LV Write Access read/write
LV Creation host, time ubuntu-server, 2023-09-26 14:33:59 +0000
LV Status available
# open 1
LV Size 18.22 GiB
Current LE 4665
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
root@wxserver:~ =========== vgextend ubuntu-vg /dev/sdb1 (vgextend <YourVGName> <分区>)
Volume group "ubuntu-vg" successfully extended
root@wxserver:~ ========= lvdisplay
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID jRI8Np-ylL9-1wGW-3rv9-f2c2-6bJS-B8Mwf1
LV Write Access read/write
LV Creation host, time ubuntu-server, 2023-09-26 14:33:59 +0000
LV Status available
# open 1
LV Size 18.22 GiB
Current LE 4665
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
root@wxserver:~ ========= lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv <YourVGName>/<YourLVName>
Size of logical volume ubuntu-vg/ubuntu-lv changed from 18.22 GiB (4665 extents) to <28.22 GiB (7224 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@wxserver:~ =========== resize2fs /dev/ubuntu-vg/ubuntu-lv
<YourVGName>/<YourLVName>
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 7397376 (4k) blocks long.
已有硬盘分区进行挂载
1、查看磁盘使用情况
df -h
2、查看磁盘分区详细信息,发现sda3分区可以挂载
fdisk -l
3、fdisk 磁盘名
4、详情
5、删除
6、发现已被删除
7、重新创建,磁盘柱起始位置和结束位置要保持一致,并且不要删除签名!!!(输入n)
查看详情
列出pv,发现没有
root@wxserver:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 18.22 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4665
Free PE 0
Allocated PE 4665
PV UUID eA30ga-5pez-3qLl-jjJJ-9zy5-ZFPz-PXGp6A
---------------------------------->此时还需要初始化 /dev/sdb3 为物理卷
root@wxserver:~# pvcreate /dev/sdb3
WARNING: ext4 signature detected on /dev/sdb3 at offset 1080. Wipe it? [y/n]: y
Wiping ext4 signature on /dev/sdb3.
Physical volume "/dev/sdb3" successfully created.
root@wxserver:~# pvdisplay 此时发现有了
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 18.22 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4665
Free PE 0
Allocated PE 4665
PV UUID eA30ga-5pez-3qLl-jjJJ-9zy5-ZFPz-PXGp6A
"/dev/sdb3" is a new physical volume of "<2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size <2.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID aQ8CRc-sAIF-Q94q-IA4S-aMZV-8hHZ-jS3sZl
刷新pv空间
root@wxserver:~# pvdisplay #先列出pv
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size <18.23 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4665
Free PE 2105
Allocated PE 2560
PV UUID eA30ga-5pez-3qLl-jjJJ-9zy5-ZFPz-PXGp6A
root@wxserver:~# pvresize /dev/sda3 #调用pvresize进行刷新
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
root@wxserver:~# pvdisplay #再次查看pv大小 发现pv大小已经正常
--- Physical volume ---
PV Name /dev/sda3
VG Name ubuntu-vg
PV Size 18.22 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4665
Free PE 2105
Allocated PE 2560
PV UUID eA30ga-5pez-3qLl-jjJJ-9zy5-ZFPz-PXGp6A
为lv增加空间
对pv扩容完成后,会发现lv的空间依旧没有增加,此时需要扩展lv大小,使用lvextend:
root@wxserver:~# lvdisplay #列出lv信息 发现lv空间没有增加
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID jRI8Np-ylL9-1wGW-3rv9-f2c2-6bJS-B8Mwf1
LV Write Access read/write
LV Creation host, time ubuntu-server, 2023-09-26 14:33:59 +0000
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
root@wxserver:~# lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv #所有的都扩容到根目录
Size of logical volume ubuntu-vg/ubuntu-lv changed from 10.00 GiB (2560 extents) to 18.22 GiB (4665 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
root@wxserver:~# lvdisplay #再次列出lv信息 发现lv空间已经增加
--- Logical volume ---
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID jRI8Np-ylL9-1wGW-3rv9-f2c2-6bJS-B8Mwf1
LV Write Access read/write
LV Creation host, time ubuntu-server, 2023-09-26 14:33:59 +0000
LV Status available
# open 1
LV Size 18.22 GiB
Current LE 4665
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
对lv扩容完成后,会发现根目录的空间依旧没有增加,此时需要刷新根目录大小,使用resize2fs
root@wxserver:~# df -h #发现/根目录空间还是没有增加
Filesystem Size Used Avail Use% Mounted on
udev 926M 0 926M 0% /dev
tmpfs 195M 1.4M 193M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 9.8G 4.5G 4.9G 48% /
tmpfs 971M 0 971M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 971M 0 971M 0% /sys/fs/cgroup
/dev/sda2 1.8G 108M 1.5G 7% /boot
/dev/loop0 92M 92M 0 100% /snap/lxd/24061
/dev/loop1 64M 64M 0 100% /snap/core20/1828
/dev/loop2 50M 50M 0 100% /snap/snapd/18357
tmpfs 195M 0 195M 0% /run/user/1000
root@wxserver:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv #使用resize2fs进行刷新
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 4776960 (4k) blocks long.
root@wxserver:~# df -h #再次查看,发现/根目录空间已经增加
Filesystem Size Used Avail Use% Mounted on
udev 926M 0 926M 0% /dev
tmpfs 195M 1.4M 193M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 18G 4.5G 13G 27% /
tmpfs 971M 0 971M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 971M 0 971M 0% /sys/fs/cgroup
/dev/sda2 1.8G 108M 1.5G 7% /boot
/dev/loop0 92M 92M 0 100% /snap/lxd/24061
/dev/loop1 64M 64M 0 100% /snap/core20/1828
/dev/loop2 50M 50M 0 100% /snap/snapd/18357
tmpfs 195M 0 195M 0% /run/user/1000