Linux磁盤和文件系統管理

 

Linux磁盤和文件系統管理Linux磁盤和文件系統管理.pdf

Part.I 磁盤管理

1.cfdisk   #圖形化的很簡單. 不知道你們用什么 反正我喜歡這個 ^_^

cfdisk – display or manipulate disk partition table

必要參數的具體說明如下:

-a用箭頭表示選取,而不是以反白表示

-P顯示磁盤分區的內容

-z當作新磁盤直接使用

-c<數目>指定柱面數目,而不考慮BIOS的設置

-h<數目>指定磁頭數目,而不考慮BIOS的設置

-s<數目>指定磁盤分區數目,而不考慮BIOS的設置

-v版本信息

  cfdisk (util-linux 2.23.2)

 

                                   Disk Drive: /dev/sda

                             Size: 21474836480 bytes, 21.4 GB

                   Heads: 255   Sectors per Track: 63   Cylinders: 2610

 

    Name          Flags       Part Type   FS Type            [Label]          Size (MB)

 —————————————————————————————-

                               Pri/Log    Free Space                               1.05  *

    sda1          Boot         Primary    xfs                                    524.29  *

    sda2                       Primary    LVM2_member                          20949.50  *

 

     [   Help   ]  [   New    ]  [  Print   ]  [   Quit   ]  [  Units   ]

     [  Write   ]

 

                           Create new partition from free space

2.sfdisk  #sfdisk為硬盤分區工具程序,可顯示分區的設定信息,并檢查分區是否正常,也可用來建立分區。

-s [or –show-size] 顯示一個分區的大小

-c [or –id]顯示或者修改文件系統類型ID

-l [or –list]顯示每個設備的分區表信息

-d [or –dump]同上,但是以一個格式化的方式輸出

-i [or –increment]number cylinders etc. from 1 instead of from 0

-uS, -uB, -uC, -uM 以扇面//柱面數/MB為單位 顯示或形成報告

-T [or –list-types]顯示所有已知的sfdisk能辨識的文件系統ID

-D [or –DOS] 兼容DOS但是會浪費一點磁盤空間

-R [or –re-read]:讓內核重新讀取分區表

-N# 只改變分區的編號 #

-n 修改但實際上并沒有保存到磁盤

-O file 保存扇面修改并寫入分區表文件

-I file 重新恢復修改的扇面

sfdisk -d /dev/hda > hda-table 備份分區表并保存到文件

sfdisk /dev/hda < hda-table 從文件中恢復分區表

sfdisk -d /dev/hda | sfdisk /dev/hdb 在兩個磁盤間復制分區表

[root@localhost ~]# sfdisk

 

Usage:

 sfdisk [options] <device> […]

 

Options:

 -s, –show-size           list size of a partition

 -c, –id                  change or print partition Id

     –change-id           change Id

     –print-id            print Id

 -l, –list                list partitions of each device

 -d, –dump                idem, but in a format suitable for later input

 -i, –increment           number cylinders etc. from 1 instead of from 0

 -u, –unit <letter>       units to be used; <letter> can be one of

                             S (sectors), C (cylinders), B (blocks), or M (MB)

 -1, –one-only            reserved option that does nothing currently

 -T, –list-types          list the known partition types

 -D, –DOS                 for DOS-compatibility: waste a little space

 -E, –DOS-extended        DOS extended partition compatibility

 -R, –re-read             make the kernel reread the partition table

 -N <number>               change only the partition with this <number>

 -n                        do not actually write to disk

 -O <file>                 save the sectors that will be overwritten to <file>

 -I <file>                 restore sectors from <file>

 -V, –verify              check that the listed partitions are reasonable

 -v, –version             display version information and exit

 -h, –help                display this help text and exit

 

