http://dreamfire.blog.51cto.com/418026/1084729/
http://os.51cto.com/art/201409/450584.htm
对硬盘分区
sudo fdisk /dev/sdb
m 帮助
l 有8e可选
n 新建
p 主分区
回车 默认开始 n之后直接回车默认从1开始
+5G 设置大小为5G last
t #改变格式
1 选择为sdb1
8e # LVM格式
p #打印查看
w #保存
到这里/dev/就会多出几个sdbX 如果找不到就运行partprobe进行不关机重新读取分区表
上面操作是对sdb1和sdb2进行lvm格式操作
pvcreate /dev/sdb{1,2} #创建物理卷
vgcreate zzxvg /dev/sdb{1,2} #创建卷组 把两个物理卷组成一个卷组
lvcreate -L +1G -n zzxlv1 zzxvg #把卷组 zzxvg 中 创建 一个大小为1G的 逻辑卷 zzxlv1 剩下的空间还可以接着创建逻辑卷 之后这些逻辑卷的大小可以互相增减
mkfs.ext2 /dev/zzxvg/zzxlv1 #格式化逻辑卷
增加空间
resize2fs /dev/mapper/mVG-appdata(否则df -h还是不变)
vgextend VolGroup00 /dev/hda6 #扩展卷组VolGroup00 添加dha6这个划分好的pv到卷组VolGroup00
lvdisplay #查看已经存在的LV信息,以存在LV:LogVol01为例
lvextend –L 1G /dev/VolGroup00/LogVol01 #扩展LV(加-r 就不用下面那一句了)
resize2fs /dev/VolGroup00/LogVol01 #执行该重设大小,对于当前正在使用的LogVol01有效
df –h #查看挂载情况,已经扩容
vgextent datavg /dev/sdb2 # 扩容vg
lvextent -L +38G -f -r /dev/mapper/datavg-lv_appdata
/dev/datavg/lv_appdata
df-h
xfs不能动态减小lvreduce 加了-r会提示无法减小如果不加-r就会减小不过还是报错,就要卸载再强制格式化 mkfs.xfs -f /dev/mapper/myvg-appdata 后再挂载
所以xfs可以把磁盘数据拷贝出来,然后lvreduce 不加-r
[root@nmserver-7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 5.8G 42G 12% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 489M 7.2M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
tmpfs 98M 32K 98M 1% /run/user/1000
/dev/sda1 297M 141M 156M 48% /boot
/dev/mapper/myvg-appdata 11G 33M 11G 1% /appdata
[root@nmserver-7 ~]# lvreduce -L -3G -f -r /dev/mapper/myvg-appdata
fsadm: Xfs filesystem shrinking is unsupported.
/usr/sbin/fsadm failed: 1
Filesystem resize failed.
[root@nmserver-7 ~]# lvreduce -L -3G -f /dev/mapper/myvg-appdata
WARNING: Reducing active and open logical volume to 8.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Size of logical volume myvg/appdata changed from 11.00 GiB (2816 extents) to 8.00 GiB (2048 extents).
Logical volume myvg/appdata successfully resized.
[root@nmserver-7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 5.8G 42G 12% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 489M 7.2M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
tmpfs 98M 32K 98M 1% /run/user/1000
/dev/sda1 297M 141M 156M 48% /boot
/dev/mapper/myvg-appdata 11G 33M 11G 1% /appdata
[root@nmserver-7 ~]# resize2fs /dev/mapper/myvg-appdata
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/myvg-appdata
Couldn't find valid filesystem superblock.
[root@nmserver-7 ~]# cd /appdata/
[root@nmserver-7 appdata]# ll
total 0
[root@nmserver-7 appdata]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 5.8G 42G 12% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 489M 7.2M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
tmpfs 98M 32K 98M 1% /run/user/1000
/dev/sda1 297M 141M 156M 48% /boot
/dev/mapper/myvg-appdata 11G 33M 11G 1% /appdata
[root@nmserver-7 appdata]# umount /appdata/
umount: /appdata: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@nmserver-7 appdata]# umount -f /appdata/
umount: /appdata: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@nmserver-7 appdata]# fuser -uv /appdata/
USER PID ACCESS COMMAND
/appdata: root kernel mount (root)/appdata
root 2384 ..c.. (root)bash
[root@nmserver-7 appdata]# ps -ef|grep 2384
root 2384 2362 0 22:43 pts/0 00:00:03 -bash
root 3529 2384 0 23:11 pts/0 00:00:00 ps -ef
root 3530 2384 0 23:11 pts/0 00:00:00 grep --color=auto 2384
[root@nmserver-7 appdata]# kill -15 2384
[root@nmserver-7 appdata]# ps -ef|grep 2384
root 2384 2362 0 22:43 pts/0 00:00:03 -bash
root 3531 2384 0 23:12 pts/0 00:00:00 ps -ef
root 3532 2384 0 23:12 pts/0 00:00:00 grep --color=auto 2384
[root@nmserver-7 appdata]# kill -9 2384
Connection closed by foreign host.
Disconnected from remote host(192.168.67.135:22) at 14:12:20.
Type `help' to learn how to use Xshell prompt.
[c:~]$ ssh root@192.168.67.135
Connecting to 192.168.67.135:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Sat Mar 31 22:43:52 2018 from 192.168.67.1
[root@nmserver-7 ~]# umount /appdata/
[root@nmserver-7 ~]# xfs_repair /dev/mapper/myvg-appdata
Phase 1 - find and verify superblock...
error reading superblock 3 -- seek to offset 8858370048 failed
couldn't verify primary superblock - attempted to perform I/O beyond EOF !!!
attempting to find secondary superblock...
.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................found candidate secondary superblock...
verified secondary superblock...
writing modified primary superblock
xfs_repair: error - read only 0 of 512 bytes
[root@nmserver-7 ~]# mount /dev/mapper/myvg-appdata /appdata/
mount: /dev/mapper/myvg-appdata: can't read superblock
[root@nmserver-7 ~]# mkfs.xfs /dev/mapper/myvg-appdata
mkfs.xfs: /dev/mapper/myvg-appdata appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@nmserver-7 ~]# mkfs.xfs -f /dev/mapper/myvg-appdata
meta-data=/dev/mapper/myvg-appdata isize=512 agcount=4, agsize=524288 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2097152, 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
[root@nmserver-7 ~]# mount /dev/mapper/myvg-appdata /appdata/
[root@nmserver-7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 48G 5.8G 42G 12% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 489M 7.2M 482M 2% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
tmpfs 98M 32K 98M 1% /run/user/1000
/dev/sda1 297M 141M 156M 48% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/myvg-appdata 8.0G 33M 8.0G 1% /appdata