学习啦 > 学习电脑 > 操作系统 > Linux教程 > linux操作系统分区

linux操作系统分区

时间: 春健736 分享

学习啦在线学习网linux操作系统分区

  本文就用户在装Linux操作系统的过程中,所遇到的Linux操作系统分区问题来详细地介绍一下,下面大家与学习啦小编一起来学习一下吧。

  linux操作系统分区

学习啦在线学习网   每块硬盘的 MBR 最多只能存储 4 个分区信息,也就是说每块物理硬盘我们最多分成4个主分区(P + P + P + P),或者3个主分区外加一个扩展分区(P + P + P + E)。如果我们希望划分更多的分区,可以将扩展分区划分更多更小的逻辑分区。

  Linux 将编号 1 ~ 4 固定分配给 4 个主要分区。也就是说即便我们只有 1 个主分区和 1 个扩展分区,那第一个逻辑分区也只能是 hda5 (或 sda5)。

学习啦在线学习网   谈论 Linux 分区时和 Windows 有很大的不同,因为这些分区通常以某个目录方式存在 (或者说挂载点)。

  /: 默认挂载点,未指定的目录都将存放在分区中。

  /home: 用户主目录,相当于 Windows 的 Documents and Settings,存放各用户的相关数据文件,适合单独分区。

  /usr: 各种执行程序安装目录,相当于 Windows 的 Program files 和 Winnt 目录。建议单独分区。

  /var: 通常用于存放各种临时文件和缓存文件,容易产生磁盘碎片,建议单独分区。

学习啦在线学习网   当然,别忘了充当虚拟内存 swap 分区。

  以下是我个人习惯的分区方式。

  /: 1GB ~ 2GB。

  /usr: 1GB ~ 2GB,依据需要安装的服务和软件而定。

  swap: 通常是物理内存的 2 倍,但似乎没必要超过 1GB。

  /home: 所有剩余空间

学习啦在线学习网   /var: 1GB 左右

  我们用 Fdisk 对一个 8GB 的硬盘做一个分区演示。

  yuhen@yuhen-desktop:~$ sudo fdisk /dev/sdb

学习啦在线学习网   Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

学习啦在线学习网   Building a new DOS disklabel with disk identifier 0x416ba19a.

学习啦在线学习网   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 1044.

  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): p # 查看分区信息

学习啦在线学习网   Disk /dev/sdb: 8589 MB, 8589934592 bytes

  255 heads, 63 sectors/track, 1044 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Disk identifier: 0x416ba19a

学习啦在线学习网   Device Boot Start End Blocks Id System

学习啦在线学习网   Command (m for help): n # 新建主分区 /

  Command action

  e extended

  p primary partition (1-4)

  p # 新建主分区

  Partition number (1-4): 1 # 分区编号

学习啦在线学习网   First cylinder (1-1044, default 1): # 开始柱面,通常用默认值

  Using default value 1

  Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +1024M # 分区大小 1GB。

学习啦在线学习网   Command (m for help): n # 新建主分区 /usr

  Command action

  e extended

  p primary partition (1-4)

  p

  Partition number (1-4): 2

学习啦在线学习网   First cylinder (133-1044, default 133):

  Using default value 133

  Last cylinder, +cylinders or +size{K,M,G} (133-1044, default 1044): +1024M

  Command (m for help): n # 新建主分区 swap

  Command action

  e extended

  p primary partition (1-4)

  p

  Partition number (1-4): 3

  First cylinder (265-1044, default 265):

  Using default value 265

  Last cylinder, +cylinders or +size{K,M,G} (265-1044, default 1044): +512M

  Command (m for help): n # 新建扩展分区

学习啦在线学习网   Command action

  e extended

学习啦在线学习网   p primary partition (1-4)

  e

  Selected partition 4

  First cylinder (331-1044, default 331):

学习啦在线学习网   Using default value 331

  Last cylinder, +cylinders or +size{K,M,G} (331-1044, default 1044): # 全部剩余空间

  Using default value 1044

  Command (m for help): p # 查看分区

  Disk /dev/sdb: 8589 MB, 8589934592 bytes

  255 heads, 63 sectors/track, 1044 cylinders

学习啦在线学习网   Units = cylinders of 16065 * 512 = 8225280 bytes

  Disk identifier: 0x416ba19a

  Device Boot Start End Blocks Id System