Dangerous options:

 -f, –force               disable all consistency checking

     –no-reread           do not check whether the partition is in use

 -q, –quiet               suppress warning messages

 -L, –Linux               do not complain about things irrelevant for Linux

 -g, –show-geometry       print the kernel's idea of the geometry

 -G, –show-pt-geometry    print geometry guessed from the partition table

 -A, –activate[=<device>] activate bootable flag

 -U, –unhide[=<dev>]      set partition unhidden

 -x, –show-extended       also list extended partitions in the output,

                             or expect descriptors for them in the input

     –leave-last          do not allocate the last cylinder

     –IBM                 same as –leave-last

     –in-order            partitions are in order

     –not-in-order        partitions are not in order

     –inside-outer        all logicals inside outermost extended

     –not-inside-outer    not all logicals inside outermost extended

     –nested              every partition is disjoint from all others

     –chained             like nested, but extended partitions may lie outside

     –onesector           partitions are mutually disjoint

 

Override the detected geometry using:

 -C, –cylinders <number>  set the number of cylinders to use

 -H, –heads <number>      set the number of heads to use

 -S, –sectors <number>    set the number of sectors to use

 

3. parted   #磁盤分區和分區大小調整工具,與fdisk不同,它支持調整分區的大小。

-h顯示幫助信息

-i交互式模式

-s腳本模式,不提示用戶

-v顯示版本號

實例<Via http://man.linuxde.net/parted >

紅帽企業 Linux 4 Update 4供對大于 2 terabytesTB)的磁盤設備的支持。

[root@localhost ~]# fdisk -l

Disk /dev/sda: 35.8 GB, 35862976512 bytes

255 heads, 63 sectors/track, 4360 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14         144     1052257+  82  Linux swap

/dev/sda3             145        4360    33865020   83  Linux

Disk /dev/sdb: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

[root@localhost ~]# parted /dev/sdb

GNU Parted Copyright (C) 1998 – 2004 free Software Foundation, Inc.

This program is free software, covered by the GNU General Public License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY

WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A

PARTICULAR PURPOSE.  See the GNU General Public License for more details.

使用/dev/sdb

(parted)mklabel gpt

(parted)print

/dev/sdb的磁盤幾何結構:0.000-2048.000兆字節

磁盤標簽類型:gpt

Minor   起始點       終止點 文件系統   名稱                 標志

(parted)mkpart primary 0 2048  <—–上面print顯示的數字

(parted)print

/dev/sdb的磁盤幾何結構:0.000-2048.000兆字節

磁盤標簽類型:gpt

Minor   起始點       終止點 文件系統   名稱                 標志

1          0.017   2047.983

(parted)quit

如果必要,不要忘記更新/etc/fstab。

[root@localhost ~]# fdisk -l

Disk /dev/sda: 35.8 GB, 35862976512 bytes

255 heads, 63 sectors/track, 4360 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          13      104391   83  Linux

/dev/sda2              14         144     1052257+  82  Linux swap

/dev/sda3             145        4360    33865020   83  Linux

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.

 

Disk /dev/sdb: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         262     2097151+  ee  EFI GPT

Partition 1 has different physical/logical beginnings (non-Linux?):

     phys=(0, 0, 1) logical=(0,0, 2)

Partition 1 has different physical/logical endings:

     phys=(1023, 254, 63) logical=(261, 21, 16)

[root@localhost ~]# mkfs.ext3 /dev/sdb1

mke2fs 1.35 (28-Feb-2004)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

262144 inodes, 524279 blocks

26213 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=536870912

16 block groups

32768 blocks per group, 32768 fragments per group

16384 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912

Writing inode tables: done

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost ~]# mount /dev/sdb1 /mnt

[root@localhost ~]# df -h

Filesystem            容量  已用 可用 已用% 掛載點

/dev/sda3              <?xml:namespace prefix = st1 />32G  2.6G   28G   9% /

/dev/sda1              99M   12M   82M  13% /boot

none                  252M     0  252M   0% /dev/shm

