botang 发表于 2019-4-16 20:23:54

课程第6次

rescue:
能够continue :文件系统本身没有问题+原/etc/fstab内容正确。

能够chroot: 在continue之后, 原/bin/bash和原/bin/mount没有丢失。


PV/VG/LV的小实验:
# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000db1f1

   Device Boot      Start         End      Blocks   IdSystem
/dev/sda1   *      2048   2099199   1048576   83Linux
/dev/sda2         2099200    41943039    19921920   8eLinux LVM

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x7380aaa7

   Device Boot      Start         End      Blocks   IdSystem
/dev/sdb1            2048   1026047      512000   8eLinux LVM
/dev/sdb4         1026048   2097151      535552    5Extended
/dev/sdb5         1028096   2097151      534528   8eLinux LVM

Disk /dev/mapper/rhel-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vol0-test: 33 MB, 33554432 bytes, 65536 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/vol0-test2: 50 MB, 50331648 bytes, 98304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

# cat /proc/partitions
major minor#blocksname

   8      0   20971520 sda
   8      1    1048576 sda1
   8      2   19921920 sda2
   8       16    1048576 sdb
   8       17   512000 sdb1
   8       20          1 sdb4
   8       21   534528 sdb5
11      0    4391936 sr0
253      0   17821696 dm-0
253      1    2097152 dm-1
253      2      32768 dm-2
253      3      49152 dm-3
# pvs
PV         VG   FmtAttr PSize   PFree
/dev/sda2rhel lvm2 a--<19.00g      0
/dev/sdb1       lvm2 ---500.00m 500.00m
/dev/sdb5vol0 lvm2 a--512.00m 432.00m
# vgs
VG   #PV #LV #SN Attr   VSize   VFree
rhel   1   2   0 wz--n- <19.00g      0
vol0   1   2   0 wz--n- 512.00m 432.00m
# lvs
LV    VG   Attr       LSize   Pool Origin Data%Meta%Move Log Cpy%Sync Convert
rootrhel -wi-ao---- <17.00g                                                   
swaprhel -wi-ao----   2.00g                                                   
testvol0 -wi-a-----32.00m                                                   
test2 vol0 -wi-a-----48.00m                                                   
# vgdisplay vol0
--- Volume group ---
VG Name               vol0
System ID            
Format                lvm2
Metadata Areas      1
Metadata Sequence No5
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               0
Max PV                0
Cur PV                1
Act PV                1
VG Size               512.00 MiB
PE Size               16.00 MiB
Total PE            32
Alloc PE / Size       5 / 80.00 MiB
FreePE / Size       27 / 432.00 MiB
VG UUID               D9muED-xgR5-rLEx-3aUg-LCe4-T3OZ-YFBP5T
   