学习啦在线学习网   /dev/sdb1 1 132 1060258+ 83 Linux

  /dev/sdb2 133 264 1060290 83 Linux

  /dev/sdb3 265 330 530145 83 Linux

学习啦在线学习网   /dev/sdb4 331 1044 5735205 5 Extended

学习啦在线学习网   Command (m for help):

学习啦在线学习网   至此我们完成了 4 个主分区的划分,接下来为创建逻辑分区。

  Command (m for help): n # 创建 /home 逻辑分区

  First cylinder (331-1044, default 331):

  Using default value 331

  Last cylinder, +cylinders or +size{K,M,G} (331-1044, default 1044): +4096M

  Command (m for help): n # 创建 /var 逻辑分区

学习啦在线学习网   First cylinder (854-1044, default 854):

  Using default value 854

  Last cylinder, +cylinders or +size{K,M,G} (854-1044, default 1044):

学习啦在线学习网   Using default value 1044

学习啦在线学习网   Command (m for help): p # 显示分区

  Disk /dev/sdb: 8589 MB, 8589934592 bytes

  255 heads, 63 sectors/track, 1044 cylinders

  Units = cylinders of 16065 * 512 = 8225280 bytes

  Disk identifier: 0xe1bd2899

学习啦在线学习网   Device Boot Start End Blocks Id System

学习啦在线学习网   /dev/sdb1 1 132 1060258+ 83 Linux

  /dev/sdb2 133 264 1060290 83 Linux

  /dev/sdb3 265 330 530145 83 Linux

学习啦在线学习网   /dev/sdb4 331 1044 5735205 5 Extended

  /dev/sdb5 331 853 4200966 83 Linux

学习啦在线学习网   /dev/sdb6 854 1044 1534176 83 Linux

学习啦在线学习网   Command (m for help):

  别忘了保存分区表,否则上面的工作就白做了。

  Command (m for help): w

  The partition table has been altered!

学习啦在线学习网   Calling ioctl() to re-read partition table.

  Syncing disks.

  看看效果。

  yuhen@yuhen-desktop:~$ sudo fdisk -l /dev/sdb

学习啦在线学习网   Disk /dev/sdb: 8589 MB, 8589934592 bytes

学习啦在线学习网   255 heads, 63 sectors/track, 1044 cylinders

学习啦在线学习网   Units = cylinders of 16065 * 512 = 8225280 bytes

  Disk identifier: 0x71f06c9b

  Device Boot Start End Blocks Id System

  /dev/sdb1 1 132 1060258+ 83 Linux

  /dev/sdb2 133 264 1060290 83 Linux

  /dev/sdb3 265 330 530145 83 Linux

学习啦在线学习网   /dev/sdb4 331 1044 5735205 5 Extended

  /dev/sdb5 331 853 4200966 83 Linux

  /dev/sdb6 854 1044 1534176 83 Linux

  接下来就是格式化分区了。

学习啦在线学习网   yuhen@yuhen-desktop:~$ sudo mke2fs -j -L "root" /dev/sdb1

学习啦在线学习网   mke2fs 1.41.4 (27-Jan-2009)

学习啦在线学习网   Filesystem label=root

  OS type: Linux

学习啦在线学习网   Block size=4096 (log=2)

学习啦在线学习网   Fragment size=4096 (log=2)

  66384 inodes, 265064 blocks

  13253 blocks (5.00%) reserved for the super user

学习啦在线学习网   First data block=0

学习啦在线学习网   Maximum filesystem blocks=272629760

学习啦在线学习网   9 block groups

学习啦在线学习网   32768 blocks per group, 32768 fragments per group

  7376 inodes per group

学习啦在线学习网   Superblock backups stored on blocks:

学习啦在线学习网   32768, 98304, 163840, 229376

  Writing inode tables: done

学习啦在线学习网   Creating journal (8192 blocks): done

学习啦在线学习网   Writing superblocks and filesystem accounting information: done

  This filesystem will be automatically checked every 27 mounts or

学习啦在线学习网   180 days, whichever comes first. Use tune2fs -c or -i to override.

  给分区设置一个 Label,便于以后管理。

学习啦在线学习网   有关分区挂载点,可查看后续章节。

学习啦在线学习网   下图是我在 VMware 上安装 Ubuntu Desktop 9.04 时的分区设置,由于 Desktop 默认集成了一些软件,因此对 "/" 和 "/usr" 有最小尺寸限制。


655876