1. View the disk information
fdisk -l
Here I need to sda partition, it will come in to sda in
2. To enter the disk partition
$ 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. Review the information when prompted:
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. Partition
It can be seen in my sda, the 4096-209723391 part has been given to sda1, the remaining space can be partitioned, beginning and ending remaining space: from 209,723,392 to 500,118,191.
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.
The partition is complete, check the partitions
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. Save and exit
Note that the above portion of the partition table is updated, not really a physical partition, you need to type "w" to save before exit into effect.
7. Modify the format ext4:
Error:
$ 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).
The reason: the original type extend, needs to be changed 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.
It can then be formatted as 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. Check the new file system
$ 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. Mount
They can create a new file as a mount point, I mkdir up in their own home new folder, this partition will be mounted here.
$ Sudo Mount / dev / sda2 / home / lsy / new
If you think mount wrong, I want to re-mount, you can use
$ umount /dev/sda2
Before then after the mount command to remount. Although the mount point has changed, but sda2 already saved content will not change.