/dev/sdb1             2.0G   36M  1.9G   2% /mnt

 

 

4.fdisk   #老牌分區軟件<Via http://man.linuxde.net/fdisk>

-b<分區大小>指定每個分區的大小

-l列出指定的外圍設備的分區表狀況

-s<分區編號>將指定的分區大小輸出到標準輸出上,單位為區塊

-u搭配"-l"參數列表,會用分區數目取代柱面數目,來表示每個分區的起始地址

-v顯示版本信息。

[root@localhost ~]# fdisk /dev/sdb

command (m for help): m

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition

   l   list known partition types

   m   print this menu

   n   add a new partition

   o   create a new empty DOS partition table

   p   print the partition table

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit

   x   extra functionality (experts only)

Command (m for help): p

 

Disk /dev/sdb: 3221 MB, 3221225472 bytes

255 heads, 63 sectors/track, 391 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1           1        8001   8e  Linux LVM

/dev/sdb2               2          26      200812+  83  Linux

Command (m for help): d

Partition number (1-4): 1

 

Command (m for help): d

Selected partition 2

Command (m for help): print

 

Disk /dev/sdb: 3221 MB, 3221225472 bytes

255 heads, 63 sectors/track, 391 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

 

Command (m for help):

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p    //建立主分區

Partition number (1-4): 1  //分區號

First cylinder (1-391, default 1):  //分區起始位置

Using default value 1

last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100  //分區結束位置,單位為扇區

 

Command (m for help): n  //再建立一個分區

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 2  //分區號為2

First cylinder (101-391, default 101):

Using default value 101

Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M  //分區結束位置,單位為M

Command (m for help): p

 

Disk /dev/sdb: 3221 MB, 3221225472 bytes

255 heads, 63 sectors/track, 391 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         100      803218+  83  Linux

/dev/sdb2             101         125      200812+  83  Linux

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

e  //選擇擴展分區

Partition number (1-4): 3

First cylinder (126-391, default 126):

Using default value 126

Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):

Using default value 391

Command (m for help): p

 

Disk /dev/sdb: 3221 MB, 3221225472 bytes

255 heads, 63 sectors/track, 391 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         100      803218+  83  Linux

/dev/sdb2             101         125      200812+  83  Linux

/dev/sdb3             126         391     2136645    5  Extended

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l //選擇邏輯分區

First cylinder (126-391, default 126):

Using default value 126

Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M   

 

Command (m for help): n

Command action

   l   logical (5 or over)

   p   primary partition (1-4)

l

First cylinder (176-391, default 176):

Using default value 176

Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):

Using default value 391

Command (m for help): p

 

Disk /dev/sdb: 3221 MB, 3221225472 bytes

255 heads, 63 sectors/track, 391 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         100      803218+  83  Linux

/dev/sdb2             101         125      200812+  83  Linux

/dev/sdb3             126         391     2136645    5  Extended

/dev/sdb5             126         175      401593+  83  Linux

/dev/sdb6             176         391     1734988+  83  Linux

 

Command (m for help):

在硬盤sdb我們建立了2個主分區(sdb1,sdb2),1個擴展分區(sdb3),2個邏輯分區(sdb5,sdb6

注意:主分區和擴展分區的磁盤號位1-4,也就是說最多有4個主分區或者擴展分區,邏輯分區開始的磁盤號為5,因此在這個實驗中試沒有sdb4的。

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]# mkfs.ext2 /dev/sdb1

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

100576 inodes, 200804 blocks

10040 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=209715200

7 block groups

32768 blocks per group, 32768 fragments per group

14368 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840

 

Writing inode tables: done                          

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 32 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost ~]# mkfs.ext3 /dev/sdb6

mke2fs 1.39 (29-May-2006)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

217280 inodes, 433747 blocks

21687 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=444596224

14 block groups

32768 blocks per group, 32768 fragments per group

15520 inodes per group

