LVM

LVM,Logical Volume Manager,逻辑卷管理,可以对磁盘进行动态管理。


准备磁盘分区

[root@centos-01 ~]# fdisk -l

磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000d9f36

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    62914559    29154304   83  Linux

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

[root@centos-01 ~]# fdisk /dev/sdb 
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0x8e047468 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System

命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-20971519,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-20971519,默认为 20971519):+1G
分区 1 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM

命令(输入 m 获取帮助):n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (2099200-20971519,默认为 2099200):
将使用默认值 2099200
Last 扇区, +扇区 or +size{K,M,G} (2099200-20971519,默认为 20971519):+1G
分区 2 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM
/dev/sdb2         2099200     4196351     1048576   83  Linux

命令(输入 m 获取帮助):t
分区号 (1,2,默认 2):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM
/dev/sdb2         2099200     4196351     1048576   8e  Linux LVM

命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (4196352-20971519,默认为 4196352):
将使用默认值 4196352
Last 扇区, +扇区 or +size{K,M,G} (4196352-20971519,默认为 20971519):+1G
分区 3 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):p

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM
/dev/sdb2         2099200     4196351     1048576   8e  Linux LVM
/dev/sdb3         4196352     6293503     1048576   8e  Linux LVM

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@centos-01 ~]# fdisk -l

磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000d9f36

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    62914559    29154304   83  Linux

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM
/dev/sdb2         2099200     4196351     1048576   8e  Linux LVM
/dev/sdb3         4196352     6293503     1048576   8e  Linux LVM

准备物理卷

[root@centos-01 ~]# pvcreate /dev/sdb1
-bash: pvcreate: 未找到命令
[root@centos-01 ~]# yum provides "/*/pvcreate"
已加载插件:fastestmirror
base                                                                                                                                                                    | 3.6 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

file is encrypted or is not a database

故障排除

出了一点问题

