Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5096395
  • 博文数量: 921
  • 博客积分: 16037
  • 博客等级: 上将
  • 技术积分: 8469
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-05 02:08
文章分类

全部博文(921)

文章存档

2020年(1)

2019年(3)

2018年(3)

2017年(6)

2016年(47)

2015年(72)

2014年(25)

2013年(72)

2012年(125)

2011年(182)

2010年(42)

2009年(14)

2008年(85)

2007年(89)

2006年(155)

分类: LINUX

2015-10-22 14:26:05

Linux硬盘分区(一):添加
********************************


*************************
过程简述

*************************

  1. --添加磁盘
  2. # fdisk -l --查看磁盘情况
  3. # fdisk /dev/sdb --为/dev/sdb设备分区
  4. n --添加分区
  5. p/e --主分区/逻辑分区
  6. w --保存退出
  7. # mkdir /data --创建挂载目录
  8. # mkfs.ext3 /dev/sdb --格式化磁盘为ext3文件系统
  9. # fdisk -l --再次查看磁盘情况
  10. # mount /dev/sdb /data --挂载磁盘到创建的挂载目录下
  11. # vi /etc/fstab --修改启动自动挂载项
  12. /dev/sdb /data ext3 defaults 0 0

*************************
说明
*************************

1、以上操作为精炼总结,若如可以看懂,下面内容无需浏览;
2、以下简单列举两例,细化操作过程。

*****************************************************************************************************

 

举例1:添加1块90G磁盘,将其分为1个分区

*****************************************************************************************************

*************************
查看磁盘情况
*************************


  1. [root@hyldb /]# fdisk -l
  2. Disk /dev/sda: 128.8 GB, 128849018880 bytes
  3. 255 heads, 63 sectors/track, 15665 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sda1 * 1 64 514048+ 83 Linux
  7. /dev/sda2 65 586 4192965 82 Linux swap / Solaris
  8. /dev/sda3 587 15665 121122067+ 83 Linux
  9. Disk /dev/sdb: 96.6 GB, 96636764160 bytes
  10. 255 heads, 63 sectors/track, 11748 cylinders
  11. Units = cylinders of 16065 * 512 = 8225280 bytes
  12. Disk /dev/sdb doesn't contain a valid partition table

*************************
磁盘分区
*************************


  1. [root@hyldb /]# fdisk /dev/sdb
  2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  3. Building a new DOS disklabel. Changes will remain in memory only,
  4. until you decide to write them. After that, of course, the previous
  5. content won't be recoverable.
  6. The number of cylinders for this disk is set to 11748.
  7. There is nothing wrong with that, but this is larger than 1024,
  8. and could in certain setups cause problems with:
  9. 1) software that runs at boot time (e.g., old versions of LILO)
  10. 2) booting and partitioning software from other OSs
  11. (e.g., DOS FDISK, OS/2 FDISK)
  12. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  13. Command (m for help): m
  14. --输入m查看帮助:指令提示
  15. Command action
  16. a toggle a bootable flag
  17. b edit bsd disklabel
  18. c toggle the dos compatibility flag
  19. d delete a partition
  20. l list known partition types
  21. m print this menu
  22. n add a new partition
  23. o create a new empty DOS partition table
  24. p print the partition table
  25. q quit without saving changes
  26. s create a new empty Sun disklabel
  27. t change a partition's system id
  28. u change display/entry units
  29. v verify the partition table
  30. w write table to disk and exit
  31. x extra functionality (experts only)
  32. Command (m for help): n
  33. --添加新分区
  34. Command action
  35. e extended
  36. p primary partition (1-4)
  37. p
  38. --输入p添加主分区
  39. Partition number (1-4): 1
  40. --填写分区号
  41. First cylinder (1-11748, default 1):
  42. Using default value 1
  43. Last cylinder or +size or +sizeM or +sizeK (1-11748, default 11748):
  44. Using default value 11748
  45. Command (m for help): p
  46. --打印分区列表
  47. Disk /dev/sdb: 96.6 GB, 96636764160 bytes
  48. 255 heads, 63 sectors/track, 11748 cylinders
  49. Units = cylinders of 16065 * 512 = 8225280 bytes
  50. Device Boot Start End Blocks Id System
  51. /dev/sdb1 1 11748 94365778+ 83 Linux
  52. Command (m for help): w
  53. --保存退出
  54. The partition table has been altered!
  55. Calling ioctl() to re-read partition table.
  56. Syncing disks.
*************************
创建挂载目录
*************************

  1. [root@hyldb /]# mkdir /data

