容器学习Day04-Ubuntu常用命令(二)

系列文章目录

容器学习Day01-初识容器

容器学习Day02-VMware Workstation安装Ubuntu

容器学习Day03-Ubuntu常用命令(一)

容器学习Day04-Ubuntu常用命令(二)

容器学习Day05-Ubuntu常用命令(三)

容器学习Day06-Ubuntu常用命令(四)

容器学习Day07-Docker基础(一)

容器学习Day08-Docker基础(二)

容器学习Day09-理解容器镜像

容器学习Day10-搭建私有镜像仓库

容器学习Day11-docker commit构建容器镜像

容器学习Day12-使用Dockerfile构建容器镜像

容器学习Day13-Docker容器网络

容器学习Day14-Docker容器存储

容器学习Day15-Docker容器底层实现技术

容器学习Day16-Docker Compose容器编排


文章目录

前言

一、软件包管理相关命令

1、dpkg

2、apt

二、磁盘管理相关命令

1、fdisk

2、pvcreate&pvdisplay&pvscan&pvremove

3、vgcreate&vgdisplay&vgscan&vgremove&vgextend&vgreduce

4、lvcreate&lvdisplay&lvscan&lvremove&lvreduce&lvextend

5、mkfs

6、lsblk&blkid

总结

前言

       本次继续学习了解Ubuntu操作系统常用命令。


一、软件包管理相关命令

       Ubuntu是Debian系统的衍生版本,软件安装包和Debian一样,是deb安装包,类似于Redhat的rpm包。

1、dpkg

  • dpkg(安装deb格式软件包)

用法:类似于Redhat的rpm命令,可以通过deb文件安装软件,同rpm一样,dpkg不能自动解决软件包的依赖问题。普通用户执行命令需要加上sudo。

           dpkg -i deb文件,安装软件。

           dpkg -i -R 目录路径,安装某目录下所有的软件包。

           dpkg -r 软件包,卸载软件包,但是保留配置文件。

           dpkg -P 软件包,卸载软件,同时移除配置文件。

           dpkg -l,列出系统中所有的包,类似于rpm -qa,后可跟包名,也可以配合grep使用。

           dpkg -S 文件名,查询系统中某个文件属于哪个软件包。 

           dpkg -s 软件包,查看软件包的安装状态。

           dpkg -L,查看软件包安装位置信息。

           dpkg --help,查看命令帮助信息。

