说明,为了不做无用功,首先必须卸载要分区的设备,分区才能执行成功。通过命令umount /media/?? 或者umount /mnt/???
看你的实际情况,这一步必不可少。1、首先通过命令fdisk -l 在root命令下查看U盘的分区信息。
2、通过fdisk命令对挂载的设备进行分区操作,命令如下:fdisk /dev/sdb (可能不一定是这样,按照实际情况而定)。
3、输入fdisk /dev/sdb 会有提示命令,输入m就会列出来,如下所示:
[email protected]:~# fdisk /dev/sdbCommand (m for help): mCommand 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 u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only)Command (m for help): 4、输入p可以浏览当前设备的分区信息,如下所示:
Command (m for help): pDisk /dev/sdb: 7948 MB, 7948206080 bytes245 heads, 62 sectors/track, 1021 cylinders, total 15523840 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x13561963 Device Boot Start End Blocks Id System/dev/sdb1 2048 268287 133120 83 Linux/dev/sdb2 268288 15523839 7627776 83 LinuxCommand (m for help):
5、可以看到上面有两个分区,现在我删除这两个分区,d命令:
Command (m for help): dPartition number (1-4): 1Command (m for help): dSelected partition 2Command (m for help):
6、确定是否分区被删除了,在通过p命令:
Command (m for help): pDisk /dev/sdb: 7948 MB, 7948206080 bytes245 heads, 62 sectors/track, 1021 cylinders, total 15523840 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x13561963 Device Boot Start End Blocks Id SystemCommand (m for help): 可以看出没有了分区信息,删除分区成功。
7、现在新建分区,两个分区:
Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): Using default response pPartition number (1-4, default 1): Using default value 1First sector (2048-15523839, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-15523839, default 15523839): +200M //设定此分区的大小Command (m for help): 第一个分区已经新建完毕。
现在第二个分区:
Command (m for help): nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): Using default response pPartition number (1-4, default 2): Using default value 2First sector (411648-15523839, default 411648): Using default value 411648Last sector, +sectors or +size{K,M,G} (411648-15523839, default 15523839): //没有写,就表示剩下的空间都是此分区的。Using default value 15523839Command (m for help): 按照默认的就可以了,这样分区就完成了。
8、退出分区操作:
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
这一步有可能出错(如下),出错的原因是现有设备挂载了。首先必须卸载此设备,上面的操作才能执行成功。
Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.
上面分区成功,但是我们想要自己的文件系统,比如分区1是fat格式的,分区2是ext2格式的,这样怎样处理呢?非常重要的命令mkfs
其有很多种命令:
mkfs amfs 3 4dev mkfs.msdos mkfs.vfat mkfs.bfs 2 4 mkfs.minix fs
1、分区1为fat格式:
mkfs.vfat -F 32 -n vfat /dev/sdb1 //后面的vfat是自己起的设备的命令[email protected]:~# mkfs.vfat -F 32 -n fat /dev/sdb1mkfs.vfat 3.0.12 (29 Oct 2011)
2、分区2为ext2格式:
<2 -F -L ext2 /dev/sdb2 //同上,这个会格式化,时间依据空间的大小不定[email protected]:~# 2 -F -L ext2 /dev/sdb2 mke2fs 1.42 (29-Nov-2011)文件系统标签=ext2OS type: Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks472352 inodes, 1889024 blocks94451 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=193776844858 block groups32768 blocks per group, 32768 fragments per group8144 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: 完成 正在写入inode表: 完成 Writing superblocks and filesystem accounting information: 完成[email protected]:~#如果命令不知道,通过man mkfs.vfat查看,一目了然。
完成。
原文:.html
本文发布于:2024-02-03 00:41:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170689206147527.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |