2018-03-04 磁盤分區(qū)管理

1、如何復(fù)制設(shè)備文件

設(shè)備號(hào)碼:
主設(shè)備號(hào):major number, 標(biāo)識(shí)設(shè)備類型
次設(shè)備號(hào):minor number, 標(biāo)識(shí)同一類型下的不同設(shè)備

[root@centos6 app]#cp -a /dev/zero .
[root@centos6 app]#ll
total 0
crw-rw-rw-. 1 root root 1, 5 Jul 31 13:25 zero
[root@centos6 app]#ll /dev/zero
crw-rw-rw-. 1 root root 1, 5 Jul 31 13:25 /dev/zero
[root@centos6 app]#mknod /app/zero2 c 1 5  ---c表示字符設(shè)備 1和5分別表示主設(shè)備號(hào)和次設(shè)備號(hào)
[root@centos6 app]#ll
total 0
crw-rw-rw-. 1 root root 1, 5 Jul 31 13:25 zero
crw-r--r--. 1 root root 1, 5 Jul 31 17:06 zero2
[root@centos6 app]#ll /dev/sda1
brw-rw----. 1 root disk 8, 1 Jul 31 13:25 /dev/sda1
[root@centos6 app]#mknod /app/sda1 b 8 1
[root@centos6 app]#ll
total 0
brw-r--r--. 1 root root 8, 1 Jul 31 17:15 sda1
crw-rw-rw-. 1 root root 1, 5 Jul 31 13:25 zero
crw-r--r--. 1 root root 1, 5 Jul 31 17:06 zero2
[root@centos6 app]#mount /app/sda1 /mnt/sda
[root@centos6 app]#df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4783956  42920816  11% /
tmpfs             502056     224    501832   1% /dev/shm
/dev/sda3       40185208   49016  38088192   1% /app
/dev/sda1         991512   34904    905408   4% /boot
/dev/sr0         3878870 3878870         0 100% /media/CentOS_6.9_Final
/app/sda1         991512   34904    905408   4% /mnt/sda
[root@centos6 app]#cd /mnt/sda/
[root@centos6 sda]#ls
config-2.6.32-696.el6.x86_64  grub                                 lost+found                        System.map-2.6.32-696.el6.x86_64
efi                           initramfs-2.6.32-696.el6.x86_64.img  symvers-2.6.32-696.el6.x86_64.gz  vmlinuz-2.6.32-696.el6.x86_64

總結(jié):復(fù)制設(shè)備文件可以用cp -a,也可以用mknod,復(fù)制分區(qū)后可以用于掛載,進(jìn)入掛載的目錄,看到的內(nèi)容和復(fù)制的分區(qū)內(nèi)容是一樣的。

2、parted 管理分區(qū)

  • 創(chuàng)建gpt分區(qū)
[root@centos6 ~]#parted /dev/sdb mklabel gpt  ---聲明是要?jiǎng)?chuàng)建gpt分區(qū)
[root@centos6 ~]#parted /dev/sdb mkpart primary 1 1024 ---創(chuàng)建分區(qū)
Information: You may need to update /etc/fstab.                           
[root@centos6 ~]#parted /dev/sdb print  ---打印分區(qū)
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1024MB  1023MB               primary
[root@centos6 ~]#parted /dev/sdb mkpart primary 1025 2048  ---創(chuàng)建第二個(gè)分區(qū)
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? ignore
Information: You may need to update /etc/fstab.                                                                            
[root@centos6 ~]#parted /dev/sdb print  ---打印分區(qū)
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1024MB  1023MB               primary
 2      1025MB  2048MB  1023MB               primary
root@centos6 ~]#dd if=/dev/zero of=/dev/sdb bs=1 count=512   ---破壞gpt分區(qū)的前512個(gè)字節(jié)
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00419461 s, 122 kB/s
[root@centos6 ~]#parted /dev/sdb print   ---打印分區(qū)后仍然有分區(qū)表
Warning: /dev/sdb contains GPT signatures, indicating that it has a GPT table.
However, it does not have a valid fake msdos partition table, as it should.
Perhaps it was corrupted -- possibly by a program that doesn't understand GPT
partition tables.  Or perhaps you deleted the GPT table, and are now using an
msdos partition table.  Is this a GPT partition table?
Yes/No? yes                                                               
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  1024MB  1023MB               primary
 2      1025MB  2048MB  1023MB               primary

