Linux. Inode. Hints: различия между версиями
Cless (обсуждение | вклад) |
Cless (обсуждение | вклад) |
||
| Строка 155: | Строка 155: | ||
= XFS = | = XFS = | ||
=== Информация о директории по её inode === | |||
Получим номер inode директории '''/home''' | |||
<code>ls -lhaid '''/home'''</code> | |||
... | |||
'''33591789''' drwxr-xr-x. 5 root root 61 Nov 9 19:35 /home/ | |||
... | |||
Получим информацию inode (в том числе права доступа, родительская диреткория, субдиректории и файлы в данной директории) | |||
<code>xfs_db -r '''/dev/mapper/centos_centos7--test01-root'''</code> | |||
<code>xfs_db> '''inode 33591789'''</code> | |||
<code>xfs_db> '''print'''</code> | |||
core.magic = 0x494e | |||
core.mode = 040755 '''''// permissions''''' | |||
<...> | |||
core.uid = 0 | |||
core.gid = 0 | |||
core.flushiter = 0 | |||
core.atime.sec = Thu Nov 9 19:35:59 2023 | |||
core.atime.nsec = 643245357 | |||
core.mtime.sec = Thu Nov 9 19:35:31 2023 | |||
core.mtime.nsec = 553102389 | |||
core.ctime.sec = Thu Nov 9 19:35:31 2023 | |||
core.ctime.nsec = 553102389 | |||
<...> | |||
u3.sfdir3.hdr.parent.i4 = 64 '''''// parent dir ("/") inode number''''' | |||
u3.sfdir3.list[2].namelen = 4 '''''// child dir name length''''' | |||
u3.sfdir3.list[2].offset = 0x90 | |||
u3.sfdir3.list[2].name = "test" '''''// child dir name''''' | |||
u3.sfdir3.list[2].inumber.i4 = 262507 '''''// child dir inode number''''' | |||
u3.sfdir3.list[2].filetype = 2 '''''// file type - dir''''' | |||
u3.sfdir3.list[3].namelen = 8 '''''// file name length''''' | |||
u3.sfdir3.list[3].offset = 0xa0 | |||
u3.sfdir3.list[3].name = "file.txt" '''''// file name''''' | |||
u3.sfdir3.list[3].inumber.i4 = 33594311 '''''// file inode number''''' | |||
u3.sfdir3.list[3].filetype = 1 '''''// file type - file''''' | |||
<...> | |||
=== Информация о файле в ФС по его пути === | |||
https://blog.fpmurphy.com/2014/06/rhel7-xfs-is-a-step-backwards-forensically.html | https://blog.fpmurphy.com/2014/06/rhel7-xfs-is-a-step-backwards-forensically.html | ||
| Строка 217: | Строка 259: | ||
dioattr.maxiosz = 2147483136 | dioattr.maxiosz = 2147483136 | ||
xfs_io>quit | xfs_io>quit | ||
=== Информация о файле по его inode === | |||
Получаем номер node файла | Получаем номер node файла | ||
| Строка 223: | Строка 267: | ||
'''18558107''' -rw-r--r-- 1 root root 7 Nov 8 22:44 /tmp/test.txt | '''18558107''' -rw-r--r-- 1 root root 7 Nov 8 22:44 /tmp/test.txt | ||
... | ... | ||
Отобразить информацию inode | |||
<code>xfs_db -r /dev/mapper/centos_centos7--test01-root</code> | <code>xfs_db -r /dev/mapper/centos_centos7--test01-root</code> | ||
<code>xfs_db> '''inode 18558107'''</code> | |||
<code>xfs_db> '''print'''</code> | |||
core.magic = 0x494e | |||
'''core.mode = 0100644''' | |||
core.version = 3 | |||
core.format = 2 (extents) | |||
core.nlinkv2 = 1 | |||
core.onlink = 0 | |||
core.projid_lo = 0 | |||
core.projid_hi = 0 | |||
'''core.uid = 0 | |||
core.gid = 0''' | |||
core.flushiter = 0 | |||
'''core.atime.sec = Wed Nov 8 22:44:13 2023 | |||
core.atime.nsec = 209025224 | |||
core.mtime.sec = Wed Nov 8 22:44:13 2023 | |||
core.mtime.nsec = 209025224 | |||
core.ctime.sec = Wed Nov 8 22:44:13 2023 | |||
core.ctime.nsec = 209025224''' | |||
core.size = 7 | |||
core.nblocks = 1 | |||
core.extsize = 0 | |||
core.nextents = 1 | |||
core.naextents = 0 | |||
core.forkoff = 0 | |||
core.aformat = 2 (extents) | |||
core.dmevmask = 0 | |||
core.dmstate = 0 | |||
core.newrtbm = 0 | |||
core.prealloc = 0 | |||
core.realtime = 0 | |||
core.immutable = 0 | |||
core.append = 0 | |||
core.sync = 0 | |||
core.noatime = 0 | |||
core.nodump = 0 | |||
core.rtinherit = 0 | |||
core.projinherit = 0 | |||
core.nosymlinks = 0 | |||
core.extsz = 0 | |||
core.extszinherit = 0 | |||
core.nodefrag = 0 | |||
core.filestream = 0 | |||
core.gen = 1525739181 | |||
next_unlinked = null | |||
v3.crc = 0x6ea7edb6 (correct) | |||
v3.change_count = 1 | |||
v3.lsn = 0x3c400004923 | |||
v3.flags2 = 0 | |||
v3.crtime.sec = Wed Nov 8 22:44:13 2023 | |||
v3.crtime.nsec = 209025224 | |||
v3.inumber = 18558107 | |||
v3.uuid = 6190fd2d-d76e-4406-8b22-af75ca2dea7a | |||
u3.bmx[0] = [startoff,startblock,blockcount,extentflag] 0:[0,2319856,1,0] | |||
[[Категория:EXT4]] | [[Категория:EXT4]] | ||
[[Категория:XFS]] | [[Категория:XFS]] | ||
Версия 20:18, 9 ноября 2023
Links
https://losst.pro/chto-takoe-inode
Common info
Посмотреть кол-во inode
df -i
EXT4
Установить/изменить количество inode для файловой системы
Вариант 1
Вы не можете изменить количество Inode для существующей файловой системы, зато можете указать для новой с помощью опции -N.
Например:
mkfs -t ext4 -N 3000000 /dev/nvme0n1p5
Вариант 2
When creating an ext4 file system, you can specify the usage type:
mkfs.ext4 -T usage-type /dev/something
The available usage types are listed in /etc/mke2fs.conf. The main difference between usage types is the inode ratio. The lower the inode ratio, the more you can create files in your file system.
The usage type in mke2fs.conf which allocates the highest number of inodes in the file system is "news". With this usage type on a 1 TB hard drive, ext4 creates 244 million inodes.
tune2fs -l /dev/sdb1 | grep -i "inode count"
Inode count: 244219904
sgdisk --print /dev/sdb
Disk /dev/sdb: 1953525168 sectors, 931.5 GiB
This means that it would require more than 4 TB to create an ext4 file system with "-Tnews" that could possibly hold 1 billion inodes.
Показать номер inode файла/директории
Директория в ФС ext - это особый тип файла
У директории, как и у файла есть номер inode
ls -i ./file.txt
ls -id ./directory
У корневой директории номер inode - "2"
ls -id /
2 /
Дебаг ФС. Просмотр информации о директории/файле - inode, ссылка на блоки данных, содержимое блоков данных и т.д.
Посмотреть информацию об inode с номером "2" (корневой директории "/") и содержимое директории.
Получаем номер inode корневой директории "/"
ls -ilhd /
2 drwxr-xr-x 18 root root 4.0K May 22 12:34 /
Видим, что номер inode директории - "2"
Запустим debugfs для раздела /dev/sda2
debugfs /dev/sda2
Получим информацию о директории по номеру её inode
debugfs: stat <2>
... Inode: 2 Type: directory Mode: 0755 Flags: 0x80000 Generation: 0 Version: 0x00000000:0000003e User: 0 Group: 0 Size: 4096 File ACL: 0 Directory ACL: 0 Links: 9 Blockcount: 8 Fragment: Address: 0 Number: 0 Size: 0 ctime: 0x5be96164:af6dd6bc -- Mon Nov 12 14:17:56 2018 atime: 0x5e205209:c091e918 -- Thu Jan 16 15:07:37 2020 mtime: 0x5be96164:af6dd6bc -- Mon Nov 12 14:17:56 2018 crtime: 0x558d36ca:00000000 -- Fri Jun 26 14:26:02 2015 Size of extra inode fields: 28 EXTENTS: (0):9249 ...
Видим, что inode директории ссылается на блок данных номер 9249
Имена файлов и директорий внутри этой директории хранятся в блоках данных, на который ссылается inode директории.
Получим список директорий и файлов внутри директории "/"
debugfs: block_dump 9249
0000 0200 0000 0c00 0102 2e00 0000 0200 0000 ................ 0020 0c00 0202 2e2e 0000 0b00 0000 1400 0a02 ................ 0040 6c6f 7374 2b66 6f75 6e64 0000 01ee 0b00 lost+found...... 0060 0c00 0402 626f 6f74 01fd 0100 0c00 0302 ....boot........ 0100 6574 6300 01fa 0300 1000 0502 6d65 6469 etc.........medi 0120 6100 0000 1d00 0000 1400 0b07 766d 6c69 a...........vmli 0140 6e75 7a2e 6f6c 646c 01f4 0700 0c00 0302 nuz.oldl........ 0160 7661 7200 0c00 0000 0c00 0307 6269 6e00 var.........bin. 0200 01f1 0900 0c00 0302 7573 7200 0d00 0000 ........usr..... 0220 0c00 0407 7362 696e 0e00 0000 0c00 0307 ....sbin........ 0240 6c69 6200 0f00 0000 1000 0507 6c69 6233 lib.........lib3 0260 3200 0000 1000 0000 1000 0507 6c69 6236 2...........lib6 0300 3400 0000 1100 0000 1000 0607 6c69 6278 4...........libx 0320 3332 0000 02ee 0b00 0c00 0302 6465 7600 32..........dev. 0340 02fa 0300 0c00 0402 686f 6d65 0cf7 0500 ........home.... 0360 0c00 0402 7072 6f63 1200 0000 0c00 0402 ....proc........ 0400 726f 6f74 03ee 0b00 0c00 0302 7275 6e00 root........run. 0420 03fa 0300 0c00 0302 7379 7300 0df7 0500 ........sys..... 0440 0c00 0302 746d 7000 04fa 0300 0c00 0302 ....tmp......... 0460 6d6e 7400 1500 0000 0c00 0302 7372 7600 mnt.........srv. 0500 0ef7 0500 2c00 0302 6f70 7400 0000 0000 ....,...opt..... 0520 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0540 0000 0000 0000 0000 0000 0000 1600 0000 ................ 0560 1800 0e07 696e 6974 7264 2e69 6d67 2e6f ....initrd.img.o 0600 6c64 0000 1700 0000 1000 0707 766d 6c69 ld..........vmli 0620 6e75 7a00 1a00 0000 600e 0a07 696e 6974 nuz.....`...init 0640 7264 2e69 6d67 0000 0000 0000 0000 0000 rd.img.......... 0660 0000 0000 0000 0000 0000 0000 0000 0000 ................ * 7760 0000 0000 0000 0000 0c00 00de ce12 46b7 ..............F.
Посмотреть информацию о файле с номером inode "391530" (/tmp/test.txt) и содержимое этого файла.
Получаем номер inode файла /tmp/test.txt
ls -ilhd /tmp/test.txt
391530 -rw-r--r-- 1 root root 7 Nov 8 22:49 /tmp/test.txt
Видим, что его номер inode - "391530"
Получим информацию о файле
debugfs /dev/mapper/vg01-root
debugfs: stat <391530>
... Inode: 391530 Type: regular Mode: 0644 Flags: 0x80000 Generation: 1995900267 Version: 0x00000000:00000001 User: 0 Group: 0 Project: 0 Size: 7 File ACL: 0 Links: 1 Blockcount: 8 Fragment: Address: 0 Number: 0 Size: 0 ctime: 0x654be63f:03367ae0 -- Wed Nov 8 22:49:19 2023 atime: 0x654be63f:03367ae0 -- Wed Nov 8 22:49:19 2023 mtime: 0x654be63f:03367ae0 -- Wed Nov 8 22:49:19 2023 crtime: 0x654be63f:03367ae0 -- Wed Nov 8 22:49:19 2023 Size of extra inode fields: 32 Inode checksum: 0x3043d8bf EXTENTS: (0):2155397 ...
Видим, что inode ссылается на блок данных с номером 2155397
Получим содержимое этого файла (/tmp/test.txt)
Содержимое файла хранится в блоках данных, на которые ссылается inode файла.
debugfs /dev/mapper/vg01-root
debugfs: block_dump 2155397
0000 7177 6531 3233 0a00 0000 0000 0000 0000 qwe123.......... 0020 0000 0000 0000 0000 0000 0000 0000 0000 ................ *
XFS
Информация о директории по её inode
Получим номер inode директории /home
ls -lhaid /home
... 33591789 drwxr-xr-x. 5 root root 61 Nov 9 19:35 /home/ ...
Получим информацию inode (в том числе права доступа, родительская диреткория, субдиректории и файлы в данной директории)
xfs_db -r /dev/mapper/centos_centos7--test01-root
xfs_db> inode 33591789
xfs_db> print
core.magic = 0x494e
core.mode = 040755 // permissions
<...>
core.uid = 0
core.gid = 0
core.flushiter = 0
core.atime.sec = Thu Nov 9 19:35:59 2023
core.atime.nsec = 643245357
core.mtime.sec = Thu Nov 9 19:35:31 2023
core.mtime.nsec = 553102389
core.ctime.sec = Thu Nov 9 19:35:31 2023
core.ctime.nsec = 553102389
<...>
u3.sfdir3.hdr.parent.i4 = 64 // parent dir ("/") inode number
u3.sfdir3.list[2].namelen = 4 // child dir name length
u3.sfdir3.list[2].offset = 0x90
u3.sfdir3.list[2].name = "test" // child dir name
u3.sfdir3.list[2].inumber.i4 = 262507 // child dir inode number
u3.sfdir3.list[2].filetype = 2 // file type - dir
u3.sfdir3.list[3].namelen = 8 // file name length
u3.sfdir3.list[3].offset = 0xa0
u3.sfdir3.list[3].name = "file.txt" // file name
u3.sfdir3.list[3].inumber.i4 = 33594311 // file inode number
u3.sfdir3.list[3].filetype = 1 // file type - file
<...>
Информация о файле в ФС по его пути
https://blog.fpmurphy.com/2014/06/rhel7-xfs-is-a-step-backwards-forensically.html
You can examine a XFS file’s metadata using xfs_db but it is much easier to use the xfs_io utility. Just like xfs_db, xfs_io is an XFS filesystem debugging tool, but it’s focus is on supporting regular file I/O paths rather than the raw XFS volume itself.
xfs_io
xfs_io> open /home/fpm/test xfs_io> stat fd.path = "/home/fpm/test" fd.flags = non-sync,non-direct,read-write stat.ino = 71265538 stat.type = regular file stat.size = 13644 stat.blocks = 32 fsxattr.xflags = 0x80000000 [--------------] fsxattr.projid = 0 fsxattr.extsize = 0 fsxattr.nextents = 1 fsxattr.naextents = 0 dioattr.mem = 0x200 dioattr.miniosz = 512 dioattr.maxiosz = 2147483136 xfs_io> statfs fd.path = "/home/fpm/test" statfs.f_bsize = 4096 statfs.f_blocks = 4587008 statfs.f_bavail = 3751604 statfs.f_files = 18358272 statfs.f_ffree = 18227530 geom.bsize = 4096 geom.agcount = 4 geom.agblocks = 1147392 geom.datablocks = 4589568 geom.rtblocks = 0 geom.rtextents = 0 geom.rtextsize = 1 geom.sunit = 0 geom.swidth = 0 counts.freedata = 3751604 counts.freertx = 0 counts.freeino = 202 counts.allocino = 130944 xfs_io> stat -v fd.path = "/home/fpm/test" fd.flags = non-sync,non-direct,read-write stat.ino = 71265538 stat.type = regular file stat.size = 13644 stat.blocks = 32 stat.atime = Fri Jun 13 19:03:06 2014 stat.mtime = Fri Jun 13 19:03:03 2014 stat.ctime = Fri Jun 13 19:03:03 2014 fsxattr.xflags = 0x80000000 [] fsxattr.projid = 0 fsxattr.extsize = 0 fsxattr.nextents = 1 fsxattr.naextents = 0 dioattr.mem = 0x200 dioattr.miniosz = 512 dioattr.maxiosz = 2147483136 xfs_io>quit
Информация о файле по его inode
Получаем номер node файла
ls -lhi /tmp/test.txt
... 18558107 -rw-r--r-- 1 root root 7 Nov 8 22:44 /tmp/test.txt ...
Отобразить информацию inode
xfs_db -r /dev/mapper/centos_centos7--test01-root
xfs_db> inode 18558107
xfs_db> print
core.magic = 0x494e core.mode = 0100644 core.version = 3 core.format = 2 (extents) core.nlinkv2 = 1 core.onlink = 0 core.projid_lo = 0 core.projid_hi = 0 core.uid = 0 core.gid = 0 core.flushiter = 0 core.atime.sec = Wed Nov 8 22:44:13 2023 core.atime.nsec = 209025224 core.mtime.sec = Wed Nov 8 22:44:13 2023 core.mtime.nsec = 209025224 core.ctime.sec = Wed Nov 8 22:44:13 2023 core.ctime.nsec = 209025224 core.size = 7 core.nblocks = 1 core.extsize = 0 core.nextents = 1 core.naextents = 0 core.forkoff = 0 core.aformat = 2 (extents) core.dmevmask = 0 core.dmstate = 0 core.newrtbm = 0 core.prealloc = 0 core.realtime = 0 core.immutable = 0 core.append = 0 core.sync = 0 core.noatime = 0 core.nodump = 0 core.rtinherit = 0 core.projinherit = 0 core.nosymlinks = 0 core.extsz = 0 core.extszinherit = 0 core.nodefrag = 0 core.filestream = 0 core.gen = 1525739181 next_unlinked = null v3.crc = 0x6ea7edb6 (correct) v3.change_count = 1 v3.lsn = 0x3c400004923 v3.flags2 = 0 v3.crtime.sec = Wed Nov 8 22:44:13 2023 v3.crtime.nsec = 209025224 v3.inumber = 18558107 v3.uuid = 6190fd2d-d76e-4406-8b22-af75ca2dea7a u3.bmx[0] = [startoff,startblock,blockcount,extentflag] 0:[0,2319856,1,0]