Situation: Loosing a Directory by incorrect mount procedure (mountpath mixup!!!)
YouTube Video:
Learning target: what should we do on such situation?
If we unmount the new fs, will we get our old fs back?
Test setup:
1. create /test directory
2. Ensure it is created on / filesystem
mkdir /test
3. create a subdirectory testsub in /test and touch a file called testfile
mkdir /test/testsub
[root@vcentos79-oracle-sa1 /]# mkdir /test
[root@vcentos79-oracle-sa1 /]# cd /test/
[root@vcentos79-oracle-sa1 test]# mkdir testdir
[root@vcentos79-oracle-sa1 test]# mv testdir testsub
[root@vcentos79-oracle-sa1 test]# touch testsub/testfile
[root@vcentos79-oracle-sa1 test]# ls -altr
total 4
dr-xr-xr-x. 25 root root 4096 Feb 5 00:14 ..
drwxr-xr-x. 3 root root 21 Feb 5 00:14 .
drwxr-xr-x. 2 root root 22 Feb 5 00:14 testsub
[root@vcentos79-oracle-sa1 test]# cd testsub
[root@vcentos79-oracle-sa1 testsub]# ls -altr
total 0
drwxr-xr-x. 3 root root 21 Feb 5 00:14 ..
-rw-r--r--. 1 root root 0 Feb 5 00:14 testfile
drwxr-xr-x. 2 root root 22 Feb 5 00:14 .
[root@vcentos79-oracle-sa1 testsub]# pwd
/test/testsub
[root@vcentos79-oracle-sa1 testsub]# pwd
/test/testsub
[root@vcentos79-oracle-sa1 testsub]# cd
[root@vcentos79-oracle-sa1 ~]# df -Th /test
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 17G 4.7G 13G 28% /
[root@vcentos79-oracle-sa1 ~]#
4. Now as if you didnt know that there is a subdirectory called testsub, let us create a new FS called /test (mountpath)
fdisk /dev/sde
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-2097151, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set
Command (m for help): w
The partition table has been altered!
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): q
Changed type of partition 'Linux' to 'unknown'
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 1
WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation.
Changed type of partition 'Empty' to 'FAT12'
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation.
Changed type of partition 'FAT12' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@vcentos79-oracle-sa1 ~]#
Disk /dev/sde: 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: 0x4d9dd83f
Device Boot Start End Blocks Id System
/dev/sde1 2048 2097151 1047552 8e Linux LVM
[root@vcentos79-oracle-sa1 ~]# pvcreate /dev/sde1
Physical volume "/dev/sde1" successfully created.
[root@vcentos79-oracle-sa1 ~]# vgcreate testvg /dev/sde1
Volume group "testvg" successfully created
[root@vcentos79-oracle-sa1 ~]# lvcreate -L 1000 testvg -n testvg-test00
Logical volume "testvg-test00" created.
lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testvg-test00
LV Name testvg-test00
VG Name testvg
LV UUID SIZBUy-FdtH-d6oV-KOFU-OUgg-zMan-H63Kqc
LV Write Access read/write
LV Creation host, time vcentos79-oracle-sa1, 2025-02-05 00:25:24 +0000
LV Status available
# open 0
LV Size 1000.00 MiB
Current LE 250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:10
[root@vcentos79-oracle-sa1 ~]# mkfs.xfs /dev/testvg/testvg-test00
meta-data=/dev/testvg/testvg-test00 isize=512 agcount=4, agsize=64000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=256000, 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@vcentos79-oracle-sa1 ~]# lvdisplay|grep "LV Path"
...
LV Path /dev/testvg/testvg-test00
5. Mount it and see what happens.
a. You will loose the files
mount /dev/testvg/testvg-test00 /test
/dev/mapper/testvg-testvg--test00 xfs 997M 33M 965M 4% /test
[root@vcentos79-oracle-sa1 /]# cd /test
[root@vcentos79-oracle-sa1 test]# ls -altr
total 4
dr-xr-xr-x. 25 root root 4096 Feb 5 00:14 ..
drwxr-xr-x. 2 root root 6 Feb 5 00:25 .
[root@vcentos79-oracle-sa1 test]#
Recovery option:
6. Unmount the FS and you will see the old file coming back.
umount /test
7. List the files:
[root@vcentos79-oracle-sa1 /]# cd test
[root@vcentos79-oracle-sa1 test]# ls -altr
total 4
dr-xr-xr-x. 25 root root 4096 Feb 5 00:14 ..
drwxr-xr-x. 3 root root 21 Feb 5 00:14 .
drwxr-xr-x. 2 root root 22 Feb 5 00:14 testsub
[root@vcentos79-oracle-sa1 test]# cd testsub/
[root@vcentos79-oracle-sa1 testsub]# ls -altr
total 0
drwxr-xr-x. 3 root root 21 Feb 5 00:14 ..
-rw-r--r--. 1 root root 0 Feb 5 00:14 testfile
drwxr-xr-x. 2 root root 22 Feb 5 00:14 .
[root@vcentos79-oracle-sa1 testsub]#
8. Mount the /test again
[root@vcentos79-oracle-sa1 /]# mount /dev/testvg/testvg-test00 /test
[root@vcentos79-oracle-sa1 /]# cd /test
[root@vcentos79-oracle-sa1 test]# ls -altr
total 4
dr-xr-xr-x. 25 root root 4096 Feb 5 00:14 ..
drwxr-xr-x. 2 root root 6 Feb 5 00:25 .
[root@vcentos79-oracle-sa1 test]# cd
[root@vcentos79-oracle-sa1 ~]#
you loose it.
9. unmount you get the old content back again
[root@vcentos79-oracle-sa1 ~]# umount /test
[root@vcentos79-oracle-sa1 ~]# ls -altr /test/*/*
-rw-r--r--. 1 root root 0 Feb 5 00:14 /test/testsub/testfile
[root@vcentos79-oracle-sa1 ~]#
************** this closes the lab
No comments:
Post a Comment