Latest web development tutorials

manajemen disk Linux

Linux manajemen disk langsung berkaitan dengan kualitas kinerja manajemen dari keseluruhan sistem.

Linux perintah manajemen disk dari tiga yang umum digunakan df, du, dan fdisk.

  • df: Daftar penggunaan disk keseluruhan sistem file
  • du: Periksa jumlah penggunaan ruang disk
  • fdisk: untuk partisi

df

df parameter perintah Fungsi: Periksa sistem file disk space hunian. Anda dapat menggunakan perintah ini untuk mendapatkan hard drive mengambil banyak ruang, berapa banyak ruang yang masih tersisa dan informasi lainnya.

sintaks:

df [-ahikHTm] [目录或文件名]

Pilihan dan parameter:

  • -a: Daftar semua file sistem, termasuk sistem / proc file sistem tertentu, dll;
  • -k: KByte kapasitas untuk menampilkan semua file system;
  • -m: MBytes kapasitas untuk menampilkan semua file system;
  • -h: Lebih mudah untuk dibaca GBytes, MBytes, KByte format tampilan sendiri;
  • -H: M = 1000K untuk menggantikan M = 1024K carry cara;
  • -T: Menampilkan jenis sistem file, bersama-sama dengan nama partisi filesystem (seperti ext3) juga tercantum;
  • -i: tanpa kapasitas hard drive, dan untuk jumlah inode untuk menampilkan

contoh 1

Sistem akan semua sistem file tercantum!

[root@www ~]# df
Filesystem      1K-blocks      Used Available Use% Mounted on
/dev/hdc2         9920624   3823112   5585444  41% /
/dev/hdc3         4956316    141376   4559108   4% /home
/dev/hdc1          101086     11126     84741  12% /boot
tmpfs              371332         0    371332   0% /dev/shm

Linux df bawahnya jika tidak menambahkan opsi apapun, maka sistem akan default di semua (termasuk sistem file khusus dan swap memori di dalam) berada di 1 Kbytes kapasitas untuk dicatatkan!

contoh 2

Hasil kapasitas ditampilkan dalam format yang mudah-kapasitas

