免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 559 | 回复: 0
打印 上一主题 下一主题

linux分区操作 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-26 21:20 |只看该作者 |倒序浏览

linux 分区操作试验
=============
一:试验环境

1.vmware虚拟机
2.linux9.0
3.设置两块硬盘

=============
二:试验步骤

1.在linux9.0中安装第二块硬盘;
2.使用fdisk工具对第二块硬盘分区;
3.格式化分区;
4.挂载分区到系统目录;
5.对挂载点进行存取;
6.卸载挂载点;
7.设置系统启动自动挂载分区;

=============
三:分区工具

1.fdisk使用
因为我使用的是两块scsi硬盘,故第二块硬盘被识别为sdb
查看sdb的分区情况,因为是新硬盘,所以没有任何分区信息;
[root@www root]# fdisk -l /dev/sdb
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot    Start       End    Blocks   Id  System

2.对sdb硬盘进行分区操作
[root@www root]# fdisk /dev/sdb
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  //该表分区的id表示;
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit  //保存分区表,推出;
   x   extra functionality (experts only)

3.建立主分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): +500M
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1        62    497983+  83  Linux

4..创建扩展分区,最好将硬盘的所有剩余空间都作为扩展分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (63-522, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-522, default 522):
Using default value 522
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1        62    497983+  83  Linux
/dev/sdb2            63       522   3694950    5  Extended

5.创建逻辑分区
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (63-522, default 63):
Using default value 63
Last cylinder or +size or +sizeM or +sizeK (63-522, default 522): +500M
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1        62    497983+  83  Linux
/dev/sdb2            63       522   3694950    5  Extended
/dev/sdb5            63       124    497983+  83  Linux
Command (m for help):

6.改变分区的系统代码
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): L
0  Empty           1c  Hidden Win95 FA 70  DiskSecure Mult bb  Boot Wizard hid
1  FAT12           1e  Hidden Win95 FA 75  PC/IX           be  Solaris boot
2  XENIX root      24  NEC DOS         80  Old Minix       c1  DRDOS/sec (FAT-
3  XENIX usr       39  Plan 9          81  Minix / old Lin c4  DRDOS/sec (FAT-
4  FAT16
Hex code (type L to list codes):b
Changed system type of partition 5 to b (Win95 FAT32)
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1        62    497983+  83  Linux
/dev/sdb2            63       522   3694950    5  Extended
/dev/sdb5            63       124    497983+   b  Win95 FAT32
7.创建逻辑分区sdb6,并将其转换为swap类型;
Command (m for help): p
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1             1        62    497983+  83  Linux
/dev/sdb2            63       522   3694950    5  Extended
/dev/sdb5            63       124    497983+   b  Win95 FAT32
/dev/sdb6           125       186    497983+  82  Linux swap
8.保存分区表信息;重启计算机;
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.
Syncing disks.
[root@www root]# reboot

==============
四:格式化分区

1.格式化linux类型文件系统;
[root@www root]# mkfs -t ext3 /dev/sdb1
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
124928 inodes, 497983 blocks
24899 blocks (5.00%) reserved for the super user
First data block=1
61 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
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.
2.格式化 vfat文件系统
[root@www root]# mkfs -t vfat /dev/sdb5
mkfs.vfat 2.8 (28 Feb 2001)
3.格式化swap文件系统;
[root@www root]#  mkswap /dev/sdb6
Setting up swapspace version 1, size = 509927 kB

================
五:挂载使用分区

[root@www root]# mkdir /mnt/sdb1
[root@www root]# mount /dev/sdb1 /mnt/sdb1
[root@www root]# cd /mnt/sdb1
[root@www sdb1]# touch testfile
[root@www sdb1]# ll
总用量 12
drwx------    2 root     root        12288 10月 16 19:22 lost+found
-rw-r--r--    1 root     root            0 10月 16 19:25 testfile
[root@www sdb1]# cd
[root@www root]# umount /mnt/sdb1
[root@www root]# ls /mnt/sdb1
==========================
六:让系统启动时自动挂载分区

[root@www root]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
/dev/sda3               swap                    swap    defaults        0 0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0
/dev/sdb1               /mnt/sdb1               auto    default         0 0















本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/32649/showart_310613.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP