How to partition in linux

Source: Internet
Author: User

How to partition in linux

Lab environment: ubuntu 12.04 LTS

1. Disconnect the VM and add a hard disk.

Scsi recommended

2. view the new Hard Disk:

Fdisk-l includes a USB flash disk.

     brave@ubuntu:~$ sudo fdisk -l

Disk/dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors here there are 255 heads, 63 sectors, each sector has 5221 cylinders

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: 0x000a8b99

Device Boot Start End Blocks Id System the id here is linux's id to identify what the partition is, 83 represents linux's partition 5 represents extended partition 82 represents swap Partition

/Dev/sda1*2048 81788927 40893440 83 Linux sda1 from 2048th cylinders to 81788927 cylinder total size is 40893440

/Dev/sda2 81790974 83884031 1046529 5 Extended

/Dev/sda5 81790976 83884031 1046528 82 Linux swap/Solaris

Disk/dev/sdb: 2147 MB, 2147483648 bytes

255 heads, 63 sectors/track, 261 cylinders, total 4194304 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

Disk/dev/sdb doesn' t contain a valid partition table

Here we can see that sdb is a new hard disk and there is no partition yet. Next we will start partitioning and executing fdisk/dev/sdb (your own disk)

3 fdisk/dev/sdb start partitioning

A toggle a bootable flag Set bootable flag
B edit bsd disklabel edit bsd disk label
C toggle the dos compatibility flag sets the dos operating system compatibility tag
D delete a partition
L list known partition types display known file system types 82 swap partition 83linux partition 5 extended partition
M print this menu displays the Help menu
N add a new partition create a partition
O create a new empty DOS partition table to create a blank dos partition table
P print the partition table displays the partition list
Q quit without saving changes does not save and exits
S create a new empty Sun disklabel to create a blank sun disk label
T change a partition's system id to change the system id of a partition
U change display/entry units change display record Unit
V verify the partition table to verify the partition table
W write table to disk and exit save and exit
X extra functionality (experts only) additional features, for expert use only

N key to add a partition

P (primary) add primary Partition

E (extension) add extended partitions

L (logical) add logical partitions

Here, we need to say that if there is no more, enter m to help check the information. Note that the primary partition can only be divided into four partitions. If you want to divide multiple partitions, You need to divide them into one extended partition, then allocate multiple logical partitions in the extended partitions.

After setting

Device Boot Start End Blocks Id System
/Dev/sdb1 2048 165887 81920 83 Linux
/Dev/sdb2 165888 4194303 2014208 5 Extended
/Dev/sdb5 167936 4194303 2013184 83 Linux

W save

4. Execute partprobe to read the partition table again without restarting.

Brave @ ubuntu :~ $ Sudo partprobe

5. format the partition.

Mkfs-t ext4/dev/sdb1 mkfs-t ext4/dev/sdb5

Format sdb1 sdb5Note that sdb2 cannot format extended partitions.

6. Create and mount a mount point

Mkdir/disk1

Mkdir/disk5

Mount/dev/sdb1/disk1

Mount/dev/sdb5/disk5

View the mount/df fdisk partition. You can only see that the partition is normally allocated, but you cannot see that the partition is mounted to it.

Brave @ ubuntu :~ $ Df here we can see that the new Shard has been successfully mounted!

/Dev/sdb1 79327 5646 69585 8%/disk1
/Dev/sdb5 1981520 35720 1845144 2%/disk5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.