linux基础学习-第十五天 磁盘管理(SWAPddquotaRAIDLVM)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux基础学习-第十五天 磁盘管理(SWAPddquotaRAIDLVM)相关的知识,希望对你有一定的参考价值。
2016-08-26:
授课内容:
1、SWAP交换分区的创建
2、dd命令的使用
3、设定文件系统配额
4、设定和管理软RAID设备
5、配置逻辑卷
1、swap
(1)SWAP分区:模拟内存,当物理内存不足时,进程需要内存资源是,内存会把一部分没有在用的进程分页挪到硬盘的模拟内存中,腾出空间被现在需要使用内存资源的进程
即其作用是可以允许内存过载使用,windows系统也有类似的机制,由于虚拟内存空间是建立在硬盘之上,所以其速度和性能会大打折扣,所以适合临时使用
(2)创建SWAP分区:
相关命令:mkswap、swapon
示例:
[19:42 [email protected]/usr/local/http2]# fdisk /dev/sda 【创建分区】 WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): n First cylinder (9460-26109, default 9460): Using default value 9460 Last cylinder, +cylinders or +size{K,M,G} (9460-26109, default 26109): +2G Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext‘d (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Hex code (type L to list codes): 82 【选择swap模式】 Changed system type of partition 6 to 82 (Linux swap / Solaris) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 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) Syncing disks. [19:43 [email protected]/usr/local/http2]# mkswap /dev/sda6 【格式化交换分区】 Setting up swapspace version 1, size = 2100024 KiB no label, UUID=ae9d3eee-1908-47fe-9b32-2a777d0b28b1 [19:43 [email protected]/usr/local/http2]# swapon -a 【挂载swap】 [19:44 [email protected]/usr/local/http2]# free 【查看已经挂载成功】 total used free shared buffers cached Mem: 1907300 1059764 847536 1336 65000 724408 -/+ buffers/cache: 270356 1636944 Swap: 4095996 0 4095996 [19:44 [email protected]/usr/local/http2]# cat /proc/swaps FilenameTypeSizeUsedPriority /dev/sda5 partition40959960-1
2、dd命令的使用;
dd:convert and copy a file,转换并复制文件,与cp命令相似,只是用法格式有不一样,dd复制的是数据流,工作在vfs之下
用法:
dd if=/PATH/FROM/SRC of=/PATH/TO/DEST bs=#:block size, 复制单元大小 count=#:复制多少个bs
of=file写到所命名的文件而不是到标准输出
if=file从所命名文件读取而不是从标准输入
bs=size指定块大小(既是是ibs也是obs)
ibs=size一次读size个byte
obs=size 一次写size个byte
cbs=size 一次转化size个byte
skip=blocks从开头忽略blocks个ibs大小的块
seek=blocks从开头忽略blocks个obs大小的块
count=n只拷贝n个记录
cbs=size 一次转换多少byte
说明:
磁盘拷贝:
dd if=/dev/sda of=/dev/sdb
备份MBR:
dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1
破坏MBR中的bootloader:
dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446
有一个大与2K的二进制文件fileA。现在想从第64个字节位置开始读取,需要读取的大小是128Byts。又有fileB, 想把上面读取到的128Bytes写到第32个字节开始的位置,替换128Bytes,请问如何实现?
dd if=fileA of=fileB bs=1 count=128 skip=63 seek=31 conv=notrunc
备份:
dd if=/dev/sdx of=/dev/sdy
将本地的/dev/sdx整盘备份到/dev/sdy
dd if=/dev/sdx of=/path/to/image
将/dev/sdx全盘数据备份到指定路径的image文件
dd if=/dev/sdx | gzip >/path/to/image.gz
备份/dev/sdx全盘数据,并利用gzip工具进行压缩,保存到指定路径
恢复:
dd if=/path/to/image of=/dev/sdx
将备份文件恢复到指定盘
gzip -dc /path/to/image.gz | dd of=/dev/sdx
将压缩的备份文件恢复到指定盘
3、文件系统配额:以文件系统(分区)为单位启用
分区配额管理:在一个分区内进行管理
(1)、启用磁盘配额:
分区挂载选项(在fstab修改挂载属性:usrquota,grpquota):
usrquota:控制单个用户
grpquota:控制组用户
(2)、创建配额数据库
quotacheck -cug /filesystem 成功后会在文件系统有两个aquota的文件
[[email protected] home]# ll total 36 -rw-------. 1 root root 7168 Aug 26 15:04 aquota.group -rw-------. 1 root root 7168 Aug 26 15:04 aquota.user drwxr-xr-x. 4 hill root 4096 Aug 26 15:00 hill drwx------. 2 root root 16384 Aug 26 14:50 lost+found [[email protected] home]# getenforce Enforcing [[email protected] home]# setenforce 0 [[email protected] home]# getenforce Permissive
(3)、启用
quotaon /filesystem
(4)、设置用户配额:
edqupta USERNAME
根据文件所有者来定义用户使用了多大
(5)、查看、测试
[[email protected] home]# repquota -a *** Report for user quotas on device /dev/sda6 Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 141468 0 0 4 0 0 hill -- 36 50000 60000 9 0 0
4、RAID:(raid的最小存储单位是chunk,即每次平均分到物理磁盘的大小)
(1)RAID:Redundant Array of Inexpensive Disks:廉价磁盘冗余阵列
:Redundant Array of Independent Disks:独立磁盘冗余阵列
【注意】:由于在用户层面看来,raid组成一块磁盘,所以要对磁盘进行分区、格式化才能使用
(2)RAID级别:仅代表磁盘组织方式不同,没有上下之分;
0: 条带
性能提升: 读,写
冗余能力(容错能力): 无
空间利用率:nS
至少2块盘
1: 镜像
性能表现:写性能下降,读性能提升
冗余能力:有
空间利用率:1/2
至少2块盘
2
3
4:
5: 带基偶校验位
性能表现:读,写提升
冗余能力:有
空间利用率:(n-1)/n
至少需要3块
10:
性能表现:读、写提升
冗余能力:有
空间利用率:1/2
至少需要4块
01:
性能表现:读、写提升
冗余能力:有
空间利用率:1/2
至少需要4块
50:
性能表现:读、写提升
冗余能力:有
空间利用率:(n-2)/n
至少需要6块
jbod:
性能表现:无提升
冗余能力:无
空间利用率:100%
至少需要2块
(3)实现RAID方式:
硬RAID(实际生产环节):
外接专门的存储机箱,机箱里接上多个硬盘
Bios中进行设置
软RAID(系统演示环节,并不建议在生产环节使用):mdadm
RAID设备(软raid)可命名为/dev/md0、/dev/md1、/dev/md2、/dev/md3等等
(4)软件raid
命令的语法格式:mdadm[mode] <raiddevice> [options] <component-devices>
模式:
创建:-C
装配: -A
监控: -F
管理:-f, -r, -a
<raiddevice>: /dev/md#
<component-devices>: 任意块设备
-C: 创建模式
-n #: 使用#个块设备来创建此RAID
-l #:指明要创建的RAID的级别
-a {yes|no}:自动创建目标RAID设备的设备文件
-c CHUNK_SIZE: 指明块大小
-x #: 指明空闲盘的个数
-D:显示raid的详细信息;
mdadm -D /dev/md#
管理模式:
-f: 标记指定磁盘为损坏
-a: 添加磁盘
-r: 移除磁盘
观察md的状态:
cat /proc/mdstat
使用mdadm创建并定义RAID设备
#mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
用文件系统对每个RAID设备进行格式化
#mke2fs -j /dev/md0
测试RAID设备
使用mdadm检查RAID设备的状况
#mdadm --detail|D /dev/md0
增加新的成员
#mdadm –G /dev/md0 –n4 -a /dev/sdf1
模拟磁盘故障
#mdadm /dev/md0 -f /dev/sda1
移除磁盘
#mdadm /dev/md0 –r /dev/sda1
从软件RAID磁盘修复磁盘故障
替换出故障的磁盘然后开机
在备用驱动器上重建分区
#mdadm /dev/md0 -a /dev/sda1
5、逻辑卷管理器(LVM)【最小的存储单位PE(Physical Extend)】
(1)允许在多个物理设备间重新组织文件系统
LVM可以弹性的更改LVM的容量:通过交换PE来进行资料的转换,将原来LV内的PE转移到其他的设备中以降低LV的容量,或将其他设备中的PE加到LV中以加大容量
(2)LVM管理分为三层来管理:
LV(logical volume)
VG(volume group)
PV(physical volume)
创建LV逻辑卷的过程:要先把物理磁盘创建为物理卷PV,再由多个物理卷创建为卷组VG(相当于扩展分区的概念,不能直接使用),再在VG卷组上创建需要的逻辑卷LV
(3)相关命令(相似):
PV:pvcreate、pvremove、pvmove、pvextend、pvdisplay
VG:vgcreate、vgreduce、vgextend、vgdisplay
LV:lvcreate、lvremove、lvextend、lvdisplay
pv管理工具
显示pv信息
pvs:简要pv信息显示
pvdisplay
创建pv
pvcreate /dev/DEVICE
vg管理工具
显示卷组
vgs
vgdisplay
创建卷组
vgcreate [-s #[kKmMgGtTpPeE]] VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
管理卷组
vgextend VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
vgreduce VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
删除卷组
先做pvmove,再做vgremove
lv管理工具
显示逻辑卷
lvs
Lvdisplay
创建逻辑卷
lvcreate-L #[mMgGtT] -n NAME VolumeGroup
删除逻辑卷
lvremove/dev/VG_NAME/LV_NAME
重设文件系统大小
fsadm[options] resize device [new_size[BKMGTEP]]
resize2fs [-f] [-F] [-M] [-P] [-p] device [new_size]
实例:创建LV过程:
简述: 一、分区
fdisk /dev/sda t 8e
partx -a /dev/sda
lsblk
2、
pvcreate /dev/sd{a7,b}
pvs
pvdisplay
3、
vgcreate vg0 /dev/sd{a7,b}
vgs;pvs;pvdisplay;vgdisplay
4、lvcreate -n lv0 -L 10G vg0
5、mkfs.ext4 /dev/vg0/lv0
6、
vi /etc/fstab
mkdir /mnt/lv0;mount -a
二、扩展逻辑卷lv(可以在没有卸载的情况下进行扩展)
1、lvdisplay
2、lvextend -L +1G /dev/vg0/lv0
3、resize2fs /dev/vg0/lv0
4、lvdisplay
三、扩展卷组VG
1、vgdisplay
2、pvcreat /dev/sdb
3、vgextend vg0 /dev/sdb
四、缩减逻辑卷
注意:1、不能在线缩减,得先卸载;
2、确保缩减后的空间大小依然能存储原有的所有数据;
3、在缩减之前应该先强行检查文件,以确保文件系统处于一至性状态;
df -lh
umount
e2fsck -f
resize2fs /PATH/TO/PV 3G
lvreduce -L [-]# /PATH/TO/LV
mount
1、创建LV
[16:18 [email protected]~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): t Partition number (1-8): 8 Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext‘d (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Hex code (type L to list codes): 8e Changed system type of partition 8 to 8e (Linux LVM) Command (m for help): t Partition number (1-8): 7 Hex code (type L to list codes): 8e Changed system type of partition 7 to 8e (Linux LVM) Command (m for help): t Partition number (1-8): 6 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000e82d5 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 6400 51200000 83 Linux /dev/sda3 6400 8950 20480000 83 Linux /dev/sda4 8950 26109 137829376 5 Extended /dev/sda5 8950 9460 4096000 82 Linux swap / Solaris /dev/sda6 9460 9721 2100029 8e Linux LVM /dev/sda7 9722 9983 2104483+ 8e Linux LVM /dev/sda8 9984 10376 3156741 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 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) Syncing disks. [16:18 [email protected]~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 BLKPG: Device or resource busy error adding partition 8 [16:19 [email protected]~]# pvdisplay [16:19 [email protected]~]# pvcreate /dev/sda{6,7,8} Physical volume "/dev/sda6" successfully created Physical volume "/dev/sda7" successfully created Physical volume "/dev/sda8" successfully created [16:20 [email protected]~]# pvdisplay "/dev/sda6" is a new physical volume of "2.00 GiB" --- NEW Physical volume --- PV Name /dev/sda6 VG Name PV Size 2.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID OcC0N8-Ojcf-6oPq-gvaS-Dny2-JVs4-Lds51R "/dev/sda7" is a new physical volume of "2.01 GiB" --- NEW Physical volume --- PV Name /dev/sda7 VG Name PV Size 2.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID amnydg-48Qm-tIZs-ZXnp-ngWA-4Fuk-6k53TP "/dev/sda8" is a new physical volume of "3.01 GiB" --- NEW Physical volume --- PV Name /dev/sda8 VG Name PV Size 3.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID mir8t7-yoTX-1pAD-A6bA-Gl4U-JYLe-pSmPSc [16:20 [email protected]~]# vgdisplay [16:20 [email protected]~]# vgcreate vg0 /dev/sda{6,7,8} Volume group "vg0" successfully created [16:20 [email protected]~]# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 3 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 3 Act PV 3 VG Size 7.01 GiB PE Size 4.00 MiB Total PE 1795 Alloc PE / Size 0 / 0 Free PE / Size 1795 / 7.01 GiB VG UUID OXd09k-uQ7C-BMNr-gkeY-HeQv-NJnP-H9WWxQ [16:20 [email protected]~]# lvdisplay [16:21 [email protected]~]# lvcreate -n lv0 -L 5G vg0 Logical volume "lv0" created. [16:21 [email protected]~]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [16:22 [email protected]~]# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 7.01 GiB PE Size 4.00 MiB Total PE 1795 Alloc PE / Size 1280 / 5.00 GiB Free PE / Size 515 / 2.01 GiB VG UUID OXd09k-uQ7C-BMNr-gkeY-HeQv-NJnP-H9WWxQ [16:25 [email protected]~]# mke2fs -j /dev/vg0/lv0 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [16:26 [email protected]~]# mkdir /mnt/lv0 [16:26 [email protected]~]# mount /dev/vg0/lv0 /mnt/lv0/ [16:26 [email protected]~]# mo modem-manager mogrify mount.cifs mountpoint mozilla-plugin-config modinfo montage mount.fuse mountstats modprobe more mount.nfs mount.tmpfs modutil mount mount.nfs4 mousetweaks
2、 扩展逻辑卷(要在挂载状态执行resize2fs)
[16:28 [email protected]/mnt/lv0]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 1 LV Size 5.00 GiB Current LE 1280 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [16:36 [email protected]/mnt/lv0]# lvextend -L +1G /dev/vg0/lv0 Size of logical volume vg0/lv0 changed from 5.00 GiB (1280 extents) to 6.00 GiB (1536 extents). Logical volume lv0 successfully resized. [16:36 [email protected]/mnt/lv0]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 1 LV Size 6.00 GiB Current LE 1536 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [16:36 [email protected]/mnt/lv0]# resize2fs /dev/vg0/lv0 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg0/lv0 is mounted on /mnt/lv0; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/vg0/lv0 to 1572864 (4k) blocks. The filesystem on /dev/vg0/lv0 is now 1572864 blocks long. [16:37 [email protected]/mnt/lv0]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 50264772 4865484 42839288 11% / tmpfs 953648 72 953576 1% /dev/shm /dev/sda1 194241 39020 144981 22% /boot /dev/sda3 20027260 44996 18958264 1% /testdir /dev/mapper/vg0-lv0 6192704 141436 5736708 3% /mnt/lv0
3、扩展卷组
[16:58 [email protected]/mnt/lv0]# pvcreate /dev/sda9 Physical volume "/dev/sda9" successfully created [16:58 [email protected]/mnt/lv0]# vgextend vg0 /dev/sda9 Volume group "vg0" successfully extended [16:58 [email protected]/mnt/lv0]# vgdisplay --- Volume group --- VG Name vg0 System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 4 Act PV 4 VG Size 9.02 GiB PE Size 4.00 MiB Total PE 2308 Alloc PE / Size 1536 / 6.00 GiB Free PE / Size 772 / 3.02 GiB VG UUID OXd09k-uQ7C-BMNr-gkeY-HeQv-NJnP-H9WWxQ
4、缩减逻辑卷
没有做文件系统检测和resize2fs,直接缩减,会使原来逻辑卷的数据损坏:
[17:28 [email protected]~]# ll /mnt/lv0/ total 20 -rw-rw-r--. 1 hill hill 0 Aug 27 17:23 f1 drwx------. 2 root root 16384 Aug 27 16:26 lost+found drwxr-xr-x. 2 hill hill 4096 Aug 27 17:24 pam.d [19:00 [email protected]~]# umount /mnt/lv0/ [19:00 [email protected]~]# lvreduce -L 3G /dev/vg0/lv0 WARNING: Reducing active logical volume to 3.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/lv0? [y/n]: y Size of logical volume vg0/lv0 changed from 7.00 GiB (1792 extents) to 3.00 GiB (768 extents). Logical volume lv0 successfully resized. [19:05 [email protected]~]# cd /mnt/lv0/ [19:05 [email protected]/mnt/lv0]# ll ls: cannot access pam.d: Input/output error total 16 -rw-rw-r--. 1 hill hill 0 Aug 27 17:23 f1 drwx------. 2 root root 16384 Aug 27 16:26 lost+found d?????????? ? ? ? ? ? pam.d [19:05 [email protected]/mnt/lv0]# cd pam.d -bash: cd: pam.d: Input/output error [19:05 [email protected]/mnt/lv0]#
正确步骤:
[19:20 [email protected]~]# umount /mnt/lv0/ #先卸载 [19:21 [email protected]~]# e2fsck -f /dev/vg0/lv0 #对文件系统进行强制检测 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg0/lv0: 12/327680 files (0.0% non-contiguous), 38512/1310720 blocks [19:21 [email protected]~]# resize2fs /dev/vg0/lv0 3G #物理先调整文件系统大小 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg0/lv0 to 786432 (4k) blocks. The filesystem on /dev/vg0/lv0 is now 786432 blocks long. [19:22 [email protected]~]# lvdisplay #查看缩减前的LV大小 --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [19:22 [email protected]~]# lvreduce -L 3G /dev/vg0/lv0 #缩减LV大小 WARNING: Reducing active logical volume to 3.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vg0/lv0? [y/n]: y Size of logical volume vg0/lv0 changed from 5.00 GiB (1280 extents) to 3.00 GiB (768 extents). Logical volume lv0 successfully resized. [19:22 [email protected]~]# lvdisplay --- Logical volume --- LV Path /dev/vg0/lv0 LV Name lv0 VG Name vg0 LV UUID 32AMUw-xgxw-ejJ2-rps1-fm0e-feYw-OoTPS8 LV Write Access read/write LV Creation host, time Centos6.8, 2016-08-27 16:21:48 +0800 LV Status available # open 0 LV Size 3.00 GiB Current LE 768 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [19:23 [email protected]~]# mount /dev/vg0/lv0 /mnt/lv0/ #重新挂载 [19:23 [email protected]~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 48G 4.7G 41G 11% / tmpfs 932M 72K 932M 1% /dev/shm /dev/sda1 190M 39M 142M 22% /boot /dev/sda3 20G 44M 19G 1% /testdir /dev/mapper/vg0-lv0 3.0G 69M 2.8G 3% /mnt/lv0 [19:24 [email protected]~]# ll /mnt/lv0/ #文件正常 total 20 -rw-r--r--. 1 root root 28 Aug 27 19:12 f1 drwx------. 2 root root 16384 Aug 27 19:12 lost+found
本文出自 “6638225” 博客,转载请与作者联系!
以上是关于linux基础学习-第十五天 磁盘管理(SWAPddquotaRAIDLVM)的主要内容,如果未能解决你的问题,请参考以下文章