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


 



How to partition in Linux

Solution 1: "standard" SOLUTION

/8g swap 2G/BOOT 100 m/USR 7G/HOME 8G

Note: In fact, 6 GB for/8G is enough, but some redundancy is required. For example, some software is installed here by default, or you temporarily place some files on the desktop (if you are under ROOT). Therefore, we recommend that you use 8 GB

SWAP 2 GB temporary partition, the maximum value is 2 GB. If your physical memory is large enough, such as MB or more, SWAP can be set to a smaller value. Generally, it is set to the maximum value, because the 2 GB disk may be nothing (currently the hard disk is dozens of hundreds of GB), but when you are running a lot of programs, maybe this SWAP came in handy (I once observed my system, and even m of memory was used up-I didn't open any large programs, and I also called SWAP .)

The BOOT partition/BOOT 100 M is usually used as an independent partition. If you are only experimenting with it, you do not need to divide it separately. But remember, in a single LINUX system, this partition should be independent.

/USR 7G to be accurate, 7G may be a little small, if you need to use the MYSQL service. This is usually where program files are stored. Some databases, such as MYSQL, do not specify the database storage path .. Therefore, you can adjust the size of this area as needed.

/HOME 8g you said you need to place some music files or something, so the corresponding partition is a little larger. You can determine the size of this area based on the total amount of your space

The above is a balanced division. If a single hard disk is used in all cases, the proportion can be basically used. Because it is an experiment, we will not divide the/VAR partition separately. In the future, we may need to divide the/VAR partition, which is usually used to set FTP and WEB services, some system logs are also stored here. Because space is limited, it is not divided separately.

Solution 2 "extreme" solutions

First, determine the approximate amount of space you need in/HOME, and then allocate all the remaining space/
Or you are not sure, please allocate all the space/

I hope the proposed solution will be useful to you ~

How to partition LINUX?

In LINUX system management, if not, search for GParted in the new version and mark the installation. In this way, a "partition Editor" will be added to the system management ". Use it to format the hard disk.
The commands on the upstairs are too complex to be used by beginners. You can also use the partitioning tool in the WINPE micro-system to partition (start the disc or USB flash disk, currently, GHOST disks all contain PE). If you only use LINUX, we recommend that you use EXT4 partitions. Otherwise, use NTFS. Note that you need to specify a part of swap space, which is equivalent to WINDOWS virtual memory, generally, it is twice the physical memory size. It does not need to be so large. It should be about MB.
 

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.