Superblock backups stored on blocks:

        32768, 98304, 163840, 229376, 294912

 

Writing inode tables: done                          

Creating journal (8192 blocks): done

Writing superblocks and filesystem accounting information: done

 

This filesystem will be automatically checked every 32 mounts or

180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost ~]#

建立兩個目錄/oracle和/web,將新建好的兩個分區掛載到系統:

[root@localhost ~]# mkdir /oracle

[root@localhost ~]# mkdir /web

[root@localhost ~]# mount /dev/sdb1 /oracle

[root@localhost ~]# mount /dev/sdb6 /web

查看分區掛載情況:

[root@localhost ~]# df -h

文件系統              容量  已用 可用 已用% 掛載點

/dev/mapper/VolGroup00-LogVol00

                      6.7G  2.8G  3.6G  44% /

/dev/sda1              99M   12M   82M  13% /boot

tmpfs                 125M     0  125M   0% /dev/shm

/dev/sdb1             773M  808K  733M   1% /oracle

/dev/sdb6             1.7G   35M  1.6G   3% /web

如果需要每次開機自動掛載則需要修改/etc/fstab文件,加入兩行配置:

[root@localhost ~]# vim /etc/fstab

 

/dev/VolGroup00/LogVol00 /                       ext3    defaults        1 1

LABEL=/boot             /boot                   ext3    defaults        1 2

tmpfs                   /dev/shm                tmpfs   defaults        0 0

devpts                  /dev/pts                devpts  gid=5,mode=620  0 0

sysfs                   /sys                    sysfs   defaults        0 0

proc                    /proc                   proc    defaults        0 0

/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0

/dev/sdb1               /oracle                 ext2    defaults        0 0

/dev/sdb6               /web                    ext3    defaults        0 0

 

5.df   #顯示磁盤分區上的可使用的磁盤空間

-a [or –all ]包含全部的文件系統

–block-size=<區塊大小>以指定的區塊大小來顯示區塊數目

-h [ or–human-readable ]以可讀性較高的方式來顯示信息

-H [ or—si ]-h參數相同,但在計算時是以1000 Bytes為換算單位而非1024 Bytes

-I  [or—inodes ]顯示inode的信息

-k [ or—kilobytes ]指定區塊大小為1024字節

-l  [ —local ]僅顯示本地端的文件系統

-m [ or—megabytes ]指定區塊大小為1048576字節

–no-sync在取得磁盤使用信息前,不要執行sync指令,此為預設值

-P [ or—portability ]使用POSIX的輸出格式

–sync在取得磁盤使用信息前,先執行sync指令

-t<文件系統類型>–type=<文件系統類型>僅顯示指定文件系統類型的磁盤信息

-T [ or–print-type ]顯示文件系統的類型

-x<文件系統類型>–exclude-type=<文件系統類型>不要顯示指定文件系統類型的磁盤信息

–help顯示幫助

–version顯示版本信息

[root@LinServ-1 ~]# df

文件系統               1K-塊        已用     可用 已用% 掛載點

/dev/sda2            146294492  28244432 110498708  21% /

/dev/sda1              1019208     62360    904240   7% /boot

tmpfs                  1032204         0   1032204   0% /dev/shm

/dev/sdb1            2884284108 218826068 2518944764   8% /data1

使用-h選項以KB以上的單位來顯示,可讀性高:

[root@LinServ-1 ~]# df -h

文件系統              容量  已用 可用 已用% 掛載點

/dev/sda2             140G   27G  106G  21% /

/dev/sda1             996M   61M  884M   7% /boot

tmpfs                1009M     0 1009M   0% /dev/shm

/dev/sdb1             2.7T  209G  2.4T   8% /data1

查看全部文件系統:

[root@LinServ-1 ~]# df -a

文件系統               1K-塊        已用     可用 已用% 掛載點

/dev/sda2            146294492  28244432 110498708  21% /