*************************
格式化磁盘
*************************


  1. [root@hyldb /]# mkfs.ext3 /dev/sdb
  2. --格式化sdb1,格式成ext3格式文件系统
  3. mke2fs 1.39 (29-May-2006)
  4. /dev/sdb is entire device, not just one partition!
  5. Proceed anyway? (y,n) y
  6. Filesystem label=
  7. OS type: Linux
  8. Block size=4096 (log=2)
  9. Fragment size=4096 (log=2)
  10. 11796480 inodes, 23592960 blocks
  11. 1179648 blocks (5.00%) reserved for the super user
  12. First data block=0
  13. Maximum filesystem blocks=4294967296
  14. 720 block groups
  15. 32768 blocks per group, 32768 fragments per group
  16. 16384 inodes per group
  17. Superblock backups stored on blocks:
  18. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  19. 4096000, 7962624, 11239424, 20480000
  20. Writing inode tables: done
  21. Creating journal (32768 blocks): done
  22. Writing superblocks and filesystem accounting information: done
  23. This filesystem will be automatically checked every 33 mounts or
  24. 180 days, whichever comes first. Use tune2fs -c or -i to override.
  25. [root@hyldb /]# fdisk -l
  26. Disk /dev/sda: 128.8 GB, 128849018880 bytes
  27. 255 heads, 63 sectors/track, 15665 cylinders
  28. Units = cylinders of 16065 * 512 = 8225280 bytes
  29. Device Boot Start End Blocks Id System
  30. /dev/sda1 * 1 64 514048+ 83 Linux
  31. /dev/sda2 65 586 4192965 82 Linux swap / Solaris
  32. /dev/sda3 587 15665 121122067+ 83 Linux
  33. Disk /dev/sdb: 96.6 GB, 96636764160 bytes
  34. 255 heads, 63 sectors/track, 11748 cylinders
  35. Units = cylinders of 16065 * 512 = 8225280 bytes
  36. Disk /dev/sdb doesn't contain a valid partition table

*************************
挂载磁盘到指定路径下
*************************


  1. [root@hyldb /]# mount /dev/sdb /data
  2. [root@hyldb /]# df -h
  3. Filesystem Size Used Avail Use% Mounted on
  4. /dev/sda3 112G 4.3G 102G 5% /
  5. /dev/sda1 487M 17M 445M 4% /boot
  6. tmpfs 1006M 0 1006M 0% /dev/shm
  7. /dev/sdb 89G 184M 84G 1% /data

*************************
修改启动磁盘自动挂载
*************************


  1. [root@xckydb ~]# vi /etc/fstab
  2. LABEL=/ / ext3 defaults 1 1
  3. LABEL=/boot /boot ext3 defaults 1 2
  4. tmpfs /dev/shm tmpfs defaults 0 0
  5. devpts /dev/pts devpts gid=5,mode=620 0 0
  6. sysfs /sys sysfs defaults 0 0
  7. proc /proc proc defaults 0 0
  8. LABEL=SWAP-sda2 swap swap defaults 0 0
  9. /dev/sdb /data ext3 defaults 0 0
  10. ~
  11. ~
  12. "/etc/fstab" 8L, 608C written
  13. --格式说明
  14. /dev/sdb1 /u01 ext3 defaults 0 0
  15. 要挂载的对象 挂载的目录 系统类型 文件系统访问权限 开机后是否检测 出问题后是否转储

*****************************************************************************************************

 

举例2:

1、添加1块10G磁盘;
2、将其分为六个分区;
3、三个主分区分别为2G;
4、剩余空间分为扩展分区,具体分为两个逻辑分区分别为1G,剩余空间单独分为一个逻辑分区。
*****************************************************************************************************


