A detailed approach to creating partitions and file systems under Linux

Source: Internet
Author: User
Tags data structures require versions root directory gparted

Creating partitions or new file systems in Linux usually means one thing: Install the Gnome Parted Partition editor (GParted). This is the only way for most Linux users. However, have you ever considered creating these partitions and filesystems at the terminal? Of course! Here's how it's done!

Use Cfdisk to create a basic Linux partition

The following is the correct scenario for creating a basic Linux partition on the command line. The first thing to do is to open your terminal first. If you are open, you need to find the disk where you want to create the partition. This can be found by using a simple command.

Copy Code

The code is as follows:

Lsblk

When you run the LSBLK, you should see a detailed list of each disk on the current system. Take a look at this list and find out which disk you want to use. In this article, I'll use SDB to do the demo.

Enter this command at the terminal. It displays a powerful, terminal-based partition-editing program.

The code is as follows:

sudo cfdisk/dev/sdb

Note: Replace SDB with the disk you want to use in the LSBLK command.

When you enter this command, you will enter the partition editor and then access the disk you want to change.

Because of the different disk partitions, depending on the needs of the user, this section of the guide will be on how to build a separate Linux home/root partition layout.

First, you need to create a root partition. This needs to be segmented based on the number of bytes in the disk. The disk I tested is GB.

Use the arrow keys on the keyboard in Cfdisk to select the space you want to allocate. When you find it, use the arrow keys to select [NEW], and then press Enter.

The program will require you to enter the partition size. Once you have specified a good size, press Enter. This will be referred to as the root partition (or/DEV/SDB1).

The next step is to create the home partition (/DEV/SDB2). You need to select some free partitions in the Cfdisk. Use the arrows to select the NEW option, and then press Enter. Enter the size of your home partition and press ENTER to create it.

Finally, you need to create an interchange partition. Like the first two, find some free partitions and use the arrows to select the NEW option. Then, calculate how much of the swap partition you want Linux to use.

Note: Swap partitions are usually about the same size as your computer's memory.

Now you have created the swap partition, which specifies its type. Use the up and down arrows to select it. Then use the left and right arrows to select [TYPE]. Locate the Linux swap option, and then press the Enter key.

After all partitions are created. It is then written to disk. Using the right ARROW key, select the WRITE option, and then press Enter. This will directly write the newly created distribution to disk.

Using MKFS to create a file system

Sometimes you don't need a whole repartition, you just want to create a filesystem. You can use the MKFS command directly at the terminal to implement it.

First, find the disk you want to use. In the terminal input lsblk find out. It will print out the list, and then just find the partition or letter that you want to create the file system.

In this example, I will use the/dev/sdb1 of the second hard disk as the first partition. You can use MKFS for/DEV/SDB (this will use the entire partition).

To create a new file system on a specific partition, simply type

Copy Code

The code is as follows:

sudo mkfs.ext4/dev/sdb1

At the terminal. It should be noted that MKFS.EXT4 can be replaced with any file system you want to use.

PS: Adjust partitions using GParted

The easiest way to adjust partitions in Linux is to use the GUI GParted program. Although you can run GParted from your regular Linux installation, it refuses to operate on any of the currently mounted partitions. Therefore, you cannot adjust the root directory (/) or other partitions that are critical to operating system functionality. Here I will describe how to implement your changes using a Linux emergency boot disk. After the disk is booted, you can run GParted, just as you would run from a regular system, using a point-and-click operation to tell the software what you want to do. Let's install the software first. Type gparted directly under the terminal and get prompted to enter sudo apt-get install gparted, dots, from the network download complete.

1. Run an emergency disk

There are now a number of Linux emergency disks (emergency discs), such as Partedmagic and SYSTEMRESCUECD (see Resources). You can also use your Linux installation media, and many versions include a rescue mode (rescue mode) that supports access to GParted or similar utilities. To illustrate the issue, I will introduce the use of partedmagic 4.11, but generally speaking, other tools are similar. However, you need to start GParted in a different way.

Most emergency disks come in the form of x86 (32-bit), but these disks work well in x86-64 (64-bit) computers, even if the system runs 64-bit versions of Linux. File system data structures are not affected by the central processing unit (CPU) architecture. If you want to run on another machine, in addition to the standard personal computer (PC), such as the Macintosh, you need to check that your emergency disk can work with your hardware.

In general, you must boot an emergency disk as if you were booting a Linux installation disk. On some systems, insert the disk and then reboot the computer to perform the task. On some systems, you must press a function key to select a boot device, or adjust a basic input/output system (BIOS) option to boot from the CD drive without booting from the hard drive. The specifics of how to do this are based on the system, and you need to consult the man page for more information.

When you boot Partedmagic, a boot menu appears. Select Default settings (ns from RAM) to boot to the standard system. When the system boots, you can see a desktop that contains icons for commonly used tools, including a Partition Editor that starts GParted. Double-click the icon to start resizing your partition.

2. Tell GParted about your changes

To resize a partition, right-click it, and choose Resize/move from the Drop-down menu. The result is a dialog box that appears as shown in the picture. You can use the Graphics slider or text input fields to resize and position the partitions.

Move the start point to the right to make room for the/DEV/SDB5 extension.

You also want to move the swap partition (/DEV/SDB6) to the right before resizing the/DEV/SDB5 size. Alternatively, you can delete and recreate the swap partition, however, this may require modifying the space in the/etc/fstab by using the UUID primer, and you can extend the/DEV/SDB5 after the swap space is moved.

If you want to make room for the primary partition from a logical partition, you must explicitly adjust the extended partition around the logical partition, and vice versa. You can do this as you would any other partition, but you will find it easier to click on a list entry than to click on a chart in the above partition list.

GParted does not allow you to adjust the partition you are using. For example, there is a lock icon next to the entry in the partition. You can right-click the partition and choose Unmount to uninstall it. Note If any one of the partitions included in the extended partition (including swap space) is in use, it is locked in this way.

3. Implement your changes in GParted

After you notify GParted of your changes, you must implement it by selecting the Edit > Apply all Operations menu item or by clicking the Apply icon. The result is a progress dialog box that outlines everything that the program is doing. If you decide to undo, you can either use the Undo feature of GParted or exit the program directly without applying your changes, then your disk will not change.

Zoning tuning takes time to complete, ranging from one second to several hours, depending on the nature of the change and how much data is moved. You cannot interrupt a running operation under any circumstances! If you do this will destroy the file system, causing the data to be unrecoverable.

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.