Linux 分区管理

Linux 分区管理、创建分区
1、先看硬盘是否被主机识别出来
[root@future /]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         978     7855753+  83  Linux
/dev/sda2             979        1043      522112+  82  Linux swap / Solaris
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  83  Linux
/dev/sdb2             131         261     1052257+  82  Linux swap / Solaris
Disk /dev/sdc: 2147 MB, 2147483648 bytes    //可以看出硬盘已经被识别出来
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
2、对硬盘进行分区:
1)创建第1个大小为1.2GB左右的分区, 这里我只是估计一下,我是2GB的硬盘,柱面261个,一个柱面代表8M左右,
[root@future dev]# fdisk /dev/sdc
Command (m for help): n 
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 150
2)用剩下的空间创建第2个分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (151-261, default 151):
Using default value 151
Last cylinder or +size or +sizeM or +sizeK (151-261, default 261):
Using default value 261
3) 查看分区结果
Command (m for help): p
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         150     1204843+  83  Linux
/dev/sdc2             151         261      891607+  83  Linux
4)修改创建分区的文件系统ID
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): 83  //83代表ext3系统
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82  //82代表swap系统
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         150     1204843+  83  Linux
/dev/sdc2             151         261      891607+  82  Linux swap / Solaris
5)保存所做的分区修改
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3、格式化第1个分区sdc1 为ext3文件系统
[root@future dev]# mkfs -V -t ext3 -c /dev/sdc1
mkfs (util-linux 2.13-pre7)
mkfs.ext3 -c /dev/sdc1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
150720 inodes, 301210 blocks
15060 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=310378496
10 block groups
32768 blocks per group, 32768 fragments per group
15072 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840,  229376, 294912
Checking for bad blocks (read-only test): done                               
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.
4、挂载我们创建的第1个分区sdc1
[root@future dev]# mkdir /mnt/sdc1
[root@future dev]# mount /dev/sdc1 /mnt/sdc1
5、往新加的分区里复制一个文件,检验新加的分区是否已经可以使用
[root@future dev]# cp /var/log/messages /mnt/sdc1
[root@future dev]# cat /var/log/messages | tail -1
Mar  8 15:05:21 future kernel: EXT3-fs: mounted filesystem with ordered data mode.
6、查看系统当前的内存信息,包括物理内存和虚拟内存
[root@future dev]# free
             total       used       free     shared    buffers     cached
Mem:        231424     193156      38268          0       1800      45204
-/+ buffers/cache:     146152      85272
Swap:      1574352      50632    1523720
7、显示虚拟内存的信息
[root@future dev]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       522104  50632   -1
/dev/sdb2                               partition       1052248 0       -2
[root@future dev]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       522104  50632   -1
/dev/sdb2                               partition       1052248 0       -2
8、格式化我们创建的第2个分区sdc2为swap文件系统
[root@future dev]# mkswap /dev/sdc2
Setting up swapspace version 1, size = 912998 kB
9、激活交换分区sdc2
[root@future dev]# swapon /dev/sdc2 
10、检查操作结果
[root@future dev]# free
             total       used       free     shared    buffers     cached
Mem:        231424     198544      32880          0       1348      45708
-/+ buffers/cache:     151488      79936
Swap:      2465948      47748    2418200
[root@future dev]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       522104  47748   -1
/dev/sdb2                               partition       1052248 0       -2
/dev/sdc2                               partition       891596  0       -3
[root@future dev]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       522104  47748   -1
/dev/sdb2                               partition       1052248 0       -2
/dev/sdc2                               partition       891596  0       -3
 
如果你无法或者不想创建交换分区,你可以创建一个交换文件来代替交换分区,步骤如下:
1、从/dev/sdc2中抽出10MB的空间创建一个空白文件
[root@future dev]# dd if=/dev/sdc2 of=/swap bs=1024 count=10000
10000+0 records in
10000+0 records out
10240000 bytes (10 MB) copied, 1.0449 seconds, 9.8 MB/s
 
2、将该空白文件格式化成swap文件系统
[root@future dev]# mkswap /swap
Setting up swapspace version 1, size = 10235 kB
3、激活该交换文件
[root@future dev]# swapon /swap
4、查看是否激活成功
[root@future dev]# swapon -s
Filename                                Type            Size    Used    Priority
/dev/sda2                               partition       522104  47748   -1
/dev/sdb2                               partition       1052248 0       -2
/dev/sdc2                               partition       891596  0       -4
/swap                                   file            9992    0       -5
输出最下方显示出了swap文件,类型显示为file
5、顺便将缓冲区里的内容写进硬盘
[root@future dev]# sync
 

你可能感兴趣的:(linux,分区,职场,休闲)