*************************
查看磁盘情况
*************************

  1. [root@hyl ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/sda1 9.7G 5.4G 3.9G 59% /
  4. /dev/sda3 35G 17G 17G 50% /home
  5. tmpfs 1006M 0 1006M 0% /dev/shm
  6. [root@hyl ~]# fdisk -l
  7. Disk /dev/sda: 53.6 GB, 53687091200 bytes
  8. 255 heads, 63 sectors/track, 6527 cylinders
  9. Units = cylinders of 16065 * 512 = 8225280 bytes
  10. Device Boot Start End Blocks Id System
  11. /dev/sda1 * 1 1305 10482381 83 Linux
  12. /dev/sda2 1306 1827 4192965 82 Linux swap / Solaris
  13. /dev/sda3 1828 6527 37752750 83 Linux
  14. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  15. 255 heads, 63 sectors/track, 1305 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17. Disk /dev/sdb doesn't contain a valid partition table

*************************
为/dev/sdb设备分区
*************************


  1. [root@hyl ~]# fdisk /dev/sdb
  2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  3. Building a new DOS disklabel. Changes will remain in memory only,
  4. until you decide to write them. After that, of course, the previous
  5. content won't be recoverable.
  6. The number of cylinders for this disk is set to 1305.
  7. There is nothing wrong with that, but this is larger than 1024,
  8. and could in certain setups cause problems with:
  9. 1) software that runs at boot time (e.g., old versions of LILO)
  10. 2) booting and partitioning software from other OSs
  11. (e.g., DOS FDISK, OS/2 FDISK)
  12. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  13. Command (m for help): m
  14. Command action
  15. a toggle a bootable flag
  16. b edit bsd disklabel
  17. c toggle the dos compatibility flag
  18. d delete a partition
  19. l list known partition types
  20. m print this menu
  21. n add a new partition
  22. o create a new empty DOS partition table
  23. p print the partition table
  24. q quit without saving changes
  25. s create a new empty Sun disklabel
  26. t change a partition's system id
  27. u change display/entry units
  28. v verify the partition table
  29. w write table to disk and exit
  30. x extra functionality (experts only)

*************************

创建第一个主分区:大小2G
*************************


  1. Command (m for help): n
  2. Command action
  3. e extended
  4. p primary partition (1-4)
  5. p
  6. Partition number (1-4): 1
  7. First cylinder (1-1305, default 1):
  8. Using default value 1
  9. Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +2048M

*************************
创建第二个主分区:大小2G
*************************


  1. Command (m for help): n
  2. Command action
  3. e extended
  4. p primary partition (1-4)
  5. p
  6. Partition number (1-4): 1
  7. First cylinder (1-1305, default 1):
  8. Using default value 1
  9. Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305): +2048M
  10. Command (m for help): n
  11. Command action
  12. e extended
  13. p primary partition (1-4)
  14. p
  15. Partition number (1-4): 2
  16. First cylinder (251-1305, default 251):
  17. Using default value 251
  18. Last cylinder or +size or +sizeM or +sizeK (251-1305, default 1305): +2048M

*************************
创建第三个主分区:大小2G
*************************

  1. Command (m for help): n
  2. Command action
  3. e extended
  4. p primary partition (1-4)
  5. p
  6. Partition number (1-4): 3
  7. First cylinder (501-1305, default 501):
  8. Using default value 501
  9. Last cylinder or +size or +sizeM or +sizeK (501-1305, default 1305): +2048M

*************************
先打印分区列表看一下
*************************

  1. Command (m for help): p
  2. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  3. 255 heads, 63 sectors/track, 1305 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sdb1 1 250 2008093+ 83 Linux
  7. /dev/sdb2 251 500 2008125 83 Linux
  8. /dev/sdb3 501 750 2008125 83 Linux

*************************
创建扩展分区
*************************


  1. Command (m for help): n
  2. Command action
  3. e extended
  4. p primary partition (1-4)
  5. e
  6. Selected partition 4
  7. First cylinder (751-1305, default 751):
  8. Using default value 751
  9. Last cylinder or +size or +sizeM or +sizeK (751-1305, default 1305):
  10. Using default value 1305

*************************
创建第一个逻辑分区:大小1G
*************************

  1. Command (m for help): n
  2. First cylinder (751-1305, default 751):
  3. Using default value 751
  4. Last cylinder or +size or +sizeM or +sizeK (751-1305, default 1305): +1024M

*************************
创建第二个逻辑分区:大小1G
*************************

  1. Command (m for help): n
  2. First cylinder (876-1305, default 876):
  3. Using default value 876
  4. Last cylinder or +size or +sizeM or +sizeK (876-1305, default 1305): +1024M

*************************
剩余容量创建最后一个逻辑分区
*************************

  1. Command (m for help): n
  2. First cylinder (1001-1305, default 1001):
  3. Using default value 1001
  4. Last cylinder or +size or +sizeM or +sizeK (1001-1305, default 1305):
  5. Using default value 1305
*************************
打印分区列表
*************************


  1. Command (m for help): p
  2. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  3. 255 heads, 63 sectors/track, 1305 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sdb1 1 250 2008093+ 83 Linux
  7. /dev/sdb2 251 500 2008125 83 Linux
  8. /dev/sdb3 501 750 2008125 83 Linux
  9. /dev/sdb4 751 1305 4458037+ 5 Extended
  10. /dev/sdb5 751 875 1004031 83 Linux
  11. /dev/sdb6 876 1000 1004031 83 Linux
  12. /dev/sdb7 1001 1305 2449881 83 Linux
