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 4月 12 16:55 /dev/vg1/lv1 -> ../dm-0
[root@centos-01 ~]# ls -l /dev/mapper/vg1-lv1
lrwxrwxrwx. 1 root root 7 4月 12 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