Linux 基础 之 系统分区管理

给系统分区,是为了方便系统管理。

我们首先来区分以下df,blkic,cat /pro/partition,fdisk -l 这四个查看命名的不同点

    

              df        <=     blkid         <=          cat /pro/partition       <=           fdisk -l

(正在挂载使用)  (可以使用)      (系统识别但不能使用)      (所有真实存在,系统不一定识别)


Command action

   a   toggle a bootable flag    
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
    delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
    list known partition types
   m   print this menu
   add a new partition     ##新建分区
    create a new empty DOS partition table
   p   print the partition table   ##显示分区信息
     quit without saving changes   ##退出
   s   create a new empty Sun disklabel
    change a partition's system id    ##修改分区id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit   ##将当前操作写入硬盘分区表
     extra functionality (experts only)


步骤:

     1.fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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


   2.fdisk  /dev/vdb
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe41113f7.

Command (m for help):

    3.
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    ##确定主分区id
First sector (2048-20971519, default 2048):     ##分区起始块的位置,用默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M   ##分区结束位置,用+大小的方式指定
Partition 1 of type Linux and of size 100 MiB is set

Command (m for help): wq     ##保存分区策略并退出fdisk界面


     4.partprobe    ##手动同步分区

     5.cat /proc/partitions     ##查看设备是否被系统识别
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     102400 vdb1
 253       18     102400 vdb2
 253       19     102400 vdb3
 253       20          1 vdb4
 253       21     102400 vdb5

     


      6.blkid  ##查看可用设备

[root@localhost ~]# blkid
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"

当然,单纯的去挂载是不行的
 [root@localhost ~]# mount /dev/vdb1 /mnt/
mount: /dev/vdb3 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'      ##出现了报错


必须得先进行格式化,才可网系统里安装设备

 [root@localhost ~]# mkfs.xfs /dev/vdb1
meta-data=/dev/vdb3              isize=256    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0



          7.blkid                                                       ##再次查看可用设备
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb5: UUID="90cfdea8-f3a3-4074-895c-996e4cb068e4" TYPE="xfs"
/dev/vdb2: UUID="3ebce184-64e6-42ba-851c-8f759f5628d8" TYPE="xfs"
/dev/vdb3: UUID="daaa2039-1547-4bcb-b893-03a031b6fd79" TYPE="xfs"


但是,vdb4,不可以格式化,因为它是一个扩展分区(容器)。

以上所建的分区一共有2TB的内存,如果要解决超出2TB的内存,我们则要使用gpt的格式
首先,要对上步挂载的进行卸载。

fdisk /dev/vdb

Command (m for help): d
Partition number (1-5, default 5): 1         ##建了几个就输入id
Partition 1 is deleted
直到:
Command (m for help): d
No partition is defined yet!

记住一定要wq退出保存。

p   print the partition table   ##显示分区信息


 [root@localhost ~]# partprobe
 [root@localhost ~]# cat /proc/partitions
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb

更改gpt分区,gpt分区可以建立1-128个分区。

步骤:

[root@localhost ~]# parted /dev/vdb     
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel                                                          
New disk label type?                                     (##双击tab键查看)                
aix    amiga  bsd    dvh    gpt    loop   mac    msdos  pc98   sun    
New disk label type? gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
(parted) quit
Information: You may need to update /etc/fstab.

[root@localhost ~]# fdisk -l              ##查看                                

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: gpt                            ##变成了gpt


#         Start          End    Size  Type            Name


[root@localhost ~]# fdisk /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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): n
Partition number (1-128, default 1):
First sector (34-20971486, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971486, default 20971486): +100M
Created partition 1


Command (m for help): quit


再把gpt变换成mpr形式


[root@localhost ~]# parted /dev/vdb    
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel                                                          
New disk label type?                                                      
aix    amiga  bsd    dvh    gpt    loop   mac    msdos  pc98   sun    
New disk label type? msdos           ##改成mpr
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
(parted) quit                                                             
Information: You may need to update /etc/fstab.

[root@localhost ~]# fdisk -l         ##查看

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00012042

   Device Boot      Start         End      Blocks   Id  System



报错:

         如果出现Ignore,则按I。


久性使其挂载(在/mnt)

[root@localhost ~]# vim /etc/fstab     
[root@localhost ~]# partprobe
[root@localhost ~]# mount -a



永久性使其挂载(在/swap)

[root@localhost ~]# fdisk -l                  ##system 为liunx

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Command (m for help):                              ##建一个id2
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (206848-20971519, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +1000M
Partition 2 of type Linux and of size 1000 MiB is set

Command (m for help):                 ##对id2进行修改,使system为Linux swap / Solaris
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82

WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation.

Changed type of partition 'FAT12' to 'Linux swap / Solaris'



Command (m for help): p                       ##查看是否成功

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00012042

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      206847      102400   83  Linux
/dev/vdb2          206848     2254847     1024000   82  Linux swap / Solaris

Command (m for help): wq                ##保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


[root@localhost ~]# partprobe                  ##手动同步分区
[root@localhost ~]# cat /proc/partitions          ##查看
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     102400 vdb1
 253       18    1024000 vdb2
[root@localhost ~]# mkswap /dev/vdb2                      ##格式化
mkswap: /dev/vdb2: warning: wiping old xfs signature.
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=8fb590d3-0310-40c1-bb93-91c4eb6ea289
[root@localhost ~]# swapon -a /dev/vdb2               ##测试不报错
[root@localhost ~]# swapon -s                    ##查看
Filename                Type        Size    Used    Priority
/dev/vdb2                                  partition    1023996    0    -1
[root@localhost ~]# vim /etc/fstab               ##编写这个文件,使永久挂载到swap
[root@localhost ~]# swapon -a               ##查看
   


猜你喜欢

转载自blog.csdn.net/janenancy/article/details/80157465