Linux系統分區管理

管理分區

 

 

查看系統中的分區4種方式

[root@localhost ~]# ls /dev/sd* [來自內存]

[root@localhost ~]# cat /proc/partitions

[root@localhost ~]# lsblk

/dev/sda ?/dev/sda1 ?/dev/sda2 ?/dev/sda3 ?/dev/sda4 ?/dev/sda5

 

[root@localhost ~]# fdisk -l 看磁盤中的分區表

磁盤中的分區表可能和內存中的分區表是不同步的

 

parted命令

  1. parted的操作都是實時生效的,小心使用
  2. 用法:parted [選項]… [設備 [命令 [參數]…]…]
  3. parted /dev/sdb ?mklabel gpt|msdos
  4. parted /dev/sdb ?print
  5. parted /dev/sdb ?mkpart primary 1 200 (默認M)
  6. parted /dev/sdb ?rm 1
  7. parted -l
  • mklabel gpt|msdos?用于指定創建的是GPT分區還是MBR分區

 

  • 創建分區

[root@localhost app]# parted /dev/sdb mkpart primary ?1 1000

Information: You may need to update /etc/fstab.

 

[root@localhost app]# lsblk

NAME ??MAJ:MIN RM ?SIZE RO TYPE MOUNTPOINT

sda ?????8:0 ???0 ?200G ?0 disk

├─sda1 ??8:1 ???0 ???1G ?0 part /boot

├─sda2 ??8:2 ???0 ??50G ?0 part /

├─sda3 ??8:3 ???0 ??20G ?0 part /app

├─sda4 ??8:4 ???0 ???1K ?0 part

└─sda5 ??8:5 ???0 ???2G ?0 part [SWAP]

sdb ?????8:16 ??0 ??20G ?0 disk

└─sdb1 ??8:17 ??0 ?953M ?0 part

GPT分區和MBR分區是互不兼容的,也不存在轉換的問題,一旦設置了GPT分區或者MBR分區,要想裝換只能重新分區

 

 

分區工具fdisk和gdisk

 

  1. gdisk /dev/sdb 類fdisk 的GPT分區工具
  2. fdisk -l [-u] [device…] 查看分區
  3. fdisk /dev/sdb ?管理分區
  4. 子命令:
  5. p 分區列表
  6. t 更改分區類型
  7. n 創建新分區
  8. d 刪除分區
  9. v 校驗分區
  10. u 轉換單位
  11. w 保存并退出
  12. q 不保存并退出

 

 

[root@localhost app]# gdisk /dev/sdb

GPT fdisk (gdisk) version 0.8.6

 

Partition table scan:

MBR: protective

BSD: not present

APM: not present

GPT: present

 

Found valid GPT with protective MBR; using GPT.

#gdisk的幫助信息

Command (? for help): ?

b back up GPT data to a file ? ? ? ?備份GPT分區

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)? ? ? ? 創建一個GUID分區表

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):

 

#把分區表轉換為MBR類型

[root@localhost ~]# parted /dev/sdb mklabel msdos

Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do

you want to continue?

Yes/No? yes

Information: You may need to update /etc/fstab.

 

[root@localhost ~]#

 

fdisk分區工具的使用

[root@localhost ~]# fdisk /dev/sdb

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): m

Command action

a ??toggle a bootable flag

b ??edit bsd disklabel

c ??toggle the dos compatibility flag 不以dos兼容的模式

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 以扇區為單位進行顯示(單位為K)

v ??verify the partition table

w ??write table to disk and exit

x ??extra functionality (experts only)

 

Command (m for help):

 

在CentOS6中:

[root@localhost ~]# fdisk /dev/sda

 

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to

switch off the mode (command ‘c’) and change display units to

sectors (command ‘u’).基于dos兼容模式是棄用。這是強烈推薦關掉模式(命令“c”)和改變顯示單位部門(命令“u”)。也就是用傳統的柱面的方式來劃分去分區,并且要求以整柱面位單位進行劃分,

 

 

Command (m for help): p

 

Disk /dev/sda: 214.7 GB, 214748364800 bytes

255 heads, 63 sectors/track, 26108 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: 0x0008cdd6

 

Device Boot ?????Start ????????End ?????Blocks ??Id ?System

/dev/sda1 ??* ??????????1 ????????131 ????1048576 ??83 ?Linux

Partition 1 does not end on cylinder boundary. 默認以柱面為單位進行劃分,不在整柱面上會提示

/dev/sda2 ????????????131 ???????6658 ???52428800 ??83 ?Linux

/dev/sda3 ???????????6658 ???????9269 ???20971520 ??83 ?Linux

/dev/sda4 ???????????9269 ??????26109 ??135265280 ???5 ?Extended

/dev/sda5 ???????????9269 ???????9530 ????2097152 ??82 ?Linux swap / Solaris

 

Command (m for help):

CentOS6默認以dos模式柱面為單位

CentOS7默認就是以非dos模式以扇區為單位,默認相當于已經加了c u 了,但也是可以改為以柱面為單位進行顯示,例如打開的時候以柱面為單位進行顯示