*************************
保存退出
*************************


  1. Command (m for help): w
  2. The partition table has been altered!
  3. Calling ioctl() to re-read partition table.
  4. Syncing disks.
*************************
查看磁盘划分
*************************


  1. [root@hyl ~]# fdisk -l
  2. Disk /dev/sda: 53.6 GB, 53687091200 bytes
  3. 255 heads, 63 sectors/track, 6527 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sda1 * 1 1305 10482381 83 Linux
  7. /dev/sda2 1306 1827 4192965 82 Linux swap / Solaris
  8. /dev/sda3 1828 6527 37752750 83 Linux
  9. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  10. 255 heads, 63 sectors/track, 1305 cylinders
  11. Units = cylinders of 16065 * 512 = 8225280 bytes
  12. Device Boot Start End Blocks Id System
  13. /dev/sdb1 1 250 2008093+ 83 Linux
  14. /dev/sdb2 251 500 2008125 83 Linux
  15. /dev/sdb3 501 750 2008125 83 Linux
  16. /dev/sdb4 751 1305 4458037+ 5 Extended
  17. /dev/sdb5 751 875 1004031 83 Linux
  18. /dev/sdb6 876 1000 1004031 83 Linux
  19. /dev/sdb7 1001 1305 2449881 83 Linux
  20. --由此可以看出,sdb1、sdb2、sdb3为主分区,sdb5、sdb6、sdb7为逻辑分区

*************************
举例:将sdb1格式化为ext3文件系统
*************************


  1. [root@hyl ~]# cd /
  2. [root@hyl /]# mkdir data1
  3. [root@hyl /]# mkfs.ext3 /dev/sdb1
  4. mke2fs 1.39 (29-May-2006)
  5. Filesystem label=
  6. OS type: Linux
  7. Block size=4096 (log=2)
  8. Fragment size=4096 (log=2)
  9. 251392 inodes, 502023 blocks
  10. 25101 blocks (5.00%) reserved for the super user
  11. First data block=0
  12. Maximum filesystem blocks=515899392
  13. 16 block groups
  14. 32768 blocks per group, 32768 fragments per group
  15. 15712 inodes per group
  16. Superblock backups stored on blocks:
  17. 32768, 98304, 163840, 229376, 294912
  18. Writing inode tables: done
  19. Creating journal (8192 blocks): done
  20. Writing superblocks and filesystem accounting information: done
  21. This filesystem will be automatically checked every 28 mounts or
  22. 180 days, whichever comes first. Use tune2fs -c or -i to override.

*************************
举例:为sdb1设置开机自动挂载

 

*************************


  1. [root@hyl /]# vi /etc/fstab
  2. --设置开机自动挂载
  3. LABEL=/ / ext3 defaults 1 1
  4. LABEL=/home /home ext3 defaults 1 2
  5. tmpfs /dev/shm tmpfs defaults 0 0
  6. devpts /dev/pts devpts gid=5,mode=620 0 0
  7. sysfs /sys sysfs defaults 0 0
  8. proc /proc proc defaults 0 0
  9. LABEL=SWAP-sda2 swap swap defaults 0 0
  10. /dev/sdb1 /data1 ext3 defaults 0 0
  11. ~
  12. ~
  13. ~
  14. "/etc/fstab" 8L, 608C written
  15. [root@hyl /]# mount /dev/sdb1 /data1
  16. [root@hyl /]# df -h
  17. Filesystem Size Used Avail Use% Mounted on
  18. /dev/sda1 9.7G 5.4G 3.9G 59% /
  19. /dev/sda3 35G 17G 17G 50% /home
  20. tmpfs 1006M 0 1006M 0% /dev/shm
  21. /dev/sdb1 1.9G 35M 1.8G 2% /data1

*****************************************************************************************************
Linux硬盘分区(二):删除

*****************************************************************************************************

 

*************************
举例:对sdb1进行umount

