page counter next up previous contents
Next: Chronyd vs. ntpd 校時 Up: fdisk 硬碟分割 Previous: v6 fdisk 使用   Contents

v7 fdisk 使用

  1. 查看硬碟編號為 vda。
    [root@kvm7 ~]# lsblk 
    NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda                 252:0    0    4G  0 disk 
    ├─vda1              252:1    0  200M  0 part /boot
    ├─vda2              252:2    0  3.4G  0 part 
    │ ├─vg_kvm7usb-swap 253:0    0  124M  0 lvm  [SWAP]
    │ └─vg_kvm7usb-root 253:1    0  3.1G  0 lvm  /
    └─vda3              252:3    0  130M  0 part 
      └─vg_kvm7home-vo  253:2    0   80M  0 lvm  /home
    
  2. fdisk 命令分割硬碟,不必再使用 -uc 選項。
    [root@kvm7 ~]# fdisk /dev/vda 
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
  3. 執行 m 可以列出所有指令。
    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
       g   create a new empty GPT partition table
       G   create an IRIX (SGI) partition table
       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)
    
  4. 執行 p 列出分割表,建議每一動作結束都使用 p 查看分割表。
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000a59f4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    
  5. 執行 n 新增分割區,MBR 只能有記錄四個分割區,若有五個以上分割區,必須使用 extended 擴展分割區。
    Command (m for help): n
    Partition type:
       p   primary (3 primary, 0 extended, 1 free)
       e   extended
    Select (default e): 
    Using default response e
    Selected partition 4
    First sector (7845888-8388607, default 7845888): 
    Using default value 7845888
    Last sector, +sectors or +size{K,M,G} (7845888-8388607, default 8388607): 
    Using default value 8388607
    Partition 4 of type Extended and of size 265 MiB is set
    
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000a59f4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    /dev/vda4         7845888     8388607      271360    5  Extended
    
  6. 執行 n 新增分割區,因 MBR 已記錄 4 筆分割區,故強制使用 logical 分割區。
    Command (m for help): n
    All primary partitions are in use
    Adding logical partition 5
    First sector (7847936-8388607, default 7847936): 
    Using default value 7847936
    Last sector, +sectors or +size{K,M,G} (7847936-8388607, default 8388607): +10M
    Partition 5 of type Linux and of size 10 MiB is set
    
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000a59f4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    /dev/vda4         7845888     8388607      271360    5  Extended
    /dev/vda5         7847936     7868415       10240   83  Linux
    
  7. 執行 t 改變分割區系統 ID,設定為 82 Linux swap 分割區。
    Command (m for help): t
    Partition number (1-5, default 5): 
    Hex code (type L to list all codes): L
    
     0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
     1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
     2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
     3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
     4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
     5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
     6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
     7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
     8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
     9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
     a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
     b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
     c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
     e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
     f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
    10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
    11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
    12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
    14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
    16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
    17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
    18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
    1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
    1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
    1e  Hidden W95 FAT1 80  Old Minix      
    Hex code (type L to list all codes): 82
    Changed type of partition 'Linux' to 'Linux swap / Solaris'
    
    Command (m for help): p
    
    Disk /dev/vda: 4294 MB, 4294967296 bytes, 8388608 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000a59f4
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048      411647      204800   83  Linux
    /dev/vda2          411648     7579647     3584000   8e  Linux LVM
    /dev/vda3         7579648     7845887      133120   8e  Linux LVM
    /dev/vda4         7845888     8388607      271360    5  Extended
    /dev/vda5         7847936     7868415       10240   82  Linux swap / Solaris
    
  8. 執行 w 儲存分割表後退出,一樣出現警告訊息。
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
    
  9. 依照警告訊息執行 partprobe 及 kpartx。
    [root@kvm7 ~]# partprobe /dev/vda
    [root@kvm7 ~]# kpartx /dev/vda
    vda1 : 0 409600 /dev/vda 2048
    vda2 : 0 7168000 /dev/vda 411648
    vda3 : 0 266240 /dev/vda 7579648
    vda4 : 0 2 /dev/vda 7845888
    vda5 : 0 20480 /dev/vda 7847936
    [root@kvm7 ~]#
    
  10. 列出分割表,已出現剛剛分割的新分割區。
    [root@kvm7 ~]# lsblk 
    NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    vda                 252:0    0    4G  0 disk 
    ├─vda1              252:1    0  200M  0 part /boot
    ├─vda2              252:2    0  3.4G  0 part 
    │ ├─vg_kvm7usb-swap 253:0    0  124M  0 lvm  [SWAP]
    │ └─vg_kvm7usb-root 253:1    0  3.1G  0 lvm  /
    ├─vda3              252:3    0  130M  0 part 
    │ └─vg_kvm7home-vo  253:2    0   80M  0 lvm  /home
    ├─vda4              252:4    0    1K  0 part 
    └─vda5              252:5    0   10M  0 part
    
  11. 沒有重新開機,直接格式化分割區 /dev/vda5 為 swap。
    [root@kvm7 ~]# mkswap /dev/vda5
    Setting up swapspace version 1, size = 10236 KiB
    no label, UUID=d9b87380-fcf6-4c59-8421-130e3749a0a3
    
  12. 建立開機自動掛載 /dev/vda5 為 swap。
    [root@kvm7 ~]# vim /etc/fstab 
    /dev/vda5 swap swap defaults 0 0
    
  13. 檢查目前 swap 只有 dm-0 大小為 126972 bytes。
    [root@kvm7 ~]# swapon -s
    Filename				Type		Size	Used	Priority
    /dev/dm-0                              	partition	126972	0	-1
    
  14. 重新掛載 /etc/fstab 上的 swap 分割區,v7 不再警告已掛載的 swap。
    [root@kvm7 ~]# swapon -a
    
  15. 檢查 swap 已出現 /dev/vda5 的 swap,大小為 10236 bytes。
    [root@kvm7 ~]# swapon -s
    Filename				Type		Size	Used	Priority
    /dev/dm-0                              	partition	126972	0	-1
    /dev/vda5                              	partition	10236	0	-2
    


2015-12-04