linux磁盘分区
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux磁盘分区相关的知识,希望对你有一定的参考价值。
磁盘分区流程:
1.插入磁盘查看磁盘信息
2.使用fdisk分区管理工具分区
选择分区类型:扩展分区/主分区
选择第几个分区
分区起始位置
分区大小
分区类型
查看分区信息
保存
退出分区交互界面
3.格式化分区 设置分区的文件系统
4.挂载
命令: (下例的所有命令)
fdisk -l /dev/sdb
fdisk /dev/sdb
n--p--1--回车--+15G--l--t--83--p--w
mkdir /data
mkfs.ext4 /dev/sdb1
mount /dev/sdb1 /data
mount -a
mount
echo "/data /dev/sdb1 ext4 default 0 0" >>/etc/fstab
例:
1.查看加入磁盘的信息:
[[email protected] ~]# fdisk -l /dev/sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
2.使用fdisk磁盘管理工具进入交互界面进行分区:
[[email protected] ~]# fdisk /dev/sdb ##对dev/sdb磁盘作操作 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x281ead65. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): n ##输入n 新建分区 Command action e extended p primary partition (1-4) p ##选择分区类型,e extended 扩展分区 p primary partition 主分区 Partition number (1-4): 1 ##输入第几个分区 1-4 First cylinder (1-2610, default 1): ##分区的起始位置,回车默认 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +15G ##输入分区的大小 Command (m for help): l ##列出分区的类型 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext‘d (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Command (m for help): t ##t 选择分区的类型 Selected partition 1 Hex code (type L to list codes): 83 ##83是linux默认的分区类型 Command (m for help): p ##显示出分完区的信息 Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x281ead65 Device Boot Start End Blocks Id System /dev/sdb1 1 1959 15735636 83 Linux Command (m for help): w ##保存退出交互界面 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
3.格式化分区:
mkfs.制定文件系统 /dev/分区名
[[email protected] ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 983488 inodes, 3933909 blocks 196695 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=4030726144 121 block groups 32768 blocks per group, 32768 fragments per group 8128 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 29 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
4.挂载:
将/dev/sdb1分区挂载到/data这个目录.
[[email protected] ~]# mkdir /data ##新建目录
[[email protected] ~]# mount /dev/sdb1 /data/ # 临时挂载,在系统重启后就失效了 [[email protected] ~]# ls /data/ lost+found
##查看挂载目录,目录下会生成一个文件lost+fount
##这个文件是用来存放损坏和修复的文件,比如说系统down了,或者突然断电了,会残生损坏的文件,里面如果有文件了,那你就要注意了,检查。
[[email protected] ~]# mount -a ##刷新挂载分区 [[email protected] ~]# mount ##查看分区信息,最后一行是我们刚挂载的信息 /dev/mapper/VolGroup-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/VolGroup-lv_home on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/sdb1 on /data type ext4 (rw)
永久挂载,这个配置文件是存放磁盘挂载点的 每次开机都会加载这个文件,从而实现开机挂载
[[email protected] ~]# vi /etc/fstab
在最后一样加入:
/data /dev/sdb1 ext4 default 0 0
挂载的目录 分区 文件系统类型 挂载的权限 开机检测 备份
[[email protected] ~]# tail -l /etc/fstab # /dev/mapper/VolGroup-lv_root / ext4 defaults 1 1 UUID=d5b5318c-9872-4206-bb61-f0e7cbc3d05f /boot ext4 defaults 1 2 /dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2 /dev/mapper/VolGroup-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /data/dev/sdb1ext4default0 0 [[email protected] ~]# tail -1 /etc/fstab /data/dev/sdb1ext4default0 0
本文出自 “向往技术的小白” 博客,请务必保留此出处http://lesliecheung.blog.51cto.com/12622169/1957016
以上是关于linux磁盘分区的主要内容,如果未能解决你的问题,请参考以下文章