# pvs
PV         VG   FmtAttr PSize   PFree
/dev/sda2rhel lvm2 a--<19.00g      0
/dev/sdb1       lvm2 ---500.00m 500.00m
/dev/sdb5vol0 lvm2 a--512.00m 432.00m
# pvremove /dev/sdb5
PV /dev/sdb5 is used by VG vol0 so please use vgreduce first.
(If you are certain you need pvremove, then confirm by using --force twice.)
/dev/sdb5: physical volume label not removed.
# vgextendvol0 /dev/sdb1
Volume group "vol0" successfully extended
# vgreduce vol0/dev/sdb5
Physical volume "/dev/sdb5" still in use
# lvs
LV    VG   Attr       LSize   Pool Origin Data%Meta%Move Log Cpy%Sync Convert
rootrhel -wi-ao---- <17.00g                                                   
swaprhel -wi-ao----   2.00g                                                   
testvol0 -wi-a-----32.00m                                                   
test2 vol0 -wi-a-----48.00m                                                   
#
同时观察以下终端:
# vgs vol0
VG   #PV #LV #SN Attr   VSize   VFree
vol0   1   2   0 wz--n- 512.00m 432.00m
# vgs vol0
VG   #PV #LV #SN Attr   VSize    VFree
vol0   2   2   0 wz--n- 1008.00m 928.00m
#
解决办法:1. 挪走pv上面的数据(pvmove)
2. 缩小vg
3. pvremove
# pvmove /dev/sdb5 /dev/sdb1
/dev/sdb5: Moved: 40.00%
/dev/sdb5: Moved: 100.00%
# pvs
PV         VG   FmtAttr PSize   PFree
/dev/sda2rhel lvm2 a--<19.00g      0
/dev/sdb1vol0 lvm2 a--496.00m 416.00m
/dev/sdb5vol0 lvm2 a--512.00m 512.00m
# vgreducevol0 /dev/sdb5
Removed "/dev/sdb5" from volume group "vol0"
# pvs
PV         VG   FmtAttr PSize   PFree
/dev/sda2rhel lvm2 a--<19.00g      0
/dev/sdb1vol0 lvm2 a--496.00m 416.00m
/dev/sdb5       lvm2 ---522.00m 522.00m
# pvremove /dev/sdb5
Labels on physical volume "/dev/sdb5" successfully wiped.
#
扩大逻辑卷和文件系统:
Last login: Tue Apr 16 08:53:35 2019
# pvs
PV         VG   FmtAttr PSize   PFree
/dev/sda2rhel lvm2 a--<19.00g      0
/dev/sdb1vol0 lvm2 a--496.00m 496.00m
/dev/sdb5vol0 lvm2 a--512.00m 432.00m
# vgs
VG   #PV #LV #SN Attr   VSize    VFree
rhel   1   2   0 wz--n-<19.00g      0
vol0   2   2   0 wz--n- 1008.00m 928.00m
# lvs
LV    VG   Attr       LSize   Pool Origin Data%Meta%Move Log Cpy%Sync Conv                                                                           ert
rootrhel -wi-ao---- <17.00g                                                                                                                              
swaprhel -wi-ao----   2.00g                                                                                                                              
testvol0 -wi-ao----32.00m                                                                                                                              
test2 vol0 -wi-ao----48.00m                                                                                                                              
# lvextend -L 320M /dev/vol0/test
Size of logical volume vol0/test changed from 32.00 MiB (2 extents) to 320.00                                                                              MiB (20 extents).
Logical volume vol0/test successfully resized.
# df -h
Filesystem            SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root    17G3.7G   14G22% /
devtmpfs                894M   0894M   0% /dev
tmpfs                   910M   0910M   0% /dev/shm
tmpfs                   910M   11M900M   2% /run
tmpfs                   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            1014M178M837M18% /boot
/dev/mapper/vol0-test2   45M2.6M   43M   6% /b
/dev/mapper/vol0-test    27M   27M   0 100% /a
tmpfs                   182M8.0K182M   1% /run/user/42
tmpfs                   182M   0182M   0% /run/user/0
# resize2fs/dev/vol0/test
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vol0/test is mounted on /a; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/vol0/test is now 327680 blocks long.

# df -h
Filesystem            SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root    17G3.7G   14G22% /
devtmpfs                894M   0894M   0% /dev
tmpfs                   910M   0910M   0% /dev/shm
tmpfs                   910M   11M900M   2% /run
tmpfs                   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            1014M178M837M18% /boot
/dev/mapper/vol0-test2   45M2.6M   43M   6% /b
/dev/mapper/vol0-test   306M   28M265M10% /a
tmpfs                   182M8.0K182M   1% /run/user/42
tmpfs                   182M   0182M   0% /run/user/0
# lvextend -L +20M /dev/vol0/test
Rounding size to boundary between physical extents: 32.00 MiB.
Size of logical volume vol0/test changed from 320.00 MiB (20 extents) to 352.0                                                                           0 MiB (22 extents).
Logical volume vol0/test successfully resized.
# resize2fs/dev/vol0/test
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vol0/test is mounted on /a; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/vol0/test is now 360448 blocks long.

