《Linux之磁盘管理fdisk磁盘分区工具公开课.docx》由会员分享,可在线阅读,更多相关《Linux之磁盘管理fdisk磁盘分区工具公开课.docx(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Linux之磁盘管理fdisk磁盘分区工具:添加一块5G的虚拟硬盘,使用fdisk -I命令查看硬盘信息:root0ftp -# fdisk -IDisk /dev/sda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice BootStartEndBlocksId/dev/sdal *11310439183/dev/sda21410448281507+8eSystem LinuxLinux LVM
2、Disk /dev/sdb: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk Zdev/sdb doesn1t contain a valid partition table rootftp 二TFj/dev/sdb 是新添加的 SATA 硬盘,还没有进行分区,don t cantain a valid partition table : 不包含一个有效的分区表.使用fdisk设备名”命令进入分区管理交互
3、模式:rootftp fdisk /dev/sdb川Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab elBuilding a new DOS disklabel. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content wont be recoverable.Warning: invalid flag 0x0000
4、of partition table 4 will be corrected by w(rite)Command (m for help): |交互模式指令及其说明。指令说明1列出已知的分区类型。D删除一个分区M显示所有可以使用的fdisk命令P显示当前分区表N新建一个分区W保存退出q不保存退出L指令:Command (m for help): I0 EmptyleHidden W95FAT180Old MinixbfSolaris1 FAT1224NEC DOS81Minix / oldLin clDRDOS/sec (FAT-2 XENIX root39Plan 982Linux swap
5、 /So c4DRDOS/sec (FAT-3 XENIX usr3cPartitionMagic83Linuxc6DRDOS/sec (FAT-4 FAT16 32M40Venix 8028684OS/2 hiddenC: c7Syrinx5 Extended41PPC PReP Boot85Linux extended daNon-FS data6 FAT1642SFS86NTFS volumeset dbCP/M / CTOS / .7 HPFS/NTFS4dQNX4.x27NTFS volumeset deDell Utility8 AIX4eQNX4.x 2ndpart88Linux
6、 plaintext dfBootit9 AIX bootable4fQNX4.x 3rdpart9eLinux LVMelDOS accessa OS/2 Boot Manag50OnTrack DM93Amoebae3DOS R/0b W95 FAT3251OnTrack DM6Aux94Amoeba BBTe4SpeedStorC W95 FAT32 (LBA)52CP/M9fBSD/OSebBeOS fse W95 FAT16 (LBA)53OnTrack DM6AuxaOIBM Thinkpadhi eeEFI GPTf W95 Extd (LBA)540nTrackDM6a5Fre
7、eBSDefEFI (FAT-12/16/10 OPUS55EZ-Drivea6OpenBSDfeLinux/PA-RISC b11 Hidden FAT1256Golden Bowa7NeXTSTEPflSpeedStor12 Compaq diagnost5cPriam Ediska8Darwin UFSf4SpeedStor14 Hidden FAT16 361SpeedStora9NetBSDf2DOS secondary16 Hidden FAT1663GNU HURD orsysabDarwin bootfbVMware VMFS17 Hidden HPFS/NTF64Novell
8、 Netwareb7BSDI fsfcVMware VMKCORE18 AST Smartsleep65Novell Netwareb8BSDI swapfdLinux raid autolb Hidden W95 FAT370DiskSecureMultbbBoot Wizardhid feLANstepM指令:Command (m for help): mCommand actionatoggle a bootable flagbedit bsd disklabelctoggle the dos compatibility flagddelete a partitionIlist know
9、n partition typesmprint this menunadd a new partitiono create a new empty DOS partition tabpprint the partition tableqquit without saving changess create a new empty Sun disklabel.tchange a partitions system iduchange display/entry unitsvverify the partition tablew write table to disk and exitx extr
10、a functionality (experts only)C nmmand ( m r hal n N指令穿件一个新的分区:rootftp # fdisk /dev/sdbCommand (m for helJ): nCommand action e extended p primary partition (1-4)PPartition number (1-4): 1First cylinder (l-652-default 1):Using default value 1Last cylinder or +size or +sizeM or +sizeK (1-652, defaultU
11、sing default value 652Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.第一步输入n,创建新分区 第二步选择分区类型:e (extended)代表扩展分区,p (primary)代表主分区第三步创建主分区号为1第四步设置开始位置,缺省为1第五步设置分区大小,缺省为剩余全部空间第六步保存退出。P指令查看分区情况:Command (m for help): pDisk /dev/sdb: 536
12、8 MB, 5368709120 bytes652 cylinders512 = 8225280 bytes255 heads, 63 sectors/track, Units = cylinders of 16065 Device Boot /dev/sdblDevice Boot /dev/sdblStart1End652Blocks Id System 5237158+ 83 Linuxrootftp -# fdisk -IDisk /dev/sda: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinder
13、sUnits - cylinders of 16065 * 512-8225280 bytesId838eSystem LinuxLinux LVMDevice Boot /dev/sdal * /dev/sda2Start114End13 1044Blocks104391 8281507+Disk /dev/sdb: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280Device BootStartEndbytesBlock
14、sIdSystem/dev/sdbl16525237158+83Linux使用mkfs创建文件系统:rootftp -# mkfs -t ext3 -b 2648 /dev/sdbl mke2fs 1.39 (29-May-2666)Filesystem label=OS type: LinuxBlock size-2648 (log=l)Fragment size=2048 (log=l) 655360 inodes, 2618578 blocks130928 blocks (5.00%) reserved for the super userFirst data block=0Maximu
15、m filesystem blocks=54e01664e160 block groups16384 blocks per group, 16384 fragments per group4096 inodes per groupSuperblock backups stored on blocks:16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000Writing inode tables: doneCreating journal (32768 blocks): doneWriting s
16、uperblocks and filesystem accounting information: w doneThis filesystem will be automatically checked every 29 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override, -t :指定文件系统类型。-b:指定文件块大小使用mount挂载分区:root(aftp # mount /dev/sdbl /test/rootftp # df文件系统IK一块已用可用已用先挂载点/dev/mapper/V
17、olGroup60-LogVol.0069831683041636358108446%/dev/sdal101086121858368213%/boottmpfs25765602576560%/dev/shm/dev/sdbl51545087695248157002%/test利用fstab文件实现开机自动挂载:l/dev/VolGroupOO/LogVoloe /ext3defaults1 1LABEL/boot/bootext3defaults1 2rmpfs/dev/shmtmpfsdefaultse 0devpts/dev/ptsdevptsgid-5,mode-620e osysfs
18、/syssysfsdefaultse oproc/procprocdefaultse o/dev/VolGroup00/LogVolOl swapswapdefaults0 /dev/sdbl/testext3defaultse o|磁盘配额的系统配置:L在fstab文件中添加“usrquota”和grpquota参数/dev/VolGroupG9/LogVol00 /ext3defaults1 1LABEL-/boot/bootext3defaults1 2tmpfs/dev/shmtmpfsdefaultsG 0devpts/dev/ptsdevptsgid-5,mode-6200 0sy
19、sfs/syssysfsdefaults0 9proc/procprocdefaults0 0/dev/VolGroupe9/LogVol01 swapswapdefaultsG G/dev/sdbl/testext3defaults,usrquota,grpquota|usrquota参数表示在该文件系统中限制用户的使用空间 grpquota参数表示在该文件系统中限制用户组的使用空间 2.重新挂载配额分区|rootftp *# mount -o remount /test重载过程是先卸载分区,在重新挂载,根分区是无法卸载的3 .生成aquota.group和aquota.user磁盘配额文件
20、为了使系统能够按照磁盘配额进行工作,必须先建立磁盘配额文件aquota.group和 aquota.user0使用quotacheck命令可以完成配额文件的自动创建。Quotacheck命令还具有 还具有检查文件系统、建立硬盘使用率列表,以及检查每个文件系统的空间限额等功能。rootftp # quotacheck -avguquotacheck: Scanning /dev/sdtfl-tTtest quotacheck: Cannot stat old user quota file:没有那个文件 或目录quotacheck: Cannot stat old group quota fil
21、e:没有那个文件或目录quotacheck: Cannot stat old user quota file:没有那 文件或目录quotacheck: Cannot stat old group quota file:没有那个文件或目录 donequotacheck: Checked 3 directories and 2 filesquotacheck: Old file not found.quotacheck: Old file not found.rootftp cd /test/(rootftp test# Is 、Aniinta nrmin AHimta iiuar* 1 nct.
22、fmind参数:-a :扫描在/etc/mtab文件中所有挂载的非NTFS文件系统- v :显示命令执行过程- g :计算每个用户组占用的目录和文件数目,并创建aquota.group文件- u :计算每个用户占用的目录和文件数目,并创建aquota.user文件.利用edquota命令给用户进行磁盘配额:|rootftp edquota-u userlhardinodessofthard50000080100|isk quotas for user userl (uid 503):Filesystemblocks soft/dev/sdbl640090Blocks表示已经使用的磁盘空间。So
23、ft表示用户的软限额,当用户使用的磁盘空间达到40M时,系统会提示用户已经达到软 限额,但用户仍可以继续写入。Hard表示用户的硬限额,当硬限额达到50M时,系统将禁止用户继续写入Inodes表示i节点数,即用户的建立的文件数。Soft表示用户建立文件数的软限额,达到后会提示用户,但仍可以创建文件。Hard表示用户建立文件数的硬限额,达到硬限额后用户将无法建立文件或目录。edquota命令参数及说明:选项说明-g设置用户组的磁盘配额限制-u设置用户的磁盘配额限制,缺省值-p对磁盘配额设置进行复制-t为文件系统设置软时间限制如果有很多用户需要设置相同的配额,则可以使用-p选项复制:rootftp # edquota -p userl -u user? user3 user4 user5 user6配置脚本:#!/bin/bashQor num in S(seq 2 20)doser=userSnumedquota -p userl -u Suserdone