ubuntu16 外挂硬盘

1. 查看磁盘信息

fdisk -l

这里我需要对sda进行分区,所以要进到sda中

2. 进到欲分区磁盘中

$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

3. 按照提示查看信息:

Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): p
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 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
Disklabel type: dos
Disk identifier: 0x3370b165

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1  *     4096 209723391 209719296  100G  7 HPFS/NTFS/exFAT

4. 分区

可以看到,在我的sda中,4096到209723391部分已经分给了sda1,剩余空间可以进行分区,剩余空间的起止:209723392到500118191.

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 
First sector (2048-500118191, default 2048): 209723392
Last sector, +sectors or +size{K,M,G,T,P} (209723392-500118191, default 500118191): 

Created a new partition 2 of type 'Extended' and of size 138.5 GiB.

5. 分区完成,查看分区情况

Command (m for help): p
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 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
Disklabel type: dos
Disk identifier: 0x3370b165

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         4096 209723391 209719296   100G  7 HPFS/NTFS/exFAT
/dev/sda2       209723392 500118191 290394800 138.5G  5 Extended

6. 保存退出

注意,以上部分是更新的分区表,并未真正进行物理的分区,需要 键入 “w” 保存退出后才正式生效。

7. 修改格式为 ext4:

报错:

$ sudo mkfs -t ext4 /dev/sda2
mke2fs 1.42.13 (17-May-2015)
Found a dos partition table in /dev/sda2
Proceed anyway? (y,n) y
mkfs.ext4: inode_size (128) * inodes_count (0) too big for a
    filesystem with 0 blocks, specify higher inode_ratio (-i)
    or lower inode count (-N).

原因:原类型为extend,需要改为Linux。

change type:

$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 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
Disklabel type: dos
Disk identifier: 0x3370b165

Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         4096 209723391 209719296   100G  7 HPFS/NTFS/exFAT
/dev/sda2       209723392 500118191 290394800 138.5G  5 Extended

Command (m for help): t
Partition number (1,2, default 2): 2
Partition type (type L to list all types): 83

Changed type of partition 'Extended' to 'Linux'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

之后可以格式化为 ext4

$ sudo mkfs -t ext4 /dev/sda2
mke2fs 1.42.13 (17-May-2015)
Found a dos partition table in /dev/sda2
Proceed anyway? (y,n) y
Discarding device blocks: done                            
Creating filesystem with 36299350 4k blocks and 9076736 inodes
Filesystem UUID: bc630198-ae61-45af-a0c2-75e8e97cb5bd
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

8. 检查新文件系统

$ sudo fsck -f /dev/sda2
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda2: 11/9076736 files (0.0% non-contiguous), 617661/36299350 blocks

9. 挂载

自己可以新建一个文件作为挂载点,我在自己的home下 mkdir了new这个文件夹,将这块分区挂载在这里。

$sudo mount /dev/sda2 /home/lsy/new

如果觉得挂载错了,想重新挂载,可以用

$ umount /dev/sda2

之后再用之前的mount命令重新挂载即可。虽然挂载点变了,但是sda2中已经保存的内容不会改变的。

猜你喜欢

转载自www.cnblogs.com/shiyublog/p/10939061.html
今日推荐