# df -h
Filesystem            SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root    17G3.7G   14G22% /
devtmpfs                894M   0894M   0% /dev
tmpfs                   910M   0910M   0% /dev/shm
tmpfs                   910M   11M900M   2% /run
tmpfs                   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            1014M178M837M18% /boot
/dev/mapper/vol0-test2   45M2.6M   43M   6% /b
/dev/mapper/vol0-test   337M   28M295M   9% /a
tmpfs                   182M8.0K182M   1% /run/user/42
tmpfs                   182M   0182M   0% /run/user/0
# lvextend -l +1 /dev/vol0/test
Size of logical volume vol0/test changed from 352.00 MiB (22 extents) to 368.0                                                                           0 MiB (23 extents).
Logical volume vol0/test successfully resized.
# resize2fs/dev/vol0/test
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vol0/test is mounted on /a; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 3
The filesystem on /dev/vol0/test is now 376832 blocks long.

# df -h
Filesystem            SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root    17G3.7G   14G22% /
devtmpfs                894M   0894M   0% /dev
tmpfs                   910M   0910M   0% /dev/shm
tmpfs                   910M   11M900M   2% /run
tmpfs                   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            1014M178M837M18% /boot
/dev/mapper/vol0-test2   45M2.6M   43M   6% /b
/dev/mapper/vol0-test 353M   28M310M   9% /a
tmpfs                   182M8.0K182M   1% /run/user/42
tmpfs                   182M   0182M   0% /run/user/0
------------------------------------------------------------------------
xfs 版本:
# df -Th
Filesystem             Type      SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-rootxfs      17G3.7G   14G22% /
devtmpfs               devtmpfs894M   0894M   0% /dev
tmpfs                  tmpfs   910M   0910M   0% /dev/shm
tmpfs                  tmpfs   910M   11M900M   2% /run
tmpfs                  tmpfs   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            xfs      1014M178M837M18% /boot
/dev/mapper/vol0-test2 xfs      45M2.6M   43M   6% /b
/dev/mapper/vol0-testext4      353M   28M310M   9% /a
tmpfs                  tmpfs   182M   12K182M   1% /run/user/42
tmpfs                  tmpfs   182M   0182M   0% /run/user/0
# lvdisplay/dev/vol0/test2
--- Logical volume ---
LV Path                /dev/vol0/test2
LV Name                test2
VG Name                vol0
LV UUID                3TxeHB-gXRj-a1JU-Z05r-ZF4n-AEpI-eqwAzp
LV Write Access      read/write
LV Creation host, time station60.example.com, 2019-04-13 10:00:50 -0400
LV Status            available
# open               1
LV Size                48.00 MiB
Current LE             3
Segments               1
Allocation             inherit
Read ahead sectors   auto
- currently set to   8192
Block device         253:3

# lvdisplay/dev/mapper/vol0-test2
--- Logical volume ---
LV Path                /dev/vol0/test2
LV Name                test2
VG Name                vol0
LV UUID                3TxeHB-gXRj-a1JU-Z05r-ZF4n-AEpI-eqwAzp
LV Write Access      read/write
LV Creation host, time station60.example.com, 2019-04-13 10:00:50 -0400
LV Status            available
# open               1
LV Size                48.00 MiB
Current LE             3
Segments               1
Allocation             inherit
Read ahead sectors   auto
- currently set to   8192
Block device         253:3

# lvextend -l +1 /dev/vol0/test2
Size of logical volume vol0/test2 changed from 48.00 MiB (3 extents) to 64.00 MiB (4 extents).
Logical volume vol0/test2 successfully resized.
# df -Th
Filesystem             Type      SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-rootxfs      17G3.7G   14G22% /
devtmpfs               devtmpfs894M   0894M   0% /dev
tmpfs                  tmpfs   910M   0910M   0% /dev/shm
tmpfs                  tmpfs   910M   11M900M   2% /run
tmpfs                  tmpfs   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            xfs      1014M178M837M18% /boot
/dev/mapper/vol0-test2 xfs      45M2.6M   43M   6% /b
/dev/mapper/vol0-testext4      353M   28M310M   9% /a
tmpfs                  tmpfs   182M   12K182M   1% /run/user/42
tmpfs                  tmpfs   182M   0182M   0% /run/user/0
# xfs_
xfs_admin      xfs_estimate   xfs_info       xfs_metadump   xfs_repair
xfs_bmap       xfs_freeze   xfs_io         xfs_mkfile   xfs_rtcp
xfs_copy       xfs_fsr      xfs_logprint   xfs_ncheck
xfs_db         xfs_growfs   xfs_mdrestorexfs_quota
# xfs_growfs   /dev/vol0/test2
meta-data=/dev/mapper/vol0-test2 isize=512    agcount=2, agsize=6144 blks
         =                     sectsz=512   attr=2, projid32bit=1
         =                     crc=1      finobt=0 spinodes=0
