Linux下磁盤兩種分區方式

使用fdisk管理磁盤分區

使用fdisk命令對sdc硬盤分區:

# fdisk /dev/sdc 
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.
## 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)

##p 打印分區表
Command (m for help): p

Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x2ebdc3b7

   Device Boot      Start         End      Blocks   Id  System
##n 新建分區
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
##p代表主分區,e代表擴展分區
Select (default p): p
##1表示分區編號爲1
Partition number (1-4, default 1): 1
##輸入磁盤起始扇區,直接回車表示使用默認值
First sector (2048-104857599, default 2048): 
Using default value 2048
##輸入磁盤結束扇區,直接回車表示使用默認值(這裏表示超出磁盤大小了)
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +50G
Value out of range.
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +49G
Partition 1 of type Linux and of size 49 GiB is set
##p 打印分區表,這裏就可以看到分區表信息了
Command (m for help): p

Disk /dev/sdc: 53.7 GB, 53687091200 bytes, 104857600 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: 0x2ebdc3b7

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   102762495    51380224   83  Linux
## w 將分區信息寫入磁盤
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
##格式化磁盤
# mkfs.ext4 /dev/sdc1 

##創建掛載點
# mkdir -p /data/sdv1

##掛載
# mount /dev/sdc1 /data/sdv1/

fdisk

使用parted管理磁盤分區

使用fdisk命令對sdd硬盤分區(大於2T磁盤掛載可使用):

[root@cy1 ~]# parted /dev/sdf 
GNU Parted 3.1
Using /dev/sde
Welcome to GNU Parted! Type 'help' to view a list of commands.
##help 打印幫助信息
(parted) help 
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices,
        free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright
        information of GNU Parted
##打印當前磁盤信息
(parted) print                                                            
Error: /dev/sde: unrecognised disk label
Model: VMware Virtual disk (scsi)                                         
Disk /dev/sde: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
##轉換磁盤分區格式(大於2T使用GPT格式)
(parted) mklabel gpt                                                      
##設置單位
(parted) unit GB                                                          
##創建分區(0爲起始,53.7爲結束)
(parted) mkpart primary 0 53.7
##打印當前分區信息
(parted) print                                                            
Model: VMware Virtual disk (scsi)
Disk /dev/sde: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      0.00GB  53.7GB  53.7GB               primary

##退出
(parted) quit                                                             
Information: You may need to update /etc/fstab.

parted

##格式化磁盤
# mkfs.ext4 /dev/sdf1 

##創建掛載點
# mkdir -p /data/sdv2

##掛載
# mount /dev/sdf1 /data/sdv2/

添加交換分區

交換分區添加方式和普通分區差不多:

# fdisk /dev/sdd 
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.


Command (m for help): p

Disk /dev/sdd: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000d2019

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +8G
Partition 1 of type Linux and of size 8 GiB is set

Command (m for help): p

Disk /dev/sdd: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000d2019

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048    16779263     8388608   83  Linux
##t 修改分區類型
Command (m for help): t
Selected partition 1
##l 列出支持的分區類型
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      
##82 表示Linux swap
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/sdd: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000d2019

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048    16779263     8388608   82  Linux swap / Solaris

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
##格式化磁盤
#  mkswap /dev/sdd1 

##開啓swap
# swapon /dev/sdd1

設置開機自動掛載

##在/etc/fstab添加配置:
# vi /etc/fstab
/dev/sdc1 /data/sdv1/                   ext4    defaults,noatime        1 2     
/dev/sdf1 /data/sdv2/                   ext4    defaults,noatime        1 2  
/dev/sdd1 swap                  swap    defaults                        0 0  

fstab

發佈了91 篇原創文章 · 獲贊 132 · 訪問量 53萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章