總結(jié):gpt分區(qū)破壞前512個(gè)字節(jié)后仍然有分區(qū)表,因?yàn)間pt分區(qū)后面還要備份的分區(qū)表,并不是都在0扇區(qū)內(nèi),因此gpt分區(qū)比較安全。

  • 創(chuàng)建MBR分區(qū)
[root@centos6 ~]#parted /dev/sdb mklabel msdos  ---指定是要?jiǎng)?chuàng)建MBR分區(qū)
[root@centos6 ~]#parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos   ---顯示標(biāo)簽為mbr分區(qū)
Number  Start  End  Size  Type  File system  Flags
[root@centos6 ~]#parted /dev/sdb mkpart extend 1 1024 ---創(chuàng)建一個(gè)擴(kuò)展分區(qū)
Information: You may need to update /etc/fstab.                           
[root@centos6 ~]#parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type      File system  Flags
 1      1049kB  1024MB  1023MB  extended               lba                                                            
[root@centos6 ~]#parted /dev/sdb mkpart primary 1025 2048 ---創(chuàng)建一個(gè)主分區(qū)
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore                                                     
Information: You may need to update /etc/fstab.                           
[root@centos6 ~]#parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type      File system  Flags
 1      1049kB  1024MB  1023MB  extended               lba
 2      1025MB  2048MB  1023MB  primary
[root@centos6 ~]#parted /dev/sdb mkpart logical 5 500 ---創(chuàng)建一個(gè)邏輯分區(qū)
Information: You may need to update /etc/fstab.                           
[root@centos6 ~]#parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type      File system  Flags
 1      1049kB  1024MB  1023MB  extended               lba
 5      5243kB  500MB   495MB   logical
 2      1025MB  2048MB  1023MB  primary
[root@centos6 ~]#dd if=/dev/zero of=/dev/sdb bs=1 count=64 skip=446 seek=446  ---破壞分區(qū)表的64個(gè)字節(jié)
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.0014034 s, 45.6 kB/s
[root@centos6 ~]#fdisk -l /dev/sdb  ---此時(shí)已經(jīng)沒有分區(qū)表信息
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000e89e3 ---仍然顯示有分區(qū)。只是不顯示分區(qū)表
   Device Boot      Start         End      Blocks   Id  System
[root@centos6 ~]#hexdump -C /dev/sdb -n 512  ---55A標(biāo)記位還有
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  e3 89 0e 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200
[root@centos6 ~]#dd if=/dev/zero of=/dev/sdb bs=1 count=66 skip=446 seek=446  ---破壞66個(gè)字節(jié)后55A標(biāo)記位也被破壞
66+0 records in
66+0 records out
66 bytes (66 B) copied, 0.00180802 s, 36.5 kB/s
[root@centos6 ~]#hexdump -C /dev/sdb -n 512
00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  e3 89 0e 00 00 00 00 00  |................|
000001c0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000200
[root@centos6 ~]#fdisk -l /dev/sdb  ---此時(shí)不顯示分區(qū)信息
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000e89e3
[root@centos6 ~]#parted /dev/sdb rm 5  ---刪除分區(qū)

總結(jié):MBR分區(qū)破壞分區(qū)表后就無法顯示分區(qū)表,分區(qū)就被破壞,但仍然顯示有分區(qū)。只有破壞55A標(biāo)記位后才徹底顯示沒有分區(qū)了。
parted對(duì)gpt和mbr分區(qū)都可以進(jìn)行管理和創(chuàng)建,但的操作都是實(shí)時(shí)生效的,小心使用。

3、復(fù)制一個(gè)磁盤的分區(qū)給另外一個(gè)磁盤