data   =                     bsize=4096   blocks=12288, 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 12288 to 16384
# df -Th
Filesystem             Type      SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-rootxfs      17G3.7G   14G22% /
devtmpfs               devtmpfs894M   0894M   0% /dev
tmpfs                  tmpfs   910M   0910M   0% /dev/shm
tmpfs                  tmpfs   910M   11M900M   2% /run
tmpfs                  tmpfs   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            xfs      1014M178M837M18% /boot
/dev/mapper/vol0-test2 xfs      61M2.6M   59M   5% /b
/dev/mapper/vol0-testext4      353M   28M310M   9% /a
tmpfs                  tmpfs   182M   12K182M   1% /run/user/42
tmpfs                  tmpfs   182M   0182M   0% /run/user/0
#

--------------------------------------------------------------# resize2fs/dev/vol0/test 40M
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vol0/test is mounted on /a; on-line resizing required
resize2fs: On-line shrinking not supported
# umount/dev/vol0/test
# resize2fs/dev/vol0/test 40M
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vol0/test' first.

# e2fsck -f /dev/vol0/test
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Inode 7, i_blocks is 4050, should be 3990.Fix<y>? yes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/vol0/test: ***** FILE SYSTEM WAS MODIFIED *****
/dev/vol0/test: 12/94208 files (8.3% non-contiguous), 44233/376832 blocks
# e2fsck -yf /dev/vol0/test
e2fsck 1.42.9 (28-Dec-2013)
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/vol0/test: 12/94208 files (8.3% non-contiguous), 44233/376832 blocks
# resize2fs/dev/vol0/test 40M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vol0/test to 40960 (1k) blocks.
The filesystem on /dev/vol0/test is now 40960 blocks long.

# lvreduce -L 40M/dev/vol0/test
Rounding size to boundary between physical extents: 48.00 MiB.
WARNING: Reducing active logical volume to 48.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vol0/test? : y
Size of logical volume vol0/test changed from 368.00 MiB (23 extents) to 48.00 MiB (3 extents).
Logical volume vol0/test successfully resized.
# mount-a
# df -h
Filesystem            SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root    17G3.7G   14G22% /
devtmpfs                894M   0894M   0% /dev
tmpfs                   910M   0910M   0% /dev/shm
tmpfs                   910M   11M900M   2% /run
tmpfs                   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            1014M178M837M18% /boot
/dev/mapper/vol0-test2   61M2.6M   59M   5% /b
tmpfs                   182M   12K182M   1% /run/user/42
tmpfs                   182M   0182M   0% /run/user/0
/dev/mapper/vol0-test    35M   27M6.0M82% /a
#-------------------------------------------------------------------------------------------

增量写入快照   但是看快照的时候是不变的

