2021-05-12 14:32:11
Linux 硬碟,格式化,分割區 入門詳解
disk是Linux自帶的硬碟分割區工具,可以對硬碟進行分割區,或者對硬碟分割區進行調整。
首先選擇要進行操作的磁碟
[root@linuxidc ~]# fdisk /dev/sdb
輸入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
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/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1 8001 8e Linux LVM
/dev/sdb2 2 26 200812+ 83 Linux
輸入d,然後選擇分割區,刪除現有分割區
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
檢視分割區情況,確認分割區已經刪除
Command (m for help): print
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help):
輸入n,建立新的磁碟分割區,首先建立兩個主磁碟分割區
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p //建立主分割區
Partition number (1-4): 1 //分割區號
First cylinder (1-391, default 1): //分割區起始位置
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分割區結束位置,單位為磁區
Command (m for help): n //再建立一個分割區
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2 //分割區號為2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分割區結束位置,單位為M
確認分割區建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
再建立一個邏輯分割區
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e //選擇擴充套件分割區
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):
Using default value 391
確認擴充套件分割區建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended
在擴充套件分割區上建立兩個邏輯分割區
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l //選擇邏輯分割區
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391
確認邏輯分割區建立成功
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended
/dev/sdb5 126 175 401593+ 83 Linux
/dev/sdb6 176 391 1734988+ 83 Linux
Command (m for help):
從上面的結果我們可以看到,在硬碟sdb我們建立了2個主分割區(sdb1,sdb2),1個擴充套件分割區(sdb3),2個邏輯分割區(sdb5,sdb6)
注意:主分割區和擴充套件分割區的磁碟號位1-4,也就是說最多有4個主分割區或者擴充套件分割區,邏輯分割區開始的磁碟號為5,因此在這個實驗中試沒有sdb4的。
最後對分割區操作進行儲存
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
建立好分割區之後我們還需要對分割區進行格式化才能在系統中使用磁碟。
在sdb1上建立ext2分割區
[root@linuxidc ~]# mkfs.ext2 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
100576 inodes, 200804 blocks
10040 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
14368 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
在sdb6上建立ext3分割區
[root@linuxidc ~]# mkfs.ext3 /dev/sdb6
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
217280 inodes, 433747 blocks
21687 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=444596224
14 block groups
32768 blocks per group, 32768 fragments per group
15520 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@linuxidc ~]#
建立兩個目錄/Oracle和/web,將新建好的兩個分割區掛載到系統
[root@linuxidc ~]# mkdir /oracle
[root@linuxidc ~]# mkdir /web
[root@linuxidc ~]# mount /dev/sdb1 /oracle
[root@linuxidc ~]# mount /dev/sdb6 /web
檢視分割區掛載情況
[root@linuxidc ~]# df -h
檔案系統 容量 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
6.7G 2.8G 3.6G 44% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/sdb1 773M 808K 733M 1% /oracle
/dev/sdb6 1.7G 35M 1.6G 3% /web
如果需要每次開機自動掛載則需要修改/etc/fstab檔案,加入兩行設定
[root@linuxidc ~]# vim /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/sdb1 /oracle ext2 defaults 0 0
/dev/sdb6 /web ext3 defaults 0 0
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新連結地址:https://www.linuxidc.com/Linux/2018-08/153580.htm
相關文章