[root@centos6 ~]#lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1   3.7G  0 rom  /media/CentOS_6.9_Final
sda      8:0    0   200G  0 disk 
├─sda1   8:1    0  1000M  0 part /boot
├─sda2   8:2    0  48.8G  0 part /
├─sda3   8:3    0  39.1G  0 part /app
├─sda4   8:4    0     1K  0 part 
└─sda5   8:5    0     2G  0 part [SWAP]
sdb      8:16   0   100G  0 disk 
├─sdb1   8:17   0   976M  0 part 
├─sdb2   8:18   0 975.6M  0 part 
├─sdb3   8:19   0   1.9G  0 part 
└─sdb4   8:20   0   1.8G  0 part 
sdc      8:32   0   150G  0 disk 
sdd      8:48   0    80G  0 disk 
[root@centos6 ~]#dd if=/dev/sda of=mbr bs=1 count=512 ---備份/dev/sda 的分區(qū)表信息
512+0 records in
512+0 records out
512 bytes (512 B) copied, 0.00149843 s, 342 kB/s
[root@centos6 ~]#ls
acl.txt          Documents  f3                  mbr       Public
anaconda-ks.cfg  Downloads  install.log         Music     Templates
Desktop          f1         install.log.syslog  Pictures  Videos
[root@centos6 ~]#dd if=mbr of=/dev/sdb ---將/dev/sda分區(qū)表信息拷貝到/dev/sdb
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00501896 s, 102 kB/s
[root@centos6 ~]#fdisk -l /dev/sdb   ---可以看出只復(fù)制了四個(gè)分區(qū),第五個(gè)邏輯分區(qū)并沒有覆蓋
Warning: invalid flag 0x0000 of partition table 5 will be corrected by w(rite)
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x000838ae
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1         128     1024000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2             128        6502    51200000   83  Linux
/dev/sdb3            6502       11601    40960000   83  Linux
/dev/sdb4           11601       26109   116530176    5  Extended

總結(jié):MBR分區(qū)的0磁道0扇區(qū)只保存主分區(qū)和擴(kuò)展分區(qū)的分區(qū)表,邏輯分區(qū)的分區(qū)表在擴(kuò)展分區(qū)的0扇區(qū),不在前512的字節(jié)內(nèi),每一個(gè)邏輯分區(qū)的前面都有一個(gè)分區(qū)表,用來指明邏輯分區(qū)從哪到哪。

4、fdisk管理MBR分區(qū)

[root@centos6 ~]#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)

總結(jié):fdisk管理MBR分區(qū)很方便,根據(jù)提示一步一步的完成就可以,如果記不住可以輸入m看幫助信息。

5、gdisk管理gpt分區(qū)

[root@centos6 ~]#gdisk /dev/sdc
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): ?
b   back up GPT data to a file
c   change a partition's name
d   delete a partition
i   show detailed information on a partition
l   list known partition types
n   add a new partition
o   create a new empty GUID partition table (GPT)
p   print the partition table
q   quit without saving changes
r   recovery and transformation options (experts only)
s   sort partitions
t   change a partition's type code
v   verify disk
w   write table to disk and exit
x   extra functionality (experts only)
?   print this menu

Command (? for help):
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1 概述 本文通過對(duì)講解了磁盤的基本概念,分區(qū),創(chuàng)建文件系統(tǒng),掛載,卸載等步驟進(jìn)行講解。使得用戶能夠創(chuàng)建基本的磁盤...
    ghbsunny閱讀 1,729評(píng)論 0 0
  • 目錄磁盤結(jié)構(gòu)磁盤分區(qū)磁盤分區(qū)管理文件系統(tǒng)管理掛載 一、磁盤結(jié)構(gòu) (一)設(shè)備文件 設(shè)備文件:linux系統(tǒng)下一切皆文...
    哈嘍別樣閱讀 1,212評(píng)論 0 0
  • 1、如何復(fù)制設(shè)備文件 設(shè)備號(hào)碼:主設(shè)備號(hào):major number, 標(biāo)識(shí)設(shè)備類型次設(shè)備號(hào):minor numbe...
    張大志的博客閱讀 427評(píng)論 0 0
  • 導(dǎo)讀目錄 硬盤的組成 硬盤的物理結(jié)構(gòu)主要針對(duì)的是機(jī)械硬盤及其內(nèi)部的結(jié)構(gòu)加以介紹,以下內(nèi)容可能不是硬盤內(nèi)部全部的部件...
    香吉矢閱讀 4,321評(píng)論 0 12
  • 她不用說話,就知道是個(gè)好姑娘。 愛笑,笑起來眼睛月兒彎彎,她們說那是桃花眼;海浪邊站在夕陽(yáng)下,一回頭便笑,戴個(gè)小草...
    江先生__閱讀 125評(píng)論 0 0

友情鏈接更多精彩內(nèi)容