proc                         0         0         0   –  /proc

sysfs                        0         0         0   –  /sys

devpts                       0         0         0   –  /dev/pts

/dev/sda1              1019208     62360    904240   7% /boot

tmpfs                  1032204         0   1032204   0% /dev/shm

/dev/sdb1            2884284108 218826068 2518944764   8% /data1

none                         0         0         0   –  /proc/sys/fs/binfmt_misc

 

6.du  #顯示目錄下所有文件和子目錄占用磁盤空間大小

-a [ or-all ] 顯示目錄中個別文件的大小

-b [ or-bytes ] 顯示目錄或文件大小時,以byte為單位

-c [ or—total ] 除了顯示個別目錄或文件的大小外,同時也顯示所有目錄或文件的總和

-k [ or—kilobytes ] KB(1024bytes)為單位輸出

-m [ or—megabytes ] MB為單位輸出

-s [ or–summarize ]僅顯示總計,只列出最后加總的值

-h [ or–human-readable ] K,MG為單位,提高信息的可讀性

-x [ or–one-file-xystem ] 以一開始處理時的文件系統為準,若遇上其它不同的文件系統目錄則略過

-L<符號鏈接> [ or–dereference<符號鏈接> ] 顯示選項中所指定符號鏈接的源文件大小

-S [ or–separate-dirs ] 顯示個別目錄的大小時,并不含其子目錄的大小

-X<文件> [ or–exclude-from=<文件> ] <文件>指定目錄或文件

–exclude=<目錄或文件> 略過指定的目錄或文件

-D [ or–dereference-args ] 顯示指定符號鏈接的源文件大小

-H [ or—si ] -h參數相同,但是K,M,G是以1000為換算單位

-l [ or –count-links ] 重復計算硬件鏈接的文件

[root@localhost ~]# du /tmp –max-depth=2

0        /tmp/.X11-unix

0        /tmp/.XIM-unix

0        /tmp/.Test-unix

0        /tmp/.ICE-unix

0        /tmp/.font-unix

32       /tmp/hsperfdata_root

0        /tmp/.esd-0

0        /tmp/tracker-extract-files.0

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-vmtoolsd.service-6B52wS/tmp

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-vmtoolsd.service-6B52wS

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-cups.service-NRAW9g/tmp

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-cups.service-NRAW9g

0        /tmp/.esd-988

0        /tmp/.esd-1000

0        /tmp/tracker-extract-files.1000

0        /tmp/hsperfdata_lethe

0        /tmp/kde-root

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-colord.service-8pFC1a/tmp

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-colord.service-8pFC1a

0        /tmp/akonadi-root.m8CZHQ

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-rtkit-daemon.service-rJ2EvH/tmp

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-rtkit-daemon.service-rJ2EvH

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-vmtoolsd.service-YnwnWL/tmp

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-vmtoolsd.service-YnwnWL

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-cups.service-5FlgDB/tmp

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-cups.service-5FlgDB

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-colord.service-KmmVvc/tmp

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-colord.service-KmmVvc

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-rtkit-daemon.service-K7mkBA/tmp

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-rtkit-daemon.service-K7mkBA

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-vmtoolsd.service-zUafAT/tmp

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-vmtoolsd.service-zUafAT

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-cups.service-X0i2eR/tmp

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-cups.service-X0i2eR

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-colord.service-M4XbD4/tmp

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-colord.service-M4XbD4

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-rtkit-daemon.service-qO3RUJ/tmp

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-rtkit-daemon.service-qO3RUJ

48       /tmp

[root@localhost ~]# du /tmp –max-depth=1

0        /tmp/.X11-unix

0        /tmp/.XIM-unix

0        /tmp/.Test-unix

0        /tmp/.ICE-unix

0        /tmp/.font-unix

32       /tmp/hsperfdata_root

0        /tmp/.esd-0