[root@localhost ~]# fdisk -h

Usage:

fdisk [options] <disk> ???change partition table

fdisk [options] -l <disk> list partition table(s)

fdisk -s <partition> ?????give partition size(s) in blocks

 

Options:

-b <size> ????????????sector size (512, 1024, 2048 or 4096)

-c[=<mode>] ??????????compatible mode: ‘dos’ or ‘nondos’ (default)

-h ???????????????????print this help text

-u[=<unit>] ??????????display units: ‘cylinders’ or ‘sectors’ (default)

-v ???????????????????print program version

-C <number> ??????????specify the number of cylinders

-H <number> ??????????specify the number of heads

-S <number> ??????????specify the number of sectors per track

 

[root@localhost ~]# fdisk -u=cylinders /dev/sda

 

WARNING: cylinders as display units are deprecated. Use command ‘u’ to

change units to sectors.

Device Boot ?????Start ????????End ?????Blocks ??Id ?System

/dev/sda1 ??* ??????????1 ????????131 ????1048576 ??83 ?Linux

/dev/sda5 ???????????9269 ???????9530 ????2097152 ??82 ?Linux swap / Solaris

 

注意:注意不要在一個分區中的夾縫中分區,避免分出來的空間過小,或者分區的時候空間過大進行報錯提示

Device Boot ?????Start ????????End ?????Blocks ??Id ?System

/dev/sdc1 ???????????2048 ???????8192 ???????3072+ ?83 ?Linux

/dev/sdc2 ??????????10240 ???62914559 ???31452160 ??83 ?Linux

Last sector, +sectors or +size{K,M,G} (8193-10239, default 10239): +10G

Value out of range.

分區不能調大調小,只能重頭開始分區。例如刪除分區6,分區7會變成分區6。

 

分區的標識、設備名是不穩定的,帶來的問題就是將來在磁盤上進行分區配置文件的修改,寫/sda5 sda6這樣的名字,萬一刪掉了分區,設備名就變了,數據就找不到了配置文件就會出問題,不推薦寫設備名稱,分區完成后會生成UUID號,是唯一且不變的,建議寫UUID號

 

在6中創建分區表同步失敗

Command (m for help): n

First sector (148899903-419430399, default 148899903):

Using default value 148899903

Last sector, +sectors or +size{K,M,G} (148899903-148903935, default 148903935):

Using default value 148903935

 

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.

[root@localhost ~]#

 

需要手動同步分區表

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/89200

(0)
無言勝千言無言勝千言
上一篇 2017-12-02 19:49
下一篇 2017-12-02 20:23

相關推薦

  • 第二周相關習題。

    習題 顯示/var目錄下所有以l開頭,以一個小寫字母結尾,且中間至少出現一位數字(可以有其它字符)的文件或目錄。 [root@localhost /]# ls -d /var/l*[0-9]*[[:lower:]] 顯示/etc目錄下,以任意一個數字開頭,且以非數字結尾的文件或目錄。 [root@localhost&n…

    Linux干貨 2016-11-05
  • DNS原理詳解02

    9、子域授權     1、在父域的區域配置文件中增加以下記錄,即為增加了子域授權            opt.patrickli.com.         IN      NS     &…

    Linux干貨 2016-08-29
  • yum——替你排憂解難的前端包安裝工具

    yum CentOS前端工具: yum, dnf 統一資源定位符:URL YUM: Yellowdog Update Modifier,rpm的前端程序,用來解決軟件包相關依賴性,可以在多個庫之間定位軟件包,自動安裝軟件包,以及該軟件包的依賴包,up2date的替代工具 yum repository: yum repo (yum倉庫)  &nbsp…

    Linux干貨 2016-08-24
  • HSRP vs VRRP

    HSRP:(Hot Standby Router Protocol)-熱備份路由協議 是cisco平臺一種特有的技術,是cisco的私有協議。 VRRP:(Virtual Router Redundancy Protocol)-虛擬路由冗余協議 是國際標準,由IETF提出的解決局域網中配置靜態網關出現單點失效現象的路由協議。 ----------------…

    Linux干貨 2016-10-19
  • 6 文件系統權限(一):用戶、組

    提綱 文件系統權限 3A 安全 Authentication    :  認證    –> 用戶名&密碼、指紋、人臉識別、DNA驗證 Authorization    :  …

    Linux干貨 2016-08-10
  • Linux添加swap交換分區

    添加swap交換分區 SWAP即交換分區是一種類似于Windows系統虛擬內存的功能,將一部分硬盤空間虛擬成內存來使用,從而解決內存容量不足的情況,因為SWAP畢竟是用硬盤資源虛擬的,所以速度上比真實物理內存要慢很多,一般只有當真實物理內存耗盡時才會調用SWAP。 1、創建一個分區,看上篇文章,別著急w保存退出 修改分區的類型輸入t: Comman…

    Linux干貨 2016-09-07
欧美性久久久久