[root@centos-01 ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=128 time=20.6 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=128 time=21.3 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=3 ttl=128 time=21.4 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 20.615/21.126/21.429/0.363 ms

网络没问题,有可能是yum源的问题,或者是其他地方出问题了。不过之前用过yum,是可以的,不知怎么现在不能用了。

配置yum源

[root@centos-01 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@centos-01 ~]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@centos-01 ~]# cd /etc/yum.repos.d/
[root@centos-01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
-bash: wget: 未找到命令
[root@centos-01 yum.repos.d]# yum install -y wget
已加载插件:fastestmirror
base                                                                                                                                                                    | 3.6 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

file is encrypted or is not a database

本来参考网上指导,想下载163的yum源配置文件,但是wget命令没有安装……

换个姿势

[root@centos-01 yum.repos.d]# ls /etc/
adjtime                  cron.monthly             filesystems         hosts.allow    login.defs                os-release      rc2.d           sestatus.conf   system-release-cpe
aliases                  crontab                  firewalld           hosts.deny     logrotate.conf            pam.d           rc3.d           shadow          terminfo
aliases.db               cron.weekly              fstab               init.d         logrotate.d               passwd          rc4.d           shadow-         tmpfiles.d
alternatives             crypttab                 fuse.conf           inittab        machine-id                passwd-         rc5.d           shells          tuned
anacrontab               csh.cshrc                gcrypt              inputrc        magic                     pkcs11          rc6.d           skel            udev
asound.conf              csh.login                GeoIP.conf          iproute2       makedumpfile.conf.sample  pki             rc.d            ssh             updatedb.conf
audisp                   dbus-1                   GeoIP.conf.default  issue          man_db.conf               plymouth        rc.local        ssl             vconsole.conf
audit                    default                  gnupg               issue.net      mke2fs.conf               pm              redhat-release  statetab        virc
bash_completion.d        depmod.d                 GREP_COLORS         kdump.conf     modprobe.d                polkit-1        resolv.conf     statetab.d      vmware-tools
bashrc                   dhcp                     groff               kernel         modules-load.d            popt.d          rpc             subgid          wpa_supplicant
binfmt.d                 DIR_COLORS               group               krb5.conf      motd                      postfix         rpm             subuid          X11
centos-release           DIR_COLORS.256color      group-              krb5.conf.d    mtab                      ppp             rsyslog.conf    sudo.conf       xdg
centos-release-upstream  DIR_COLORS.lightbgcolor  grub2.cfg           ld.so.cache    my.cnf                    prelink.conf.d  rsyslog.d       sudoers         xinetd.d
chkconfig.d              dracut.conf              grub.d              ld.so.conf     my.cnf.d                  printcap        rwtab           sudoers.d       yum
chrony.conf              dracut.conf.d            gshadow             ld.so.conf.d   NetworkManager            profile         rwtab.d         sudo-ldap.conf  yum.conf
chrony.keys              e2fsck.conf              gshadow-            libaudit.conf  networks                  profile.d       sasl2           sysconfig       yum.repos.d
cron.d                   environment              gss                 libnl          nsswitch.conf             protocols       securetty       sysctl.conf
cron.daily               ethertypes               host.conf           libuser.conf   nsswitch.conf.bak         python          security        sysctl.d
cron.deny                exports                  hostname            locale.conf    openldap                  rc0.d           selinux         systemd
cron.hourly              favicon.png              hosts               localtime      opt                       rc1.d           services        system-release
[root@centos-01 yum.repos.d]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.backup/
[root@centos-01 yum.repos.d]# ls /etc/
adjtime                  cron.monthly             filesystems         hosts.allow    login.defs                os-release      rc2.d           sestatus.conf   system-release-cpe
aliases                  crontab                  firewalld           hosts.deny     logrotate.conf            pam.d           rc3.d           shadow          terminfo
aliases.db               cron.weekly              fstab               init.d         logrotate.d               passwd          rc4.d           shadow-         tmpfiles.d
alternatives             crypttab                 fuse.conf           inittab        machine-id                passwd-         rc5.d           shells          tuned
anacrontab               csh.cshrc                gcrypt              inputrc        magic                     pkcs11          rc6.d           skel            udev
asound.conf              csh.login                GeoIP.conf          iproute2       makedumpfile.conf.sample  pki             rc.d            ssh             updatedb.conf
audisp                   dbus-1                   GeoIP.conf.default  issue          man_db.conf               plymouth        rc.local        ssl             vconsole.conf
audit                    default                  gnupg               issue.net      mke2fs.conf               pm              redhat-release  statetab        virc
bash_completion.d        depmod.d                 GREP_COLORS         kdump.conf     modprobe.d                polkit-1        resolv.conf     statetab.d      vmware-tools
bashrc                   dhcp                     groff               kernel         modules-load.d            popt.d          rpc             subgid          wpa_supplicant
binfmt.d                 DIR_COLORS               group               krb5.conf      motd                      postfix         rpm             subuid          X11
centos-release           DIR_COLORS.256color      group-              krb5.conf.d    mtab                      ppp             rsyslog.conf    sudo.conf       xdg
centos-release-upstream  DIR_COLORS.lightbgcolor  grub2.cfg           ld.so.cache    my.cnf                    prelink.conf.d  rsyslog.d       sudoers         xinetd.d
chkconfig.d              dracut.conf              grub.d              ld.so.conf     my.cnf.d                  printcap        rwtab           sudoers.d       yum
chrony.conf              dracut.conf.d            gshadow             ld.so.conf.d   NetworkManager            profile         rwtab.d         sudo-ldap.conf  yum.conf
chrony.keys              e2fsck.conf              gshadow-            libaudit.conf  networks                  profile.d       sasl2           sysconfig       yum.repos.d
cron.d                   environment              gss                 libnl          nsswitch.conf             protocols       securetty       sysctl.conf     yum.repos.d.backup
cron.daily               ethertypes               host.conf           libuser.conf   nsswitch.conf.bak         python          security        sysctl.d
cron.deny                exports                  hostname            locale.conf    openldap                  rc0.d           selinux         systemd
cron.hourly              favicon.png              hosts               localtime      opt                       rc1.d           services        system-release
[root@centos-01 yum.repos.d]# rm -rf /etc/yum.repos.d/*
[root@centos-01 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@centos-01 yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@centos-01 yum.repos.d]# yum repolist
已加载插件:fastestmirror
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                                                                                                                             | 266 kB  00:00:00     
(2/3): epel/x86_64/primary_db                                                                                                                                           | 6.3 MB  00:00:08     
epel/x86_64/updateinfo         FAILED                                          
http://mirrors.aliyuncs.com/epel/7/x86_64/repodata/3e3bf72827ce3cbe2381f1cac087f6ff23b8bb8c2bdab06598f18057209e423e-updateinfo.xml.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(3/3): epel/x86_64/updateinfo                                                                                                                                           | 908 kB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

file is encrypted or is not a database

同样的错误提示

yum clean all

尝试yum clean all命令

[root@centos-01 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@centos-01 yum.repos.d]# yum repolist
已加载插件:fastestmirror
base                                                                                                                                                                    | 3.6 kB  00:00:00     
epel                                                                                                                                                                    | 4.7 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
(1/7): base/7/x86_64/group_gz                                                                                                                                           | 156 kB  00:00:00     
(2/7): epel/x86_64/group_gz                                                                                                                                             | 266 kB  00:00:00     
(3/7): extras/7/x86_64/primary_db                                                                                                                                       | 185 kB  00:00:00     
(4/7): epel/x86_64/updateinfo                                                                                                                                           | 908 kB  00:00:02     
(5/7): base/7/x86_64/primary_db                                                                                                                                         | 5.7 MB  00:00:16     
(6/7): epel/x86_64/primary_db                                                                                                                                           | 6.3 MB  00:00:16     
(7/7): updates/7/x86_64/primary_db                                                                                                                                      | 6.9 MB  00:00:19     
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                                                                       源名称                                                                                                      状态
base/7/x86_64                                                                CentOS-7 - Base - mirrors.aliyun.com                                                                         9,591
epel/x86_64                                                                  Extra Packages for Enterprise Linux 7 - x86_64                                                              12,469
extras/7/x86_64                                                              CentOS-7 - Extras - mirrors.aliyun.com                                                                         448
updates/7/x86_64                                                             CentOS-7 - Updates - mirrors.aliyun.com                                                                      2,417
repolist: 24,925

应该是用yum clean all就解决问题所在了,试了很多种方案,这才找到解决办法。

接着填前面的坑

[root@centos-01 yum.repos.d]# yum install -y wget
[root@centos-01 yum.repos.d]# yum provides "/*/pvcreate"
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base/7/x86_64/filelists_db                                                                                                                                              | 6.7 MB  00:00:15     
epel/x86_64/filelists_db                                                                                                                                                |  10 MB  00:00:18     
extras/7/x86_64/filelists_db                                                                                                                                            | 709 kB  00:00:02     
updates/7/x86_64/filelists_db                                                                                                                                           | 4.2 MB  00:00:10     
1:bash-completion-2.1-6.el7.noarch : Programmable completion for Bash
源    :base
匹配来源:
文件名    :/usr/share/bash-completion/completions/pvcreate



7:lvm2-2.02.171-8.el7.x86_64 : Userland logical volume management tools
源    :base
匹配来源:
文件名    :/usr/sbin/pvcreate

[root@centos-01 yum.repos.d]# yum install -y lvm2

准备物理卷

[root@centos-01 yum.repos.d]# pvcreate /dev/sdb1
  Device /dev/sdb1 not found (or ignored by filtering).
[root@centos-01 yum.repos.d]# fdisk -l /dev/sdb

磁盘 /dev/sdb:10.7 GB, 10737418240 字节,20971520 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x8e047468

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   8e  Linux LVM
/dev/sdb2         2099200     4196351     1048576   8e  Linux LVM
/dev/sdb3         4196352     6293503     1048576   8e  Linux LVM
[root@centos-01 ~]# ls /dev/sdb1
ls: 无法访问/dev/sdb1: 没有那个文件或目录

系统还没有识别/dev/sdb1,需要运行partprobe命令

[root@centos-01 yum.repos.d]# partprobe
[root@centos-01 yum.repos.d]# ls /dev/sdb1
/dev/sdb1
[root@centos-01 yum.repos.d]# cd ~
[root@centos-01 ~]# pvcreate /dev/sdb1
  Can't open /dev/sdb1 exclusively.  Mounted filesystem?

这是因为sdb还处于挂载中

[root@centos-01 ~]# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/sda3        28G  1.3G   27G    5% /
devtmpfs        479M     0  479M    0% /dev
tmpfs           489M     0  489M    0% /dev/shm
tmpfs           489M  6.7M  482M    2% /run
tmpfs           489M     0  489M    0% /sys/fs/cgroup
/dev/sdb         10G   33M   10G    1% /mnt
/dev/sda1       197M   97M  100M   50% /boot
tmpfs            98M     0   98M    0% /run/user/0
[root@centos-01 ~]# umount /mnt

[root@centos-01 ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.
[root@centos-01 ~]# pvcreate /dev/sdb2
  Physical volume "/dev/sdb2" successfully created.
[root@centos-01 ~]# pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created.
[root@centos-01 ~]# pvdisplay
  "/dev/sdb2" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb2
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               N2rza3-LP3L-xlEw-LgYZ-CSNz-04Va-DwR811

  "/dev/sdb3" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb3
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               shBIRV-N8fZ-0jDn-dna3-8AIV-bql7-lvVHMm

  "/dev/sdb1" is a new physical volume of "1.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               1.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               zOncNh-oBCu-TB1V-i2Do-TsUX-6Fak-6C9FCD

[root@centos-01 ~]# pvs
  PV         VG Fmt  Attr PSize PFree
  /dev/sdb1     lvm2 ---  1.00g 1.00g
  /dev/sdb2     lvm2 ---  1.00g 1.00g
  /dev/sdb3     lvm2 ---  1.00g 1.00g

创建卷组

[root@centos-01 ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
  Volume group "vg1" successfully created
[root@centos-01 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg1
  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               1.99 GiB
  PE Size               4.00 MiB
  Total PE              510
  Alloc PE / Size       0 / 0   
  Free  PE / Size       510 / 1.99 GiB
  VG UUID               Hlds6V-KdXd-CTVI-z6Hm-CMId-eS8a-bbRyFm
[root@centos-01 ~]# vgs
  VG  #PV #LV #SN Attr   VSize VFree
  vg1   2   0   0 wz--n- 1.99g 1.99g

创建逻辑卷

[root@centos-01 ~]# lvcreate -L 100M -n lv1 vg1
  Logical volume "lv1" created.

格式化(ext4)

[root@centos-01 ~]# mkfs.ext4 /dev/vg1/lv1 
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

挂载

[root@centos-01 ~]# mount /dev/vg1/lv1 /mnt/
[root@centos-01 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/sda3             28G  1.3G   27G    5% /
devtmpfs             479M     0  479M    0% /dev
tmpfs                489M     0  489M    0% /dev/shm
tmpfs                489M  6.7M  482M    2% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1            197M   97M  100M   50% /boot
tmpfs                 98M     0   98M    0% /run/user/0
/dev/mapper/vg1-lv1   93M  1.6M   85M    2% /mnt
[root@centos-01 ~]# ls -l /dev/vg1/lv1 
lrwxrwxrwx. 1 root root 7 412 16:55 /dev/vg1/lv1 -> ../dm-0
[root@centos-01 ~]# ls -l /dev/mapper/vg1-lv1
lrwxrwxrwx. 1 root root 7 412 16:55 /dev/mapper/vg1-lv1 -> ../dm-0
[root@centos-01 ~]# mkdir /mnt/test
[root@centos-01 ~]# touch /mnt/number.txt
[root@centos-01 ~]# echo "1234567890" > /mnt/number.txt

扩容逻辑卷(ext4)

重新设置卷大小

[root@centos-01 ~]# lvresize -L 200M /dev/vg1/lv1 
  Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
  Logical volume vg1/lv1 successfully resized.
[root@centos-01 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/sda3             28G  1.3G   27G    5% /
devtmpfs             479M     0  479M    0% /dev
tmpfs                489M     0  489M    0% /dev/shm
tmpfs                489M  6.7M  482M    2% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1            197M   97M  100M   50% /boot
tmpfs                 98M     0   98M    0% /run/user/0
/dev/mapper/vg1-lv1   93M  1.6M   85M    2% /mnt

发现已经挂载了/mnt/,这有点不符合操作。应该先卸载,再执行lvresize操作。

[root@centos-01 ~]# umount /mnt/
[root@centos-01 ~]# lvresize -L 200M /dev/vg1/lv1 
  New size (50 extents) matches existing size (50 extents).

检查磁盘错误

[root@centos-01 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3: 检查目录连接性
Pass 4: Checking reference counts
第5: 检查簇概要信息
/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8899/102400 blocks

更新逻辑卷信息

[root@centos-01 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.

重新挂载

[root@centos-01 ~]# mount /dev/vg1/lv1 /mnt/
[root@centos-01 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/sda3             28G  1.3G   27G    5% /
devtmpfs             479M     0  479M    0% /dev
tmpfs                489M     0  489M    0% /dev/shm
tmpfs                489M  6.7M  482M    2% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1            197M   97M  100M   50% /boot
tmpfs                 98M     0   98M    0% /run/user/0
/dev/mapper/vg1-lv1  190M  1.6M  175M    1% /mnt
[root@centos-01 ~]# ls /mnt/
lost+found  number.txt  test
[root@centos-01 ~]# cat /mnt/number.txt 
1234567890

原来的文件还在


缩减逻辑卷(xfs不支持)

先umount

[root@centos-01 ~]# umount /mnt/

检查磁盘错误

[root@centos-01 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3: 检查目录连接性
Pass 4: Checking reference counts
第5: 检查簇概要信息
/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11887/204800 blocks

更新逻辑卷信息

[root@centos-01 ~]# resize2fs /dev/vg1/lv1 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 102400 blocks long.

重新设置卷大小

[root@centos-01 ~]# lvresize -L 100M /dev/vg1/lv1
  WARNING: Reducing active logical volume to 100.00 MiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y
  Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
  Logical volume vg1/lv1 successfully resized.

[root@centos-01 ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                W13akI-yOkF-hHJB-sAe8-QGSy-lVKq-xUQPyp
  LV Write Access        read/write
  LV Creation host, time centos-01, 2018-04-12 20:54:44 +0800
  LV Status              available
  # open                 0
  LV Size                100.00 MiB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

[root@centos-01 ~]# lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg1 -wi-a----- 100.00m                    

重新挂载

[root@centos-01 ~]# mount /dev/vg1/lv1 /mnt/
[root@centos-01 ~]# ls /mnt/
lost+found  number.txt  test

并不会因为所容导致文件丢失,如果文件存储多于100M,那缩到100M肯定会丢失。


扩容逻辑卷(xfs)

卸载

[root@centos-01 ~]# umount /mnt/

重新格式化成xfs格式

[root@centos-01 ~]# mkfs.xfs -f /dev/vg1/lv1
meta-data=/dev/vg1/lv1           isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

挂载

[root@centos-01 ~]# mount /dev/vg1/lv1 /mnt/

[root@centos-01 ~]# ls /mnt/
[root@centos-01 ~]# touch /mnt/test.txt
[root@centos-01 ~]# echo "Outlier" > !$
echo "Outlier" > /mnt/test.txt
[root@centos-01 ~]# cat !$
cat /mnt/test.txt
Outlier

设置卷大小

[root@centos-01 ~]# lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg1 -wi-ao---- 100.00m                                                    
[root@centos-01 ~]# lvresize -L 300M /dev/vg1/lv1
  Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).
  Logical volume vg1/lv1 successfully resized.
[root@centos-01 ~]# lvs
  LV   VG  Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg1 -wi-ao---- 300.00m                                                    
[root@centos-01 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/sda3             28G  1.3G   27G    5% /
devtmpfs             479M     0  479M    0% /dev
tmpfs                489M     0  489M    0% /dev/shm
tmpfs                489M  6.7M  482M    2% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1            197M   97M  100M   50% /boot
tmpfs                 98M     0   98M    0% /run/user/0
/dev/mapper/vg1-lv1   97M  5.2M   92M    6% /mnt

执行分区调整

[root@centos-01 ~]# xfs_growfs /dev/vg1/lv1
meta-data=/dev/mapper/vg1-lv1    isize=512    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=855, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 25600 to 76800
[root@centos-01 ~]# df -h
文件系统             容量  已用  可用 已用% 挂载点
/dev/sda3             28G  1.3G   27G    5% /
devtmpfs             479M     0  479M    0% /dev
tmpfs                489M     0  489M    0% /dev/shm
tmpfs                489M  6.7M  482M    2% /run
tmpfs                489M     0  489M    0% /sys/fs/cgroup
/dev/sda1            197M   97M  100M   50% /boot
tmpfs                 98M     0   98M    0% /run/user/0
/dev/mapper/vg1-lv1  297M  5.5M  292M    2% /mnt

扩展卷组

[root@centos-01 ~]# pvs
  PV         VG  Fmt  Attr PSize    PFree   
  /dev/sdb1  vg1 lvm2 a--  1020.00m  720.00m
  /dev/sdb2  vg1 lvm2 a--  1020.00m 1020.00m
  /dev/sdb3      lvm2 ---     1.00g    1.00g

[root@centos-01 ~]# vgextend vg1 /dev/sdb3
  Volume group "vg1" successfully extended
[root@centos-01 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg1
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               <2.99 GiB
  PE Size               4.00 MiB
  Total PE              765
  Alloc PE / Size       75 / 300.00 MiB
  Free  PE / Size       690 / <2.70 GiB
  VG UUID               x4rfdo-Aw9n-fYIH-BIJm-BCit-U0Bk-lOxtvO

[root@centos-01 ~]# vgs
  VG  #PV #LV #SN Attr   VSize  VFree 
  vg1   3   1   0 wz--n- <2.99g <2.70g
<think>我们被要求提供LVM常用命令及使用指南。根据引用内容,LVM逻辑卷管理)是Linux中一种灵活的存储管理方式,它允许我们创建、调整大小、删除存储空间,而无需重新分区磁盘。LVM的主要件包括物理卷(PV)、卷(VG)和逻辑卷(LV)。 我们将按照以下步骤织回答: 1. LVM基本概念和件 2. LVM常用命令(创建、扩展、删除等) 3. 实际使用示例 4. 注意事项 同时,根据引用内容,我们还会提供一些相关问题的建议。 注意:在回答中,我们会引用提供的参考内容,并在适当位置添加引用标识。 开始回答: # LVM 常用命令及使用指南 LVM(Logical Volume Manager)是Linux环境下对磁盘分区进行管理的一种机制。它通过将底层物理磁盘抽象化,使得用户能够动态调整存储空间。LVM的核心概念包括: - **物理卷(Physical Volume, PV)**:物理卷可以是整个硬盘、硬盘分区或者已经创建好的软RAID设备。它是LVM的基本存储单元。 - **卷(Volume Group, VG)**:卷由一个或多个物理卷成,形成一个存储池。卷可以被划分成多个逻辑卷。 - **逻辑卷(Logical Volume, LV)**:逻辑卷建立在卷之上,它类似于传统分区,但可以动态调整大小。逻辑卷可以被格式化并挂载到文件系统上。 - **物理扩展块(Physical Extent, PE)**:每个物理卷被划分为大小相等的块,称为物理扩展块。它是LVM分配存储空间的最小单位,大小通常为4MB(默认值,可调整)[^3]。 ## 常用命令 ### 1. 物理卷(PV)管理 - 创建PV:`pvcreate [设备名]` 例如:将`/dev/sdb1`和`/dev/sdc1`初始化为物理卷: ```bash pvcreate /dev/sdb1 /dev/sdc1 ``` - 查看PV信息:`pvdisplay` 或 `pvs` - 删除PV:`pvremove [设备名]` 例如:删除物理卷`/dev/sdb1`: ```bash pvremove /dev/sdb1 ``` ### 2. 卷(VG)管理 - 创建VG:`vgcreate [卷名] [物理卷]` 例如:使用`/dev/sdb1`和`/dev/sdc1`创建名为`vgname1`的卷: ```bash vgcreate vgname1 /dev/sdb1 /dev/sdc1 ``` - 扩展VG:`vgextend [卷名] [新物理卷]` 例如:将`/dev/sdd1`添加到`vgname1`卷: ```bash vgextend vgname1 /dev/sdd1 ``` - 查看VG信息:`vgdisplay` 或 `vgs` - 删除VG:`vgremove [卷名]` 例如:删除卷`vgname1`: ```bash vgremove vgname1 ``` ### 3. 逻辑卷(LV)管理 - 创建LV:`lvcreate -L [大小] -n [逻辑卷名] [卷名]` 例如:在卷`vgname1`上创建20G大小的逻辑卷`lvname1`: ```bash lvcreate -L 20G -n lvname1 vgname1 ``` - 扩展LV:`lvextend -L +[扩展大小] /dev/[卷名]/[逻辑卷名]` 例如:将逻辑卷`lvname1`扩展10G: ```bash lvextend -L +10G /dev/vgname1/lvname1 ``` **注意**:扩展逻辑卷后,文件系统也需要扩展。对于XFS文件系统,使用`xfs_growfs`;对于EXT4文件系统,使用`resize2fs`[^3]: ```bash # 对于XFS xfs_growfs /dev/vgname1/lvname1 # 对于EXT4 resize2fs /dev/vgname1/lvname1 ``` - 查看LV信息:`lvdisplay` 或 `lvs` - 删除LV:`lvremove /dev/[卷名]/[逻辑卷名]` 例如:删除逻辑卷`lvname1`: ```bash lvremove /dev/vgname1/lvname1 ``` ### 4. 文件系统操作 - 格式化LV:使用`mkfs`命令,例如格式化为XFS: ```bash mkfs.xfs /dev/vgname1/lvname1 ``` - 挂载LV:创建挂载点并挂载 ```bash mkdir /opt/mydata mount /dev/vgname1/lvname1 /opt/mydata ``` - 卸载LV:`umount [挂载点]` ```bash umount /opt/mydata ``` ## 实际使用示例 ### 创建LVM逻辑卷并扩展 1. 使用`gdisk`或`fdisk`为磁盘(如`/dev/sdb`和`/dev/sdc`)创建分区(类型设置为Linux LVM,代码8e00)。 2. 创建PV: ```bash pvcreate /dev/sdb1 /dev/sdc1 ``` 3. 创建VG: ```bash vgcreate vgname1 /dev/sdb1 /dev/sdc1 ``` 4. 创建LV: ```bash lvcreate -L 20G -n lvname1 vgname1 ``` 5. 格式化并挂载: ```bash mkfs.xfs /dev/vgname1/lvname1 mount /dev/vgname1/lvname1 /opt ``` 6. 扩展逻辑卷(当需要增加空间时): ```bash # 扩展VG(如果需要) vgextend vgname1 /dev/sdd1 # 扩展LV lvextend -L +10G /dev/vgname1/lvname1 # 刷新文件系统 xfs_growfs /dev/vgname1/lvname1 # 或使用resize2fs ``` ## 注意事项 - 在删除LVM件时,顺序应为:先卸载并删除逻辑卷(LV),再删除卷(VG),最后删除物理卷(PV)[^3]。 - 扩展文件系统前,确保逻辑卷已扩展。对于XFS文件系统,只能在挂载状态下扩展,而EXT4可以在挂载或卸载状态下扩展。 - 备份重要数据:虽然LVM提供了灵活性,但操作失误可能导致数据丢失,建议操作前备份。 LVM 提供了灵活的存储管理方式,掌握其常用命令和操作流程对于系统管理员至关重要[^1][^2]。 ## 相关问题 1. LVM 快照(Snapshot)的创建和使用方法? 2. 如何迁移物理卷(PV)上的数据? 3. LVM 与 RAID 结合使用有哪些常见方案? 4. LVM 的元数据损坏如何修复? [^1]:37、存储管理与灾难恢复:LVM 及故障恢复指南 [^2]:Linux 中的逻辑卷 LVM 管理完整初学者指南 [^3]:Linux磁盘管理与文件系统、LVM逻辑卷管理及实战指南 [^4]:46.逻辑卷管理1,lvm架构,概念,常用命令介绍</think>### LVM 常用命令及使用指南 LVM逻辑卷管理)是 Linux 中用于动态管理磁盘空间的工具,通过抽象物理存储为逻辑卷,实现灵活的空间分配和调整。以下是核心概念和常用命令详解: --- #### **一、核心概念** 1. **物理卷(PV)**:磁盘分区或整块磁盘(如 `/dev/sdb1`)。 2. **卷(VG)**:多个 PV 的集合,形成存储池(如 `vgname1`)。 3. **逻辑卷(LV)**:从 VG 划分出的逻辑空间(如 `/dev/vgname1/lvname1`),可格式化为文件系统。 4. **物理扩展块(PE)**:VG 的最小存储单元(默认 4MB,影响 VG 最大容量)[^3]。 --- #### **二、常用命令及操作流程** ##### **1. 创建 LVM** ```bash # 初始化物理卷(PV) pvcreate /dev/sdb1 /dev/sdc1 # 创建卷(VG) vgcreate vgname1 /dev/sdb1 /dev/sdc1 # 创建逻辑卷(LV),分配 20GB lvcreate -L 20G -n lvname1 vgname1 # 格式化并挂载 mkfs.xfs /dev/vgname1/lvname1 # 或 mkfs.ext4 mount /dev/vgname1/lvname1 /opt ``` ##### **2. 扩展 LVM** ```bash # 扩展 VG(添加新 PV) vgextend vgname1 /dev/sdd1 # 扩展 LV 容量(增加 10GB) lvextend -L +10G /dev/vgname1/lvname1 # 刷新文件系统(根据类型选择) xfs_growfs /dev/vgname1/lvname1 # XFS 文件系统 resize2fs /dev/vgname1/lvname1 # EXT4 文件系统 ``` ##### **3. 删除 LVM** ```bash # 卸载并删除 LV umount /opt lvremove /dev/vgname1/lvname1 # 删除 VG 和 PV vgremove vgname1 pvremove /dev/sdb1 /dev/sdc1 ``` ##### **4. 查看信息** ```bash pvs # 查看物理卷 vgs # 查看卷 lvs # 查看逻辑卷 pvdisplay # 显示 PV 详细信息 vgdisplay # 显示 VG 详细信息 lvdisplay # 显示 LV 详细信息 ``` ##### **5. 缩减 LVM(谨慎操作)** ```bash # 卸载并检查文件系统 umount /opt e2fsck -f /dev/vgname1/lvname1 # EXT4 检查 # 缩减文件系统后再缩减 LV resize2fs /dev/vgname1/lvname1 15G # 缩至 15GB lvreduce -L 15G /dev/vgname1/lvname1 ``` --- #### **三、实战示例** **场景**:将 `/dev/sdb` 和 `/dev/sdc` 合并为 VG,创建 LV 并扩展: 1. 分区并设置类型为 `Linux LVM`(使用 `gdisk` 或 `fdisk`)。 2. 创建 PV、VG 和 LV: ```bash pvcreate /dev/sdb1 /dev/sdc1 vgcreate datavg /dev/sdb1 /dev/sdc1 lvcreate -L 50G -n datalv datavg mkfs.ext4 /dev/datavg/datalv mount /dev/datavg/datalv /data ``` 3. 扩展空间(添加新磁盘 `/dev/sdd1`): ```bash vgextend datavg /dev/sdd1 lvextend -L +20G /dev/datavg/datalv resize2fs /dev/datavg/datalv ``` --- #### **四、注意事项** 1. **备份数据**:操作前务必备份,误删 LV 可能导致数据丢失。 2. **文件系统兼容性**: - XFS 不支持缩减,仅能扩展[^3]。 - EXT4 可扩展/缩减,但需卸载后操作。 3. **PE 大小规划**:创建 VG 时指定 PE 大小(如 `-s 64M`),影响最大 LV 容量。 4. **故障恢复**:超级块损坏时,可用 `xfs_repair` 或 `fsck` 修复[^1]。 > LVM 提供了灵活的存储管理方式,而掌握故障恢复方法能保障数据安全和系统稳定运行[^1]。 --- ### 相关问题 1. **如何备份和恢复 LVM 逻辑卷?** 2. **LVM 快照(Snapshot)的原理及使用场景是什么?** 3. **如何将传统分区迁移到 LVM 逻辑卷?** 4. **LVM 与 RAID 结合使用时有哪些最佳实践?** [^1]:37、存储管理与灾难恢复:LVM 及故障恢复指南 [^2]:Linux 中的逻辑卷 LVM 管理完整初学者指南 [^3]:Linux磁盘管理与文件系统、LVM逻辑卷管理及实战指南 [^4]:46.逻辑卷管理1,lvm架构,概念,常用命令介绍
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Uri · Boyka

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

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

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

打赏作者

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

抵扣说明:

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

余额充值