0        /tmp/tracker-extract-files.0

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-vmtoolsd.service-6B52wS

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-cups.service-NRAW9g

0        /tmp/.esd-988

0        /tmp/.esd-1000

0        /tmp/tracker-extract-files.1000

0        /tmp/hsperfdata_lethe

0        /tmp/kde-root

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-colord.service-8pFC1a

0        /tmp/akonadi-root.m8CZHQ

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-rtkit-daemon.service-rJ2EvH

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-vmtoolsd.service-YnwnWL

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-cups.service-5FlgDB

0        /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-colord.service-KmmVvc

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-rtkit-daemon.service-K7mkBA

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-vmtoolsd.service-zUafAT

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-cups.service-X0i2eR

0        /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-colord.service-M4XbD4

0        /tmp/systemd-private-4600be2ef5184890a45864550edac96b-rtkit-daemon.service-qO3RUJ

48       /tmp

 

7.dd  #吊炸天的好東西作用:“可從標準輸入或文件讀取數據,依指定的用法來轉換數據,再輸出到文件、 設備或標準輸出。

bs  <字節數〉設置輸入/輸出的字節數

cbs  <字節數〉設置轉換的字節數

conv   <關鍵字〉轉換方式

cout=<區塊數〉指定讀取的區塊數。

ibs  <字節數〉設置每次讀取的字節數。

If=〈文件〉指定文件作為讀取的對象

obs  <字節數〉設置每次輸出的字節數

of=<文件> 將結果輸出到指定的文件

seek   <區塊數〉忽略指定的區塊數,不進行輸出

skip  <區塊數〉忽略指定的區塊數,不進行讀取

help 顯示幫助信息

version 顯示版本信息

實例