### 使用dpkg命令安装vsftp。
demo@docker:~$ sudo dpkg -i vsftpd_3.0.3-13+b1_amd64.deb 
Selecting previously unselected package vsftpd.
(Reading database ... 98625 files and directories currently installed.)
Preparing to unpack vsftpd_3.0.3-13+b1_amd64.deb ...
Unpacking vsftpd (3.0.3-13+b1) ...
Setting up vsftpd (3.0.3-13+b1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /lib/systemd/system/vsftpd.service.

###-r参数卸载软件包,但保留配置文件。
demo@docker:~$ sudo dpkg -r vsftpd
(Reading database ... 98684 files and directories currently installed.)
Removing vsftpd (3.0.3-13+b1) ...
demo@docker:~$ ls -l /etc/vsftpd.conf 
-rw-r--r-- 1 root root 5850 May 14 04:56 /etc/vsftpd.conf
demo@docker:~$ ls -l /etc/systemd/system/vsftpd.service 
lrwxrwxrwx 1 root root 9 Sep  7 01:46 /etc/systemd/system/vsftpd.service -> /dev/null

###使用-R参数安装vsftp,软件包放在了/home/demo中。
demo@docker:~$ sudo dpkg -i -R /home/demo/
Selecting previously unselected package vsftpd.
(Reading database ... 98630 files and directories currently installed.)
Preparing to unpack ...//vsftpd_3.0.3-13+b1_amd64.deb ...
Unpacking vsftpd (3.0.3-13+b1) ...
Setting up vsftpd (3.0.3-13+b1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
demo@docker:~$ systemctl status vsftpd
● vsftpd.service - vsftpd FTP server
     Loaded: loaded (/lib/systemd/system/vsftpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-09-07 01:52:24 UTC; 26s ago
    Process: 14934 ExecStartPre=/bin/mkdir -p /var/run/vsftpd/empty (code=exited, status=0/SUCCESS)
   Main PID: 14935 (vsftpd)
      Tasks: 1 (limit: 2248)
     Memory: 852.0K
        CPU: 5ms
     CGroup: /system.slice/vsftpd.service
             └─14935 /usr/sbin/vsftpd /etc/vsftpd.conf

Sep 07 01:52:24 docker systemd[1]: Starting vsftpd FTP server...
Sep 07 01:52:24 docker systemd[1]: Started vsftpd FTP server.

###使用-P参数卸载,配置文件也被清除。
demo@docker:~$ sudo dpkg -P vsftpd
[sudo] password for demo: 
(Reading database ... 98684 files and directories currently installed.)
Removing vsftpd (3.0.3-13+b1) ...
Purging configuration files for vsftpd (3.0.3-13+b1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
demo@docker:~$ ls -l /etc/vsftpd.conf
ls: cannot access '/etc/vsftpd.conf': No such file or directory

###重新安装vsftp,用-l参数查看一下,-l后面不加包名会列出所有已安装软件。

demo@docker:~$ sudo dpkg -l vsftpd
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-======================================================
ii  vsftpd         3.0.3-13+b1  amd64        lightweight, efficient FTP server written for security
demo@docker:~$ sudo dpkg -l |grep vsftpd
ii  vsftpd                                3.0.3-13+b1                             amd64        lightweight, efficient FTP server written for security

###使用-S查看文件属于哪个软件包
demo@docker:~$ sudo dpkg -S /etc/vsftpd.conf 
vsftpd: /etc/vsftpd.conf

###使用-s命令查看软件包安装状态。
demo@docker:~$ sudo dpkg -s vsftpd
Package: vsftpd
Status: install ok installed
Priority: optional
Section: net
Installed-Size: 354
Maintainer: Keng-Yu Lin <kengyu@debian.org>
Architecture: amd64
Source: vsftpd (3.0.3-13)
Version: 3.0.3-13+b1
Replaces: ftp-server
Provides: ftp-server
Depends: debconf (>= 0.5) | debconf-2.0, libc6 (>= 2.33), libcap2 (>= 1:2.10), libpam0g (>= 0.99.7.1), libssl3 (>= 3.0.0), libwrap0 (>= 7.6-4~), adduser, libpam-modules, lsb-base (>= 3.0-6), netbase, procps, sysvinit-utils (>= 2.96)
Recommends: logrotate, ssl-cert
Conflicts: ftp-server
Conffiles:
 /etc/ftpusers 839f3157aad792bafbbdcd932a95a345
 /etc/init.d/vsftpd caec74bf42550509365f905291645344
 /etc/logrotate.d/vsftpd dac2cb7b9cfd8a03b4fa9ca3601a43a6
 /etc/pam.d/vsftpd e75200b7896d8b2c2f2590d0e3d4a6ef
 /etc/vsftpd.conf 0ed7ed3a33022af132b878c8c937bad9
Description: lightweight, efficient FTP server written for security
 This package provides the "Very Secure FTP Daemon", written from
 the ground up with security in mind.
 .
 It supports both anonymous and non-anonymous FTP access, PAM authentication,
 bandwidth limiting, and the Linux sendfile() facility.
Homepage: http://vsftpd.beasts.org/

###使用-L参数查看软件安装位置信息
demo@docker:~$ sudo dpkg -L vsftpd 
/.
/etc
/etc/ftpusers
/etc/init.d
/etc/init.d/vsftpd
/etc/logrotate.d
/etc/logrotate.d/vsftpd
/etc/pam.d
.........

###使用--help查看帮助
demo@docker:~$ sudo dpkg --help
Usage: dpkg [<option>...] <command>

Commands:
  -i|--install       <.deb file name>... | -R|--recursive <directory>...
.........

2、apt

  • apt(软件包管理)

用法:apt update,更新软件源列表缓存信息。

           apt upgrade,升级所有可升级的软件包。

           apt search 软件包,搜索软件包。

           apt show 软件包,显示软件包的详细信息。

           apt install 软件包,安装软件包。

           apt remove,移除软件包,不删除配置文件。

           apt purge,移除软件包及配置文件。

           普通用户执行命令需要加上sudo。

###更新软件源列表缓存
demo@docker:~$ sudo apt update
[sudo] password for demo: 
Hit:1 http://cn.archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://cn.archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Fetched 324 kB in 3s (105 kB/s) 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

###更新软件包,上边其实已经查到了,所有包都是最新,不会有更新的动作。
demo@docker:~$ sudo apt upgrade -y
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

###先卸载前面安装的vsftpd,试一下使用apt安装,先查找一下,然后进行安装。
demo@docker:~$ sudo dpkg -P vsftpd
(Reading database ... 98684 files and directories currently installed.)
Removing vsftpd (3.0.3-13+b1) ...
Purging configuration files for vsftpd (3.0.3-13+b1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline

###搜索vsftp软件包。
demo@docker:~$ sudo apt search vsftpd
Sorting... Done
Full Text Search... Done
ccze/jammy 0.2.1-6 amd64
  robust, modular log coloriser
ftpd/jammy 0.17-36.2 amd64
  File Transfer Protocol (FTP) server
resource-agents-extra/jammy 1:4.7.0-1ubuntu7 amd64
  Cluster Resource Agents
vsftpd/jammy,now 3.0.5-0ubuntu1 amd64 [residual-config]
  lightweight, efficient FTP server written for security
vsftpd-dbg/jammy 3.0.5-0ubuntu1 amd64
  lightweight, efficient FTP server written for security (debug)
yasat/jammy 848-1.1 all
  simple stupid audit tool

###安装搜索到对应的包。
demo@docker:~$ sudo apt install -y vsftpd/jammy
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Selected version '3.0.5-0ubuntu1' (Ubuntu:22.04/jammy [amd64]) for 'vsftpd'
The following NEW packages will be installed:
  vsftpd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/123 kB of archives.
After this operation, 326 kB of additional disk space will be used.
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package vsftpd.
(Reading database ... 98651 files and directories currently installed.)
Preparing to unpack .../vsftpd_3.0.5-0ubuntu1_amd64.deb ...
Unpacking vsftpd (3.0.5-0ubuntu1) ...
Setting up vsftpd (3.0.5-0ubuntu1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /lib/systemd/system/vsftpd.service.
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
Scanning processes...                                                                                                                                                                       
Scanning linux images...                                                                                                                                                                    

Running kernel seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
No user sessions are running outdated binaries.
No VM guests are running outdated hypervisor (qemu) binaries on this host.

###显示软件包相关信息。
demo@docker:~$ sudo apt show vsftpd
Package: vsftpd
Version: 3.0.5-0ubuntu1
Priority: extra
Section: net
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Keng-Yu Lin <kengyu@debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 326 kB
Provides: ftp-server
Depends: debconf (>= 0.5) | debconf-2.0, libc6 (>= 2.34), libcap2 (>= 1:2.10), libpam0g (>= 0.99.7.1), libssl3 (>= 3.0.0~~alpha1), libwrap0 (>= 7.6-4~), adduser, libpam-modules, lsb-base (>= 3.0-6), netbase, procps, sysvinit-utils (>= 2.96)
Recommends: logrotate, ssl-cert
Conflicts: ftp-server
Replaces: ftp-server
Homepage: http://vsftpd.beasts.org/
Download-Size: 123 kB
APT-Manual-Installed: yes
APT-Sources: http://cn.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
Description: lightweight, efficient FTP server written for security
 This package provides the "Very Secure FTP Daemon", written from
 the ground up with security in mind.
 .
 It supports both anonymous and non-anonymous FTP access, PAM authentication,
 bandwidth limiting, and the Linux sendfile() facility.

###卸载软件包,apt remove/apt purge,remove会保留配置文件,purge不会保留配置文件。
demo@docker:~$ sudo apt purge -y vsftpd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  logrotate ssl-cert
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  vsftpd*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 326 kB disk space will be freed.
(Reading database ... 98708 files and directories currently installed.)
Removing vsftpd (3.0.5-0ubuntu1) ...
(Reading database ... 98656 files and directories currently installed.)
Purging configuration files for vsftpd (3.0.5-0ubuntu1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 78.)
debconf: falling back to frontend: Readline
  • 更换软件源

      装系统时我们没有更改软件源,使用的是默认的软件源,如果想要更改软件源,可以修改配置文件即可。以清华大学软件源为例,官网上一般都会有帮助文档,有具体使用说明。详见:ubuntu | 镜像站使用帮助 | 清华大学开源软件镜像站

###可以先备份一下原来的软件源配置/etc/apt/sources.list。
demo@docker:~$ sudo cp -p /etc/apt/sources.list /etc/apt/sources.list_bak

###打开官方文档,找到对应系统版本的配置说明,可以手工修改配置文件,也可以使用命令替换。
demo@docker:~$ sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
demo@docker:~$ sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list

###apt update,更新软件源列表缓存信息,url已被替换为新的软件源。
demo@docker:~$ sudo apt update
Get:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease [270 kB]
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease [114 kB]
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease [99.8 kB]
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease [110 kB]
Get:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main amd64 Packages [1395 kB]
Get:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/main Translation-en [510 kB]
Get:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/restricted amd64 Packages [129 kB]
Get:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/restricted Translation-en [18.6 kB]
Get:9 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe amd64 Packages [14.1 MB]
Get:10 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/universe Translation-en [5652 kB]                                                                                                 
Get:11 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/multiverse amd64 Packages [217 kB]                                                                                                
Get:12 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy/multiverse Translation-en [112 kB]                                                                                                
Get:13 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 Packages [544 kB]                                                                                              
Get:14 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main Translation-en [128 kB]                                                                                              
Get:15 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/restricted amd64 Packages [306 kB]                                                                                        
Get:16 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/restricted Translation-en [47.5 kB]                                                                                       
Get:17 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/universe amd64 Packages [254 kB]                                                                                          
Get:18 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/universe Translation-en [83.3 kB]                                                                                         
Get:19 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/multiverse amd64 Packages [7000 B]                                                                                        
Get:20 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/multiverse Translation-en [2264 B]                                                                                        
Get:21 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/main amd64 Packages [3008 B]                                                                                            
Get:22 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/main Translation-en [1432 B]                                                                                            
Get:23 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/universe amd64 Packages [6724 B]                                                                                        
Get:24 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports/universe Translation-en [9216 B]                                                                                        
Get:25 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/main amd64 Packages [295 kB]                                                                                             
Get:26 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/main Translation-en [69.1 kB]                                                                                            
Get:27 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/restricted amd64 Packages [274 kB]                                                                                       
Get:28 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/restricted Translation-en [42.3 kB]                                                                                      
Get:29 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/universe amd64 Packages [121 kB]                                                                                         
Get:30 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/universe Translation-en [41.5 kB]                                                                                        
Get:31 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/multiverse amd64 Packages [4192 B]                                                                                       
Get:32 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security/multiverse Translation-en [900 B]                                                                                        
Fetched 25.0 MB in 21s (1168 kB/s)                                                                                                                                                         
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

二、磁盘管理相关命令

       LVM(Logical volume Manager)是逻辑卷管理的简称,通过将底层物理硬盘抽象封装起来,以逻辑卷的形式提供给上层系统。LVM最大的特点就是可以对磁盘进行动态管理,动态调整逻辑卷的大小。

      创建LV(逻辑卷)需要先将硬盘进行分区(也可以直接使用整块硬盘),然后将分区或者硬盘创建成PV(物理卷),再将PV加入VG(卷组),从VG(卷组)中再创建LV(逻辑卷)。

1、fdisk

  • fdisk(创建、维护磁盘分区)

用法:fdisk -l,查看系统中磁盘分区情况。

           fdisk 设备名,对硬盘设备进行分区,输入命令回车后会进入到交互界面。

           常用交互指令:n,新建一个分区。        w,分区表同步到硬盘并退出。

                                    m,查看帮助。              q,退出。

                                    d,删除一个分区。

                                    t,更改分区类型。

           普通用户执行命令需要加上sudo。

###查看磁盘分区情况,安装系统时添加了一块20G的数据盘/dev/sdb。
demo@docker:~$ sudo fdisk -l
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 5395D176-5199-44F6-8511-24F1B07D6C47

Device       Start      End  Sectors  Size Type
/dev/sda1     2048     4095     2048    1M BIOS boot
/dev/sda2     4096  3719167  3715072  1.8G Linux filesystem
/dev/sda3  3719168 41940991 38221824 18.2G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

###对/dev/sdb进行分区,创建一个主分区,一个逻辑分区。
demo@docker:~$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

##输入n创建一个分区。
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
##输入p,创建一个主分区。
Select (default p): p
##设置一个分区编号,默认即可。
Partition number (1-4, default 1): 1
##起始扇区,默认回车。
First sector (2048-41943039, default 2048): 
##末尾扇区,可以设置一个数值,分区的大小,比如+10G。
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943039, default 41943039): +10G

Created a new partition 1 of type 'Linux' and of size 10 GiB.
##修改分区类型,输入t。
Command (m for help): t
##修改哪个编号分区的类型。
Selected partition 1
##8e代表Linux LVM类型。
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.

##输入n,再创建一个扩展分区。
Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
##选择e,扩展分区,创建逻辑分区需要先创建扩展分区。
Select (default p): e
##分区编号,默认即可。
Partition number (2-4, default 2): 2
##起始扇区,默认回车即可。
First sector (20973568-41943039, default 20973568): 
##末尾扇区,不再创建别的分区了,直接默认回车,将剩余全部分给该分区。
Last sector, +/-sectors or +/-size{K,M,G,T,P} (20973568-41943039, default 41943039): 

Created a new partition 2 of type 'Extended' and of size 10 GiB.

##输入n,创建逻辑分区。
Command (m for help): n
All space for primary partitions is in use.

Adding logical partition 5
First sector (20975616-41943039, default 20975616): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (20975616-41943039, default 41943039): 

Created a new partition 5 of type 'Linux' and of size 10 GiB.

##输入t,修改分区类型。
Command (m for help): t
##输入要修改类型的分区编号。
Partition number (1,2,5, default 5): 5
##输入8e,改为Linux LVM类型。
Hex code or alias (type L to list all): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

##输入p,打印分区表,查看分区详情。
Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xbb6522f2

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 20973567 20971520  10G 8e Linux LVM
/dev/sdb2       20973568 41943039 20969472  10G  5 Extended
/dev/sdb5       20975616 41943039 20967424  10G 8e Linux LVM

##确认无误后,输入w,保存并退出。
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

2、pvcreate&pvdisplay&pvscan&pvremove

  • pvcreate(创建PV)
  • pvdisplay(显示PV信息)
  • pvscan(PV列表)
  • pvremove(删除PV)

用法:pvcreate 设备名,创建PV,设备可以是整块硬盘,也可以是硬盘的一个分区。

           pvdisplay PV名,显示PV详细信息,不加PV名则显示所有PV的详细信息。

           pvscan,查看系统中的PV。

           pvremove PV名,删除PV。

           普通用户执行命令需要加上sudo。

###上边我们创建了两个分区/dev/sdb1和/dev/sdb5,先将其中一个分区创建成PV。
demo@docker:~$ sudo pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

###查看所有PV的信息。
demo@docker:~$ sudo pvdisplay
  --- 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               EXHek9-o5OQ-maUG-RFbE-66Pv-KfjF-ZdjM5J
   
  "/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               AjREJu-tt47-VFvK-D5fV-1p28-uhoH-Ev7S9y

###显示系统中有哪些PV。
demo@docker:~$ sudo pvscan
  PV /dev/sda3   VG ubuntu-vg       lvm2 [18.22 GiB / 8.22 GiB free]
  PV /dev/sdb1                      lvm2 [10.00 GiB]
  Total: 2 [28.22 GiB] / in use: 1 [18.22 GiB] / in no VG: 1 [10.00 GiB]

###把另一个分区也创建成PV,然后删除之前创建的PV。
demo@docker:~$ sudo pvcreate /dev/sdb5
  Physical volume "/dev/sdb5" successfully created.
demo@docker:~$ sudo pvscan
  PV /dev/sda3   VG ubuntu-vg       lvm2 [18.22 GiB / 8.22 GiB free]
  PV /dev/sdb1                      lvm2 [10.00 GiB]
  PV /dev/sdb5                      lvm2 [<10.00 GiB]
  Total: 3 [38.22 GiB] / in use: 1 [18.22 GiB] / in no VG: 2 [<20.00 GiB]
demo@docker:~$ sudo pvremove /dev/sdb1
  Labels on physical volume "/dev/sdb1" successfully wiped.
demo@docker:~$ sudo pvscan
  PV /dev/sda3   VG ubuntu-vg       lvm2 [18.22 GiB / 8.22 GiB free]
  PV /dev/sdb5                      lvm2 [<10.00 GiB]
  Total: 2 [28.22 GiB] / in use: 1 [18.22 GiB] / in no VG: 1 [<10.00 GiB]

 3、vgcreate&vgdisplay&vgscan&vgremove&vgextend&vgreduce

  • vgcreate(创建VG)
  • vgdisplay(显示VG信息)
  • vgscan(VG列表)
  • vgremove(删除VG)
  • vgreduce(VG缩容)
  • vgextend(VG扩容)

用法:vgcreate VG名 PV1 PV2...PVN,创建VG,可以加入多个PV,PV之间空格隔开。

           vgdisplay VG名,显示VG详细信息,不加VG名则显示所有VG详细信息。

           vgscan,列出所有VG。

           vgremove VG名,删除VG。

           vgreduce VG名 PV名,VG移除PV缩小容量。

           vgextend VG名 PV名,VG扩充容量。

           普通用户执行命令需要加上sudo。

###将前面删掉的PV再创建出来,两个PV组成VG。
demo@docker:~$ sudo pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

demo@docker:~$ sudo pvscan
  PV /dev/sda3   VG ubuntu-vg       lvm2 [18.22 GiB / 8.22 GiB free]
  PV /dev/sdb1                      lvm2 [10.00 GiB]
  PV /dev/sdb5                      lvm2 [<10.00 GiB]
  Total: 3 [38.22 GiB] / in use: 1 [18.22 GiB] / in no VG: 2 [<20.00 GiB]

demo@docker:~$ sudo vgcreate data-vg /dev/sdb1 /dev/sdb5
  Volume group "data-vg" successfully created

###查看新建data-vg详细信息。
demo@docker:~$ sudo vgdisplay datavg
  Volume group "datavg" not found
  Cannot process volume group datavg
demo@docker:~$ sudo vgdisplay data-vg
  --- Volume group ---
  VG Name               data-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               yLaOvM-ddwA-evU1-XtWv-lIlu-5rIy-IiX77g

###列出所有VG。
demo@docker:~$ sudo vgscan
  Found volume group "data-vg" using metadata type lvm2
  Found volume group "ubuntu-vg" using metadata type lvm2

###删除新建的data-vg。
demo@docker:~$ sudo vgscan
  Found volume group "data-vg" using metadata type lvm2
  Found volume group "ubuntu-vg" using metadata type lvm2
demo@docker:~$ sudo vgremove data-vg
  Volume group "data-vg" successfully removed
demo@docker:~$ sudo vgscan
  Found volume group "ubuntu-vg" using metadata type lvm2

###重新创建VG,对VG进行缩容。
demo@docker:~$ sudo vgcreate data-vg /dev/sdb1 /dev/sdb5
  Volume group "data-vg" successfully created
demo@docker:~$ sudo vgdisplay data-vg
  --- Volume group ---
  VG Name               data-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               tz7y0E-Cohn-FHrG-Ay4h-oUC4-iOzY-bPo9Qu
   
demo@docker:~$ sudo vgreduce data-vg /dev/sdb5
  Removed "/dev/sdb5" from volume group "data-vg"
demo@docker:~$ sudo vgdisplay data-vg
  --- Volume group ---
  VG Name               data-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <10.00 GiB
  PE Size               4.00 MiB
  Total PE              2559
  Alloc PE / Size       0 / 0   
  Free  PE / Size       2559 / <10.00 GiB
  VG UUID               tz7y0E-Cohn-FHrG-Ay4h-oUC4-iOzY-bPo9Qu

###对VG进行扩容。
demo@docker:~$ sudo vgextend data-vg /dev/sdb5
  Volume group "data-vg" successfully extended
demo@docker:~$ sudo vgdisplay data-vg
  --- Volume group ---
  VG Name               data-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               19.99 GiB
  PE Size               4.00 MiB
  Total PE              5118
  Alloc PE / Size       0 / 0   
  Free  PE / Size       5118 / 19.99 GiB
  VG UUID               tz7y0E-Cohn-FHrG-Ay4h-oUC4-iOzY-bPo9Qu

4、lvcreate&lvdisplay&lvscan&lvremove&lvreduce&lvextend

  • lvcreate(创建LV)
  • lvdisplay(列出LV详细信息)
  • lvscan(列出所有LV)
  • lvremove(移除LV)
  • lvreduce(LV缩容)
  • lvextend(LV扩容)

 用法:lvcreate -L 容量 -n LV名 VG名,创建LV。

            lvdisplay /dev/VG名/LV名,显示LV详细信息,不加LV全名则列出所有LV详细信息。

            lvscan,列出所有LV。

            lvremove /dev/VG名/LV名,删除LV。

            lvreduce -L 容量 /dev/VG名/LV名,将LV的容量缩小到多少,如果容量带-号,则表示减少多少容量。

            lvextend -L 容量 /dev/VG名/LV名,将LV的容量扩大到多少,如果容量带+号,则表示增加多少容量。

            普通用户执行命令需要加上sudo。

###创建一个5G大小的LV。
demo@docker:~$ sudo lvcreate -L 5G -n data-lv data-vg
  Logical volume "data-lv" created.

###查看LV详细信息。
demo@docker:~$ sudo lvdisplay /dev/data-vg/data-lv
  --- Logical volume ---
  LV Path                /dev/data-vg/data-lv
  LV Name                data-lv
  VG Name                data-vg
  LV UUID                cQVLj7-zMbz-HFUG-G8Zy-lP0T-6DHc-V8hTUy
  LV Write Access        read/write
  LV Creation host, time docker, 2022-09-07 16:48:38 +0000
  LV Status              available
  # open                 0
  LV Size                5.00 GiB
  Current LE             1280
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

###列出所有LV。
demo@docker:~$ sudo lvscan
  ACTIVE            '/dev/data-vg/data-lv' [5.00 GiB] inherit
  ACTIVE            '/dev/ubuntu-vg/ubuntu-lv' [10.00 GiB] inherit

###删除LV。
demo@docker:~$ sudo lvscan
  ACTIVE            '/dev/data-vg/data-lv' [5.00 GiB] inherit
  ACTIVE            '/dev/ubuntu-vg/ubuntu-lv' [10.00 GiB] inherit

demo@docker:~$ sudo lvremove /dev/data-vg/data-lv
Do you really want to remove and DISCARD active logical volume data-vg/data-lv? [y/n]: y
  Logical volume "data-lv" successfully removed
demo@docker:~$ sudo lvscan
  ACTIVE            '/dev/ubuntu-vg/ubuntu-lv' [10.00 GiB] inherit

###重新创建LV,并进行缩容。
demo@docker:~$ sudo lvcreate -L 5G -n data-lv data-vg
  Logical volume "data-lv" created.

##4G表示缩容到4G。
demo@docker:~$ sudo lvreduce -L 4G /dev/data-vg/data-lv 
  WARNING: Reducing active logical volume to 4.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce data-vg/data-lv? [y/n]: y
  Size of logical volume data-vg/data-lv changed from 5.00 GiB (1280 extents) to 4.00 GiB (1024 extents).
  Logical volume data-vg/data-lv successfully resized.

##-1G表示缩小1G。
demo@docker:~$ sudo lvreduce -L -1G /dev/data-vg/data-lv 
  WARNING: Reducing active logical volume to 3.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce data-vg/data-lv? [y/n]: y
  Size of logical volume data-vg/data-lv changed from 4.00 GiB (1024 extents) to 3.00 GiB (768 extents).
  Logical volume data-vg/data-lv successfully resized.

###扩容
##+1G表示扩容1G
demo@docker:~$ sudo lvextend -L +1G /dev/data-vg/data-lv
  Size of logical volume data-vg/data-lv changed from 3.00 GiB (768 extents) to 4.00 GiB (1024 extents).
  Logical volume data-vg/data-lv successfully resized.

##6G表示扩容到10G
demo@docker:~$ sudo lvextend -L 10G /dev/data-vg/data-lv
  Size of logical volume data-vg/data-lv changed from 4.00 GiB (1024 extents) to 10.00 GiB (2560 extents).
  Logical volume data-vg/data-lv successfully resized.

5、mkfs

  • mkfs(创建文件系统)

用法:mkfs.ext4 /dev/VG名/LV名,将LV格式化为ext4文件系统。

           mkfs.xfs /dev/VG名/LV名,将LV格式化为xfs文件系统。

           格式化完成之后,LV就可以挂载到系统中使用。

           普通用户执行命令需要加上sudo。

###将LV格式化为xfs文件系统。
demo@docker:~$ sudo mkfs.xfs /dev/data-vg/data-lv
meta-data=/dev/data-vg/data-lv   isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

###创建挂载点,并挂载LV。
demo@docker:~$ sudo mkdir /docker
demo@docker:~$ sudo mount /dev/data-vg/data-lv /docker/
demo@docker:~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              195M  904K  194M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.8G  4.2G  5.2G  45% /
tmpfs                              971M     0  971M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          1.8G  127M  1.5G   8% /boot
tmpfs                              195M  4.0K  195M   1% /run/user/1000
/dev/sr0                           1.4G  1.4G     0 100% /mnt
/dev/mapper/data--vg-data--lv       10G  104M  9.9G   2% /docker

6、lsblk&blkid

  • lsblk(列出块设备)
  • blkid(显示块设备信息)

用法:无需加其他参数,返回块设备相关信息。

           blkid可以获取到设备的UUID,可以在fstab文件中设置LV开机自动挂载。

demo@docker:~$ sudo lsblk
NAME                      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda                         8:0    0   20G  0 disk 
├─sda1                      8:1    0    1M  0 part 
├─sda2                      8:2    0  1.8G  0 part /boot
└─sda3                      8:3    0 18.2G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0   10G  0 lvm  /
sdb                         8:16   0   20G  0 disk 
├─sdb1                      8:17   0   10G  0 part 
│ └─data--vg-data--lv     253:1    0   10G  0 lvm  /docker
├─sdb2                      8:18   0    1K  0 part 
└─sdb5                      8:21   0   10G  0 part 
  └─data--vg-data--lv     253:1    0   10G  0 lvm  /docker
sr0                        11:0    1  1.4G  0 rom  /mnt

###查看块设备UUID。
demo@docker:~$ sudo blkid
/dev/sr0: BLOCK_SIZE="2048" UUID="2022-08-09-16-48-33-00" LABEL="Ubuntu-Server 22.04.1 LTS amd64" TYPE="iso9660" PTTYPE="PMBR"
/dev/mapper/ubuntu--vg-ubuntu--lv: UUID="81dec9dd-e065-46a9-98f4-5d30b8d0ecd0" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sda2: UUID="60aaae8f-932c-4562-a11c-7a5afc3e336b" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="c1f6b0b9-08e1-4fd2-a199-aec506f8ea3a"
/dev/sda3: UUID="EXHek9-o5OQ-maUG-RFbE-66Pv-KfjF-ZdjM5J" TYPE="LVM2_member" PARTUUID="031b9547-293b-40b8-9d31-7762c4c0dfb1"
/dev/mapper/data--vg-data--lv: UUID="40b47bd0-0671-4a4b-9084-4218b443e51a" BLOCK_SIZE="512" TYPE="xfs"
/dev/sdb5: UUID="jHn492-EGpc-eaSS-9AOD-wBC6-seuG-Qo3N2K" TYPE="LVM2_member" PARTUUID="09268c71-05"
/dev/sdb1: UUID="ZWhEb0-n6wr-eo9G-fcxd-uX3N-fGf3-DZUhs8" TYPE="LVM2_member" PARTUUID="09268c71-01"
/dev/sda1: PARTUUID="ca8061e0-0d23-47b0-a57a-fc4896d948ee"

###将挂载信息写入fstab文件,系统是最小化安装没有vim,可以安装vim编辑fatab文件。
demo@docker:~$ sudo apt install vim/jammy
demo@docker:~$ sudo vim /etc/fstab

###编辑fstab文件,最后一行新增挂载信息,保存并退出。
UUID="40b47bd0-0671-4a4b-9084-4218b443e51a"    /docker   xfs   defaults 0 0

###执行mount -a命令检查fstab是否有问题。
demo@docker:~$ sudo umount /docker/
demo@docker:~$ sudo mount -a
demo@docker:~$ df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              195M  904K  194M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  9.8G  4.2G  5.1G  45% /
tmpfs                              971M     0  971M   0% /dev/shm
tmpfs                              5.0M     0  5.0M   0% /run/lock
/dev/sda2                          1.8G  127M  1.5G   8% /boot
tmpfs                              195M  4.0K  195M   1% /run/user/1000
/dev/sr0                           1.4G  1.4G     0 100% /mnt
/dev/mapper/data--vg-data--lv       10G  104M  9.9G   2% /docker

总结

       以上就是今天学习了解的内容,主要是Ubuntu系统软件包管理和磁盘管理两个方面的命令,后面继续看一下其他常用命令。

<think>我们被要求使用中文回答问题,并在最后提出3-5个相关问题,且第一行必须是"§§相关问题§§"。 问题:如何快速学习ROS1 回答思路: 1. 首先,给出一个结构化、实用的学习路径。 2. 强调实践和项目驱动学习。 3. 推荐官方资源和常用学习材料。 4. 提醒避免的常见陷阱。 注意:回答要简洁但全面,然后提出相关问题。</think>### 快速学习ROS1的高效方法 #### 核心学习路径(推荐周期:2-4周): 1. **基础准备阶段**(3天): - 掌握Linux基础命令(`ls/cd/mkdir/cp`等) - 安装Ubuntu 18.04/20.04(推荐Noetic版本) - 完成官方安装教程:`http://wiki.ros.org/ROS/Installation` 2. **核心概念速通**(1周): ```bash # 每日练习框架(每个概念动手实践) Day1: 节点(Node)与话题(Topic) → rosrun/rostopic Day2: 服务(Service)与参数(Parameter) → rosservice/rosparam Day3: 消息(Message)与包(Package) → catkin_create_pkg Day4: TF坐标变换 → view_frames Day5: 启动文件(Launch) → roslaunch ``` 3. **实战项目驱动**(2周): - 初级:仿真环境搭建(Gazebo+TurtleBot3) - 中级:SLAM建图(gmapping+RViz可视化) - 高级:自主导航(move_base路径规划) #### 高效资源推荐: - **官方文档**:`wiki.ros.org`(必读"Beginner Level"教程) - **视频课程**:Coursera《机器人学专项》(中文字幕) - **书籍**:《ROS机器人编程实践》(机械工业出版社) - **代码库**:GitHub搜索`ros1_examples` #### 关键加速技巧: 1. **使用Docker容器**避免环境配置问题: ```bash docker pull osrf/ros:noetic-desktop ``` 2. **调试工具组合**: - `rqt_graph`(拓扑关系) - `rqt_console`(日志查看) - `rosbag record/play`(数据回放) 3. 加入社区(ROS Answers、古月居论坛)即时提问 #### 避坑指南: ⚠️ 避免直接看源码(先掌握通信机制) ⚠️ 勿在虚拟机运行Gazebo(性能极差) ⚠️ 及时`source devel/setup.bash`防止命令找不到
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AtobeKegio

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值