[root@www ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/hdc2             9.5G  3.7G  5.4G  41% /
/dev/hdc3             4.8G  139M  4.4G   4% /home
/dev/hdc1              99M   11M   83M  12% /boot
tmpfs                 363M     0  363M   0% /dev/shm

contoh 3

Semua format file khusus dan namanya tercantum dalam sistem

[root@www ~]# df -aT
Filesystem    Type 1K-blocks    Used Available Use% Mounted on
/dev/hdc2     ext3   9920624 3823112   5585444  41% /
proc          proc         0       0         0   -  /proc
sysfs        sysfs         0       0         0   -  /sys
devpts      devpts         0       0         0   -  /dev/pts
/dev/hdc3     ext3   4956316  141376   4559108   4% /home
/dev/hdc1     ext3    101086   11126     84741  12% /boot
tmpfs        tmpfs    371332       0    371332   0% /dev/shm
none   binfmt_misc         0       0         0   -  /proc/sys/fs/binfmt_misc
sunrpc  rpc_pipefs         0       0         0   -  /var/lib/nfs/rpc_pipefs

contoh 4

Tersedia kapasitas disk / dll di bawah layar ke format volume yang dibaca

[root@www ~]# df -h /etc
Filesystem            Size  Used Avail Use% Mounted on
/dev/hdc2             9.5G  3.7G  5.4G  41% /

du

inux du perintah juga melihat penggunaan ruang, tetapi dengan perintah df adalah file yang berbeda Linux perintah du dan direktori menggunakan ruang disk untuk melihat, atau perintah df dan ada beberapa perbedaan, di sini Linux perintah du.

sintaks:

du [-ahskm] 文件或目录名称

Pilihan dan parameter:

  • -a: daftar semua file dan direktori kapasitas karena hanya jumlah direktori file default bawah statistik saja.
  • -h: Lebih mudah untuk membaca format volume (G / M) layar;
  • -s: Daftar jumlah total itu, daripada daftar kapasitas masing-masing direktori hunian masing;
  • -S: Total tidak termasuk subdirektori, dan -s sedikit berbeda.
  • -k: tercantum di display kapasitas KByte;
  • -m: Dalam MBytes terdaftar display kapasitas;

contoh 1

Daftar semua ukuran file dari direktori saat ini

[root@www ~]# du
8       ./test4     <==每个目录都会列出来
8       ./test2
....中间省略....
12      ./.gconfd   <==包括隐藏文件的目录
220     .           <==这个目录(.)所占用的总量

Tidak ada masukan langsung du ditambah opsi apapun, maka du menganalisa direktori saat file dan direktori menempati ruang hard disk.

contoh 2

Dokumen tersebut juga tercantum kapasitas

[root@www ~]# du -a
12      ./install.log.syslog   <==有文件的列表了
8       ./.bash_logout
8       ./test4
8       ./test2
....中间省略....
12      ./.gconfd
220     .

contoh 3

Periksa di bawah direktori root masing-masing kapasitas diduduki

[root@www ~]# du -sm /*
7       /bin
6       /boot
.....中间省略....
0       /proc
.....中间省略....
1       /tmp
3859    /usr     <==系统初期最大就是他了啦!
77      /var

Wildcard * untuk mewakili setiap direktori.

Dan df tidak sama, du fakta, perintah ini langsung ke sistem file untuk mencari semua file data.


fdisk

fdisk adalah Linux partisi disk alat manipulasi tabel.

sintaks:

fdisk [-l] 装置名称

Pilihan dan parameter:

  • l: Semua isi dari partisi belakang perangkat output terhubung. Jika hanya fdisk-l, maka sistem akan dapat mencari seluruh partisi sistem untuk perangkat tercantum.

contoh 1

Daftar semua informasi partisi

[root@AY120919111755c246621 tmp]# fdisk -l

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2550    20480000   83  Linux
/dev/xvda2            2550        2611      490496   82  Linux swap / Solaris

Disk /dev/xvdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x56f40944

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb2               1        2610    20964793+  83  Linux

contoh 2

Cari tahu apa sistem direktori root disk Anda berada, dan akses ke informasi yang relevan tentang hard disk di dalam

[root@www ~]# df /            <==注意:重点在找出磁盘文件名而已
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/hdc2              9920624   3823168   5585388  41% /

[root@www ~]# fdisk /dev/hdc  <==仔细看,不要加上数字喔!
The number of cylinders for this disk is set to 5005.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):     <==等待你的输入!

Setelah memasukkan m, Anda akan melihat pengenalan perintah ini di bawah

Command (m for help): m   <== 输入 m 后,就会看到底下这些命令介绍
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition            <==删除一个partition
   l   list known partition types
   m   print this menu
   n   add a new partition           <==新增一个partition
   o   create a new empty DOS partition table
   p   print the partition table     <==在屏幕上显示分割表
   q   quit without saving changes   <==不储存离开fdisk程序
   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)

Tekan untuk meninggalkan fdisk q , maka semua tindakan tidak akan berlaku! Sebaliknya, tekan w arti dari tindakan untuk mengambil efek.

Command (m for help): p  <== 这里可以输出目前磁盘的状态

Disk /dev/hdc: 41.1 GB, 41174138880 bytes        <==这个磁盘的文件名与容量
255 heads, 63 sectors/track, 5005 cylinders      <==磁头、扇区与磁柱大小
Units = cylinders of 16065 * 512 = 8225280 bytes <==每个磁柱的大小

   Device Boot      Start         End      Blocks   Id  System
/dev/hdc1   *           1          13      104391   83  Linux
/dev/hdc2              14        1288    10241437+  83  Linux
/dev/hdc3            1289        1925     5116702+  83  Linux
/dev/hdc4            1926        5005    24740100    5  Extended
/dev/hdc5            1926        2052     1020096   82  Linux swap / Solaris
# 装置文件名 启动区否 开始磁柱    结束磁柱  1K大小容量 磁盘分区槽内的系统

Command (m for help): q

Ingin meninggalkan tanpa menyimpannya? Tekan q di sebelah kanan! Jangan tekan w ah!

Gunakan p untuk daftar saat ini informasi tabel partisi Fengyun disk, informasi di atas setengah menunjukkan status keseluruhan dari disk.


Format Disk

Setelah selesainya partisi disk alami diformat dengan sistem file, perintah diformat sangat mudah digunakan mkfs (make filesystem) perintah.

sintaks:

mkfs [-t 文件系统格式] 装置文件名

