linux磁盘相关操作

  • 查看哪些磁盘挂载着: sudo fdisk -l
Disk /dev/sdd: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
  • 分区和格式化: sudo fdisk /dev/sdd
ckt@ubuntu:~$ sudo fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xfee324c4.
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)

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
   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): n #添加一个新分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p  #主分区
Partition number (1-4, default 1): 1  #1个分区
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039

Command (m for help): p  #打印分区表

Disk /dev/sdd: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xfee324c4

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1            2048    41943039    20970496   83  Linux

Command (m for help): w  #保存修改
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
  • 格式化:

    查看已有分区格式: df -T -h。
    根据现有分区格式格式新的分区: mkfs.ext4 /dev/sdd1

  • 挂载到文件夹:

    mkdir ~/work
    mount /dev/sdd1 ~/work
    按以上方法挂载的文件夹在重启后需要重新挂载,若要重启后也有效,需使用修改/etc/fstab文件的方法,在该文件最后添加如下内容:

/dev/sdd1   /home/ckt/work  ext4    defaults    0   1

你可能感兴趣的:(linux,磁盘操作)