Linux disk partitioning and Management

Source: Internet
Author: User

The partition of a linux disk is roughly the same as that of a windows disk. A slight difference is that a swap partition is added to the linux operating system, therefore, there must be at least two linux partitions: the root partition and the switch partition. However, sometimes the system's hard disk is not enough, so we need to add a hard disk to the original computer. However, it is not enough to only put the hard disk in the computer. We need to partition and format it, and finally mount the partition to the system last time. I will share my practices below

One Partition

If the hard disk is not enough, if the new linux operating system is not recognized immediately, we need to perform a series of operations to be recognized by the operating system. if you are on a virtual machine, you can select the hard disk in the settings, and then click Addy next. After this step is completed, we can use a simple command: sudo fdisk-l to view the devices on the system.

1. View devices on the System

We can clearly see that there is a/dev/sdb. This is the newly added hard disk.

2. Start partitioning

Here we need to know about disk partitions. linux and windows have primary partitions and extended partitions, and the extended partitions include logical partitions, there can be multiple primary partitions and logical partitions, but only one extended partition can exist. Enter the sudo fdisk device name on the linux terminal to partition the device.

If you do not know which commands are available, you can enter m.

3. Create a partition and format it.

You can add a new partition using m, where the sector can be not specified. All we need to specify is a size, which only requires one write + partition size, for example, + M indicates that the new partition is set to M. note that it is best to write M in upper case. For example, if M is written in lower case on ubuntu, an error is prompted.

Then you can enter p to view the partition. If there is no problem, enter w and press Enter. You can also enter w and press enter in Several partitions.

This step is also very important. After the partition is completed, You Need To Format (also called File System) and directly use the mkfs command. The usage is as follows:

Mkfs-t type partition name

Mkfs. ext3 partition name ------- directly formatted as ext3 File System

Mkswap partition name ----- format as swap Partition

As shown in

The process for creating swap partitions is as follows:

(1) Partition

(2) Change the partition to a swap partition.

(3) Save

(4) format as a swap Partition

(5) Enable swap Partition

Next we start to divide the extended partitions. Of course, it's okay to make the primary partition.

The command to modify the partition is t. Next, format one of the partitions as swap.

Next, enable swap partition. The command is swapon. Disable swapoff.

Using free, we can clearly see that the swap partition has become larger.

4. Attach a disk

In linux, the default mount directory is/mnt. You can use mount to mount the disk.

5. Detach a disk

If the device is busy, log out of the/mnt directory and uninstall the device again.

6. automatically mount the disk upon startup

If the system restarts, you need to re-mount the system. We can modify/ect/fstab, and add the device and mount point to the end to save and exit. The hard disk will be automatically mounted each time the system is started.

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.