Pilihan dan parameter:

  • -t: Anda dapat mengakses format file sistem, seperti ext3, ext2, vfat, dll (sistem pendukung untuk berlaku)

contoh 1

Lihat mkfs didukung format file

[root@www ~]# mkfs[tab][tab]
mkfs         mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.msdos   mkfs.vfat

Tekan dua [tab], seperti yang ditunjukkan di atas mkfs akan menemukan format file yang didukung.

contoh 2

Partisi / dev / hdc6 (Anda dapat menentukan partisi sendiri) diformat sebagai sistem file ext3:

[root@www ~]# mkfs -t ext3 /dev/hdc6
mke2fs 1.39 (29-May-2006)
Filesystem label=                <==这里指的是分割槽的名称(label)
OS type: Linux
Block size=4096 (log=2)          <==block 的大小配置为 4K 
Fragment size=4096 (log=2)
251392 inodes, 502023 blocks     <==由此配置决定的inode/block数量
25101 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=515899392
16 block groups
32768 blocks per group, 32768 fragments per group
15712 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 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
# 这样就创建起来我们所需要的 Ext3 文件系统了!简单明了!

Uji Disk

fsck (file system cek) untuk memeriksa dan memelihara sistem file tidak konsisten.

Jika kegagalan daya sistem atau disk yang terjadi masalah, Anda dapat menggunakan perintah fsck untuk memeriksa sistem file.

sintaks:

fsck [-t 文件系统] [-ACay] 装置名称

Pilihan dan parameter:

  • -t: jenis tertentu sistem file, atau kernel sendiri telah ditetapkan untuk mendukung jika / etc / fstab tidak diperlukan dalam parameter ini ditambah
  • -s: berurutan satu per satu untuk memeriksa eksekusi perintah fsck
  • -A: Untuk / etc / partisi fstab (partisi) untuk melakukan semua pemeriksaan yang terdaftar
  • -C: Menampilkan kemajuan cek lengkap
  • -d debug print out hasil e2fsck
  • -p: -A kondisi pada saat yang sama ada, ada beberapa pemeriksaan fsck dilakukan bersama-sama
  • -R: -A Kondisi saat keduanya telah dihilangkan / tidak diperiksa
  • -V: Mode tampilan lengkap
  • -a: Jika cek yang salah secara otomatis memperbaiki
  • r: Periksa apakah jawabannya adalah salah oleh perbaikan pengguna
  • -y: Opsi menentukan deteksi setiap file secara otomatis masuk ya, ketidakpastian yang tidak normal, mereka dapat melakukan semua pemeriksaan # fsck perbaikan -y.

contoh 1

Lihat berapa banyak sistem file yang didukung oleh sistem perintah fsck:

[root@www ~]# fsck[tab][tab]
fsck         fsck.cramfs  fsck.ext2    fsck.ext3    fsck.msdos   fsck.vfat

contoh 2

Wajib pengujian / dev / hdc6 Subbagian:

[root@www ~]# fsck -C -f -t ext3 /dev/hdc6 
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
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
vbird_logical: 11/251968 files (9.1% non-contiguous), 36926/1004046 blocks

Jika Anda tidak menambahkan opsi -f, karena sistem file tidak memiliki masalah, periksa melalui sangat cepat! -f Jika ditambah dengan proses pengujian wajib akan menampilkan satu persatu.


Disk gunung dan turun

Linux disk yang terpasang menggunakan mount perintah, uninstall menggunakan umount perintah.

sintaks Disk gunung:

mount [-t 文件系统] [-L Label名] [-o 额外选项] [-n]  装置文件名  挂载点

contoh 1

Default seperti itu hanya akan membuat / dev / hdc6 mount / mnt / hdc6 atas!

[root@www ~]# mkdir /mnt/hdc6
[root@www ~]# mount /dev/hdc6 /mnt/hdc6
[root@www ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
.....中间省略.....
/dev/hdc6              1976312     42072   1833836   3% /mnt/hdc6

Disk uninstall perintah umount sintaks:

umount [-fn] 装置文件名或挂载点

Pilihan dan parameter:

  • -f: Angkatan turun! Tersedia dalam kasus sistem file jaringan yang sama (NFS) tidak dapat dibaca untuk;
  • -n: tidak meng-upgrade di / etc / situasi mtab turun.

Uninstall / dev / hdc6

[root@www ~]# umount /dev/hdc6