*************************


  1. [root@hyl /]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/sda1 9.7G 5.4G 3.9G 59% /
  4. /dev/sda3 35G 17G 17G 50% /home
  5. tmpfs 1006M 0 1006M 0% /dev/shm
  6. /dev/sdb1 1.9G 35M 1.8G 2% /data1
  7. [root@hyl /]# umount /data1
  8. [root@hyl /]# df -h
  9. Filesystem Size Used Avail Use% Mounted on
  10. /dev/sda1 9.7G 5.4G 3.9G 59% /
  11. /dev/sda3 35G 17G 17G 50% /home
  12. tmpfs 1006M 0 1006M 0% /dev/shm
  13. [root@hyl /]# fdisk -l
  14. Disk /dev/sda: 53.6 GB, 53687091200 bytes
  15. 255 heads, 63 sectors/track, 6527 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17. Device Boot Start End Blocks Id System
  18. /dev/sda1 * 1 1305 10482381 83 Linux
  19. /dev/sda2 1306 1827 4192965 82 Linux swap / Solaris
  20. /dev/sda3 1828 6527 37752750 83 Linux
  21. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  22. 255 heads, 63 sectors/track, 1305 cylinders
  23. Units = cylinders of 16065 * 512 = 8225280 bytes
  24. Device Boot Start End Blocks Id System
  25. /dev/sdb1 1 250 2008093+ 83 Linux
  26. /dev/sdb2 251 500 2008125 83 Linux
  27. /dev/sdb3 501 750 2008125 83 Linux
  28. /dev/sdb4 751 1305 4458037+ 5 Extended
  29. /dev/sdb5 751 875 1004031 83 Linux
  30. /dev/sdb6 876 1000 1004031 83 Linux
  31. /dev/sdb7 1001 1305 2449881 83 Linux

*************************
对第二块磁盘操作(即/dev/sdb)
*************************


  1. [root@hyl /]# fdisk /dev/sdb
  2. The number of cylinders for this disk is set to 1305.
  3. There is nothing wrong with that, but this is larger than 1024,
  4. and could in certain setups cause problems with:
  5. 1) software that runs at boot time (e.g., old versions of LILO)
  6. 2) booting and partitioning software from other OSs
  7. (e.g., DOS FDISK, OS/2 FDISK)
  8. Command (m for help): m
  9. Command action
  10. a toggle a bootable flag
  11. b edit bsd disklabel
  12. c toggle the dos compatibility flag
  13. d delete a partition
  14. l list known partition types
  15. m print this menu
  16. n add a new partition
  17. o create a new empty DOS partition table
  18. p print the partition table
  19. q quit without saving changes
  20. s create a new empty Sun disklabel
  21. t change a partition's system id
  22. u change display/entry units
  23. v verify the partition table
  24. w write table to disk and exit
  25. x extra functionality (experts only)
  26. Command (m for help): p
  27. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  28. 255 heads, 63 sectors/track, 1305 cylinders
  29. Units = cylinders of 16065 * 512 = 8225280 bytes
  30. Device Boot Start End Blocks Id System
  31. /dev/sdb1 1 250 2008093+ 83 Linux
  32. /dev/sdb2 251 500 2008125 83 Linux
  33. /dev/sdb3 501 750 2008125 83 Linux
  34. /dev/sdb4 751 1305 4458037+ 5 Extended
  35. /dev/sdb5 751 875 1004031 83 Linux
  36. /dev/sdb6 876 1000 1004031 83 Linux
  37. /dev/sdb7 1001 1305 2449881 83 Linux

*************************
删除分区:sdb1及其它
*************************


  1. Command (m for help): d
  2. --输入删除指令
  3. Partition number (1-7): 1
  4. --输入删除的分区号
  5. Command (m for help): p
  6. --打印分区表
  7. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  8. 255 heads, 63 sectors/track, 1305 cylinders
  9. Units = cylinders of 16065 * 512 = 8225280 bytes
  10. Device Boot Start End Blocks Id System
  11. /dev/sdb2 251 500 2008125 83 Linux
  12. /dev/sdb3 501 750 2008125 83 Linux
  13. /dev/sdb4 751 1305 4458037+ 5 Extended
  14. /dev/sdb5 751 875 1004031 83 Linux
  15. /dev/sdb6 876 1000 1004031 83 Linux
  16. /dev/sdb7 1001 1305 2449881 83 Linux
  17. --可以看到sdb1已经被删除了
  18. --接下来同理,删除其它分区
  19. Command (m for help): d
  20. Partition number (1-7): 2
  21. Command (m for help): d
  22. Partition number (1-7): 3
  23. Command (m for help): d
  24. Partition number (1-7): 4
  25. Command (m for help): p
  26. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  27. 255 heads, 63 sectors/track, 1305 cylinders
  28. Units = cylinders of 16065 * 512 = 8225280 bytes
  29. Device Boot Start End Blocks Id System
  30. Command (m for help): w
  31. --保存退出
  32. The partition table has been altered!
  33. Calling ioctl() to re-read partition table.
  34. Syncing disks.
  35. --现在可以移除磁盘了



原文






阅读(4755) | 评论(0) | 转发(1) |
1

上一篇:游戏AI设计

下一篇:Crontab的格式

给主人留下些什么吧!~~