# lvcreate -L 30M -s -ntestsnap/dev/vol0/test
Rounding up size to full physical extent 32.00 MiB
Logical volume "testsnap" created.
# lvs
LV       VG   Attr       LSize   Pool Origin Data%Meta%Move Log Cpy%Sync Convert
root   rhel -wi-ao---- <17.00g                                             
swap   rhel -wi-ao----   2.00g                                             
test   vol0 owi-aos---48.00m                                             
test2    vol0 -wi-ao----64.00m                                             
testsnap vol0 swi-a-s---32.00m      test   0.04                           
# mkdir /a1
# mount/dev/vol0/testsnap/a1
# cd /a
# ls
1.imglost+found
# echo "hello world" >2.txt
# ls
1.img2.txtlost+found
# cd /a1
# ls
1.imglost+found
#
用破坏方法,认清原理:# cd /a
# ls
1.img2.txtlost+found
# dd if=/dev/zero of=3.img bs=35M count=1
dd: error writing ‘3.img’: No space left on device
1+0 records in
0+0 records out
7954432 bytes (8.0 MB) copied, 0.397343 s, 20.0 MB/s
# df -h
Filesystem               SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root       17G3.7G   14G22% /
devtmpfs                   894M   0894M   0% /dev
tmpfs                      910M   0910M   0% /dev/shm
tmpfs                      910M   11M900M   2% /run
tmpfs                      910M   0910M   0% /sys/fs/cgroup
/dev/sda1               1014M178M837M18% /boot
/dev/mapper/vol0-test2      61M2.6M   59M   5% /b
tmpfs                      182M   12K182M   1% /run/user/42
tmpfs                      182M   0182M   0% /run/user/0
/dev/mapper/vol0-test       35M   34M   0 100% /a
/dev/mapper/vol0-testsnap   35M   27M6.0M82% /a1
# cd /a
# lks
bash: lks: command not found...
# ls
1.img2.txt3.imglost+found
# rm -rf 1.img
# rm -rf 3.img
# ls
2.txtlost+found
# rm 0rf *
rm: cannot remove ‘0rf’: No such file or directory
rm: remove regular file ‘2.txt’? y
rm: cannot remove ‘lost+found’: Is a directory
# cd /a1
# ls
1.imglost+found
# cd /a
# ls
lost+found
# dd if=/dev/zero of=3.img bs=35M count=1
dd: error writing ‘3.img’: No space left on device
1+0 records in
0+0 records out
34779136 bytes (35 MB) copied, 0.368419 s, 94.4 MB/s
# df -h
Filesystem            SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root    17G3.7G   14G22% /
devtmpfs                894M   0894M   0% /dev
tmpfs                   910M   0910M   0% /dev/shm
tmpfs                   910M   11M900M   2% /run
tmpfs                   910M   0910M   0% /sys/fs/cgroup
/dev/sda1            1014M178M837M18% /boot
/dev/mapper/vol0-test2   61M2.6M   59M   5% /b
tmpfs                   182M   12K182M   1% /run/user/42
tmpfs                   182M   0182M   0% /run/user/0
/dev/mapper/vol0-test    35M   34M   0 100% /a
# cd /a
# ls
3.imglost+found
# cd /a1
# ls
# ls
# ls
#
同时观察message:












Apr 16 10:04:29 station60 kernel: device-mapper: snapshots: Invalidating snapshot: Unable to allocate exception.
Apr 16 10:04:29 station60 lvm: WARNING: Snapshot vol0-testsnap changed state to: Invalid and should be removed.
Apr 16 10:04:29 station60 lvm: Unmounting invalid snapshot vol0-testsnap from /a1.
Apr 16 10:04:29 station60 kernel: Buffer I/O error on dev dm-6, logical block 16385, lost sync page write
Apr 16 10:04:29 station60 kernel: JBD2: Error -5 detected when updating journal superblock for dm-6-8.
Apr 16 10:04:29 station60 kernel: Aborting journal on device dm-6-8.
Apr 16 10:04:29 station60 kernel: Buffer I/O error on dev dm-6, logical block 16385, lost sync page write
Apr 16 10:04:29 station60 kernel: JBD2: Error -5 detected when updating journal superblock for dm-6-8.
Apr 16 10:04:29 station60 kernel: Buffer I/O error on dev dm-6, logical block 1, lost sync page write
Apr 16 10:04:29 station60 kernel: EXT4-fs error (device dm-6): ext4_put_super:800: Couldn't clean up the journal
Apr 16 10:04:29 station60 kernel: EXT4-fs (dm-6): Remounting filesystem read-only
Apr 16 10:04:29 station60 kernel: EXT4-fs (dm-6): previous I/O error to superblock detected
Apr 16 10:04:29 station60 kernel: Buffer I/O error on dev dm-6, logical block 1, lost sync page write
Apr 16 10:04:29 station60 kernel: VFS: Dirty inode writeback failed for block device dm-6 (err=-5).
Apr 16 10:04:29 station60 dmeventd: No longer monitoring snapshot vol0-testsnap.







页: [1]
查看完整版本: 课程第6次