跟馬哥學linux (lesson 4)linux磁盤管理

Linux文件系統管理:node

mkfs, mkfs -type = mkfs.ext2,3,4vim

例:bash

[root@localhost ~]# mkfs -type ext4 /dev/sdb
mkfs.ype: No such file or directory
[root@localhost ~]# mkfs -t ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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, 1605632, 2654208, 
4096000
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

ext: mke2fs異步

例:async

[root@localhost ~]# mkfs.ext4 /dev/sdb
mke2fs 1.41.12 (17-May-2010)/dev/sdb is entire device, not just one partition!Proceed anyway? (y,n) yFilesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1310720 inodes, 5242880 blocks262144 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 37 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.


建立文件系統ide

mke2fs [OPTION]..DEVICE工具

             -t ext2,ext3,ext4佈局

             -b 1024,2048,4096flex

            -L 'Lable'卷標ui

            -j mke2fs -t ext

            -i inode

            -N 保留多少inode

            -m 預留磁盤空間佔據多少百分比爲後期管理

            -O FEATURE[...]開啓預留特性

            -O^FEATUEW[...]關閉預留特性

文件系統屬性查看及調整工具:

e2lable:管理文件系統卷標

e2lable DEVICE [LAVLE]

例:

[root@localhost ~]# e2label /dev/sdb 'mydisk' 
[root@localhost ~]# e2label /dev/sdb

mydisk

tune2fs:顯示文件系統屬性,或調整文件系統屬性

-l   顯示superblock信息

-L  LABLE 修改卷標

-m 管理預留給管理員的空間

-j ext2-->ext3

-O 啓用或禁用特性

-o 文件系統默認掛載選項的開啓或關閉

例1:

[root@localhost ~]# tune2fs -l /dev/sdb
tune2fs 1.41.12 (17-May-2010)Filesystem volume name:   mydiskLast mounted on:          <not available>Filesystem UUID:          e2ec1086-064d-4eac-950f-0672a508213eFilesystem magic number:  0xEF53Filesystem revision #:    1 (dynamic)Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isizeFilesystem flags:         signed_directory_hash Default mount options:    (none)Filesystem state:         cleanErrors behavior:          ContinueFilesystem OS type:       LinuxInode count:              1310720Block count:              5242880Reserved block count:     262144Free blocks:              5116591Free inodes:              1310709First block:              0Block size:               4096Fragment size:            4096Reserved GDT blocks:      1022Blocks per group:         32768Fragments per group:      32768Inodes per group:         8192Inode blocks per group:   512Flex block group size:    16Filesystem created:       Sun Sep  6 19:08:01 2015Last mount time:          n/aLast write time:          Sun Sep  6 19:10:29 2015Mount count:              0Maximum mount count:      37Last checked:             Sun Sep  6 19:08:01 2015Check interval:           15552000 (6 months)Next check after:         Fri Mar  4 19:08:01 2016Lifetime writes:          452 MBReserved blocks uid:      0 (user root)Reserved blocks gid:      0 (group root)First inode:              11Inode size:          256Required extra isize:     28Desired extra isize:      28Journal inode:            8Default directory hash:   half_md4Directory Hash Seed:      4fc68caf-3b7f-401e-8022-707100c2b923Journal backup:           inode blocks


dumpe2fs顯示文件系統佈局及superblock信息

例:

dumpe2fs /dev/sdb

文件系統檢測系統

fsck 文件系統檢測

fsck -t test = fsck.type

-a 自動修復文件系統錯誤

-f 交互式修復

-F 強制檢測

例:

[root@localhost ~]# fsck.ext4 -a /dev/sdb 
mydisk: clean, 11/1310720 files, 126289/5242880 blocks

e2fsck: ext文件系統專用檢測工具

-y 自動修復錯誤

-f 強制檢測

例:

[root@localhost ~]# e2fsck -f /dev/sdb
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
mydisk: 11/1310720 files (0.0% non-contiguous), 126289/5242880 blocks

文件系統掛載及使用

kernel --> rootfs分區

rootfs分區

bin,sbin,boot,etc,lib,lib64,dev,tmp,usr,proc

將額外的文件系統與根文件系統某先問的目錄創建起關聯關係,進而使此目錄變爲其餘目錄的入口,成爲掛載

接觸此關聯關係的過程,稱爲卸載

掛載點:mount point 設備掛載至此目錄

注意:掛載點須要爲空目錄

掛載方法:mount:經過讀取/etc/mtab文件來顯示當前系統全部已

mount -a 掛載/etc/fstab額文件中全部支持自動掛載的設備

mount [OPTION] [-o OPTION] DEVICE MOUNT_POINT

[option]命令選項

[-o option]掛在選項

DEVICE:要掛載的設備

(1)設備文件:/dev/sda

(2)卷標 -L

(3)UUID -U

(4)僞文件系統 文件名掛載

經常使用選項

-t 文件系統屬性

-r 以只讀模式掛載

-w 以讀寫方式掛載

-n 每一個文件系統在掛載時都會自動更新/etc/mtab -n禁止此功能

-a 自動掛載全部支持自動掛載的設備

-B 綁定目錄至另外一個目錄

例:

[root@localhost ~]# mkdir /mydata
[root@localhost ~]# mount -o rw,async,noatime /dev/sdb /mydata

-o掛載選項

async 異步模式

sync 同步模式

atime/noatime 是否更新訪問時間戳

diratime/nodiratime 是否更新訪問目錄時間戳

auto/noauto 是否容許此設備是否自動掛載

exec/noexec 是否容許執行此文件系統上的可執行程序

dev/nodev 是否支持此設備上使用設備文件

suid/nosudi

remount 從新掛載

ro/rw

user/nouser 是否容許普通用戶掛載此設備

acl 是否容許此設備使用facl

umount:卸載命令

umount DEVICE

umount MOUNT_POINT

例:

[root@localhost ~]# umount /dev/sdb
[root@localhost ~]# umount /mydata

查看正在訪問指定掛載點的進程

fuser -v mount_point

終止全部正在訪問指定掛載點的進程

fuser -km mount_point

例:

[root@localhost ~]# fuser -v /mydata                     USER        PID ACCESS COMMAND/mydata:             root       2476 ..c.. bash
[root@localhost ~]# fuser -km /mydata/mydata:              2476c

交換分區:

free命令

查看menmory和swap使用狀態

free -m以MB顯示

例:

[root@localhost ~]# free -m 
             total       used       free     shared    buffers     cachedMem:          1862        253       1609          0         51         63-/+ buffers/cache:        137       1724 Swap:         3071          0       3071


free -g以G顯示(4舍5入顯示)

例:

[root@localhost ~]# free -g
             total       used       free     shared    buffers     cached
Mem:             1          0          1          0          0          0
-/+ buffers/cache:          0          1 
Swap:            2          0          2

練習:

建立一個10G的文件系統,類型爲ext4,要求開機可自動掛載至/mydata目錄

[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x13a6c9bf   Device Boot      Start         End      Blocks   Id  System/dev/sdb1               1        1306    10490413+  83  Linux
[root@localhost fs]# kpartx -a /dev/sdb1
[root@localhost fs]# mkfs.ext4 /dev/sdb1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks655776 inodes, 2622603 blocks131130 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=268854886481 block groups32768 blocks per group, 32768 fragments per group8096 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Writing inode tables: done                            Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 39 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost fs]# e2label /dev/sdb1 'mydata'[root@localhost fs]# e2label /dev/sdb1mydata
[root@localhost fs]#vim /etc/fstab
LABEL=mydata                  /mydata                 ext4    defaults        0 0
相關文章
相關標籤/搜索