【Linux】磁碟分割__Linux

來源:互聯網
上載者:User
我們在Linux操作過程中,可能會遇到磁碟分割的問題。這篇文章是對/dev/sdb 這塊磁碟進行分區。
linux分區不同於windows,linux下硬碟裝置名稱為(IDE硬碟為hdx(x為從a—d)因為IDE硬碟最多四個,SCSI,SATA,USB硬碟為sdx(x為a—z)),硬碟主要磁碟分割最多為4個,不用說大家也知道…..所以主要磁碟分割從sdb1開始到sdb4,邏輯分區從sdb5開始,(邏輯分區永遠從sdb5開始…)
主要磁碟分割(最多建立4個):第一個分區主要存放磁碟的啟動資訊。
擴充分區(Linux中最多建立1個):擴充分區屬於邏輯架構,不能再建立檔案系統,只能在下面建立邏輯分區。
邏輯分區:在擴充分區下面建立,不同的作業系統對邏輯分區個數限制也不同。
分區步驟:
1.fdisk 分區;
2.mkfs 格式化分區;
3.建立掛載點;
4.掛載磁碟或者編輯/etc/fstab檔案設定開機自動掛載

1.查看當前作業系統的所有磁碟 [root@lgr ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         535     4192965   82  Linux swap / Solaris
/dev/sda3             536        5221    37640295   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

2.fdisk命令把sdb分成1個主要磁碟分割,一個擴充分區 [root@lgr ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +5G

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (610-1305, default 610):
Using default value 610
Last cylinder or +size or +sizeM or +sizeK (610-1305, default 1305):
Using default value 1305

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (610-1305, default 610):
Using default value 610
Last cylinder or +size or +sizeM or +sizeK (610-1305, default 1305): +3G

Command (m for help):
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (976-1305, default 976):
Using default value 976
Last cylinder or +size or +sizeM or +sizeK (976-1305, default 1305): +2G

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         609     4891761   83  Linux
/dev/sdb2             610        1305     5590620    5  Extended
/dev/sdb5             610         975     2939863+  83  Linux
/dev/sdb6             976        1219     1959898+  83  Linux

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.
Syncing disks.

3.mkfs命令對分區進行格式化 [root@lgr ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
611648 inodes, 1222940 blocks
61147 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1254096896
38 block groups
32768 blocks per group, 32768 fragments per group
16096 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@lgr ~]#
[root@lgr ~]# mkfs.ext3 /dev/sdb5
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
368000 inodes, 734965 blocks
36748 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=754974720
23 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912

Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@lgr ~]# 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)
245280 inodes, 489974 blocks
24498 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=503316480
15 block groups
32768 blocks per group, 32768 fragments per group
16352 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 30 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

4.建立掛載點 [root@lgr ~]# mkdir /dsk1 /dsk5 /dsk6

5.mount命令做一次臨時掛載,編輯/etc/fstab 可以設定開機自動掛載。 ①臨時掛載
mount /dev/sdb1 /dsk1
mount /dev/sdb5 /dsk5
mount /dev/sdb6 /dsk6

②編輯檔案設定自動掛載
[root@lgr ~]# vi /etc/fstab
追加如下資訊
/dev/sdb1               /dsk1                   ext3    defaults        0 0
/dev/sdb5               /dsk5                   ext3    defaults        0 0
/dev/sdb6               /dsk6                   ext3    defaults        0 0
說明:第一行:磁碟目錄;第二行:掛載點;第三行:檔案系統格式;第四行:啟動磁碟方式;第五行:開機是否檢測(0 不檢測,1 檢測);第六行:出錯是否轉儲(0,不轉儲,1 轉儲)

6.重啟系統,fdisk-l /dev/sdb 查看分區情況。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.