( 1 軟盤互相復制

要把一張軟盤的內容復制到另一張軟盤上 ,利用/tmp 作為臨時存儲區。把源盤插入驅 動據中,輸入下述命令:  

$ dd if  =/dev/fd0  of  = / tmp/ tmpf ile

復制完成后,將源盤從驅動器中取出,把目標盤插入 ,輸入命令 :

$  dd  if  =  / tmp/ tmpf ile of   =/dev /f d0

復制完成后,應該將臨時文件刪除=

 

(2 net.i 這個文件寫入盤中,并設定讀/寫緩沖區的數目 〈注意:軟盤中的內容會

被完全覆蓋掉〉

$ dd  if  =  net.i of =  /dev /fd0 bs =  16384

(3 將文件 sflle 復制到文件 dfile 

$  dd   if =sfile  of =dfile

(4 整盤數據備份與恢復

整盤數據備份

將本地的/dev/hdx 整盤備份到/dev/hdy:

dd if =/dev/hdx  of =/dev/hdy

將/dev/hdx 全盤數據備份到指定路徑的 image 文件:

dd if =/dev/hdx   of=/path/to/image

備份/dev/hdx 金盤數據,并利用 gzip 工具進行壓縮,保存到指定路徑:

dd if=/dev/hdx  | gzip /path/to/image .gz

將備份文件恢復到指定盤:

dd if=/path/to/ image  of =/dev/hdx

將壓縮的備份文件恢復到指定盤:

gzip -dc  /path/to/ image.gz | dd  of=/dev/hdx

(5 備份恢復 MBR 記錄

① 備份 MBR 記錄

備份磁盤開始的 5128  大小的隊在BR 信息到指定文件:

dd if=/dev/hdx of=/path/to/image count=l  bs=512

② 恢復 MBR 記錄

將備份的MBR  信息寫到磁盤開始部分:

dd if =/path/to/image of =/dev/hdx

(6 復制內存資料到硬盤

將內存里的數據復制到 root  目錄下的 mem.bin 文件:

dd if =/dev/ mem of =/ root /mem .bin bs= 1024

耍從光盤復制 iso 鏡像,可復制光盤數據到 root 文件夾下,并保存為cd.iso 文件:

dd   if =/dev/cdrom  of =/root/cd.iso

(7 增加 swap 分區文件大小 創建一個足夠大的文件 (此處為 256MB )

dd if =/dev/ zero of =/swapfile bsa1024  count= 262144

 

 

把這個文件變成 swap 文件: mkswap /swa2file

啟用這個 swap 文件: swapon /swapfile

在每次開機的時候自動加載 swap 文件,需要在/etc/fstab 文件中增加一行:

/swapfile swap  swap defaults O  O

( 8 銷毀磁盤數據 利用隨機的數據填充硬盤:

dd if =/dev/urandom of =/dev/hdal

在某些必要的場合可以用來銷毀數據。執行此操作以后 ,dev/hdal 將無法掛載,創建 和復制操作無法執行。

( 9 修復硬盤

當硬盤較長時 〈比如一兩年〉 放置不使用后,磁盤上會產生 magnetic  flux point 。當 磁頭讀到這些區域時會遇到困難,并可能導致 1/0 錯誤。當這種情況影響到硬盤的第一個 扇區時,可能導致硬盤報廢。下面的命令有可能使這些數據起死回生:

dd  if=/dev/sda   of =/dev/sda

 

8.

                                                     未完待續明天再寫                    

                                                                                       ByLethe

                                                                                      20160X0X

勘誤:

    暫無 mailto:lethe@lethe.com

 

原創文章,作者:雙慶 李,如若轉載,請注明出處:http://www.www58058.com/14134

(0)
雙慶 李雙慶 李
上一篇 2016-04-05
下一篇 2016-04-05

相關推薦

  • linux終端類型

    人機交互界面:GUI、CLI GUI: gnome:c,gtk kde:c++,qt CLI: bash,zsh,sh,csh,ksh 不同CLI間跳轉:alt+f1\f2\f3\f4   終端類型: 物理終端、控制臺終端:/dev/console,控制臺console 計算機顯示器通常被稱為控制臺終端(Console) 虛擬終端:/dev/tty…

    Linux干貨 2016-10-14
  • 第四周作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其他用戶均沒有任何訪問權限 答:     復制目錄:cp -R /etc/skel /home/tuser1     修改權限:chmod -R go=- /home/tuser1 2、編輯/etc/group文件…

    Linux干貨 2016-12-07
  • 第四周作業

    1、復制/etc/skel目錄為/home/tuser1,要求/home/tuser1及其內部文件的屬組和其它用戶均沒有任何訪問權限;          [root@yangjifeng~]# cp -a /etc/skel /home/tuser1 [root@yangjife…

    Linux干貨 2017-08-28
  • 常見文件管理命令及bash特性

    cat:查看文件文本內容  -n:顯示行號  [root@study ~]# cat -n /etc/passwd  1  root:x:0:0:root:/root:/bin/bash  2  bin:x:1:1:bin:/bin:/sb…

    系統運維 2016-11-06
  • 文本編輯sed

    *** sed:Stream EDitor  流編輯器 一次處理一行內容 sed [option]…  'script'  inputfile…常用選項:     -n∶使用安靜(silent)模式。在一般 sed 的用法中, &nbs…

    Linux干貨 2016-08-10
  • 第一周作業

    1、描述計算機的組成及其功能。 計算機的基本功能:數據處理、數據存儲、數據傳輸、控制; 計算機中的數據:包含計算機所能處理的給中對象,如數值、字符、圖形、圖像、聲音、視頻等。 計算機的所有功能都是通過指令實現的。 指令:是計算機硬件能直接識別并執行的命令,不同種類的計算機通常有著不同的指令編碼,一臺計算機的所有指令集合稱之為指令系統。若干條指令組成的一個指令…

    Linux干貨 2016-12-12

評論列表(1條)

  • stanley
    stanley 2016-04-05 22:51

    寫標簽提高文章收錄率,樣式上建議使用markdown

欧美性久久久久