Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create Partition and File system in Linux

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to create partitions and file systems in Linux. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Create a basic Linux partition using CFdisk

Here is the right way to create a basic Linux partition on the command line. The first thing to do is to open your terminal first. If you have opened it, you need to find the disk on which you want to create the partition. This can be found using a simple command.

The code is as follows:

Lsblk

When you run lsblk, you should see a detailed list of each disk on the current system. Look at this list and find out which disk you want to use. In this article, I will use sdb to demonstrate.

Enter this command on the terminal. It will show a powerful terminal-based partition editor.

The code is as follows:

Sudo cfdisk / dev/sdb

Note: replace sdb with the disk you want to use in the output of the lsblk command.

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

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

First, you need to create a root partition. This needs to be split according to the number of bytes on the disk. The disk I tested was 32 GB.

In CFdisk, use the arrow keys on the keyboard to select the space that needs to be allocated. When you find it, use the arrow keys to select [NEW], and then press Enter.

The program will ask you to enter the partition size. Once you have specified the size, press Enter. This will be called the root partition (or / dev/sdb1).

Next it's time to create the home partition (/ dev/sdb2). You need to select some more 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 a swap partition. As with the previous two times, find some free partitions and use the arrows to select the [NEW] option. After that, calculate the size of the swap partition you want to use for Linux.

Note: the swap partition is usually about the same size as the computer's memory.

Now that you have created the swap partition, you should specify its type. Use the up and down arrows to select it. After that, use the left and right arrows to select [TYPE]. Locate the Linux swap option and press Enter.

After all partitions are created. Then write it to disk. Use the right arrow key, select the [WRITE] option, and then press Enter. This writes the newly created distribution directly to disk.

Create a file system using mkfs

Sometimes you don't need an entire repartition, you just want to create a file system. You can use the mkfs command directly in the terminal to achieve this.

First, find out which disk you want to use. Type lsblk in the terminal to find out. It will print out a list, and then just find the partition or drive letter you want to create the file system.

In this example, I will use the / dev/sdb1 of the second hard drive 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

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: adjusting 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 currently mounted partition. Therefore, you cannot adjust the root directory (/) or other partitions that are critical to the functionality of the operating system. Here I'll show you how to use an Linux emergency boot disk to implement your changes. After the disk is booted, you can run GParted, just as you would from a regular system, using point-and-click operations to tell the software what you want to do. Install the software first. Type gparted directly under the terminal, get a prompt to enter sudo apt-get install gparted, follow suit, and download it from the network.

1. Run an emergency disk

There are many 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, I will introduce the use of PartedMagic 4.11; however, other tools are similar in general terms. 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 on x86-64 (64-bit) computers, even if the system is running a 64-bit version of Linux. The file system data structure is not affected by the central processing unit (CPU) architecture. If you want to run on other machines, other than standard personal computers (PC), such as Macintosh, you need to check that your emergency disk works with your hardware.

In general, you must boot an emergency disk, just as you boot a Linux installation disk. On some systems, insert the disk and reboot the computer to perform the task. On some systems, you must press a function key to select the boot device, or adjust a basic input / output system (BIOS) option to boot from the CD drive instead of the hard drive. The details of how to do this depend on the system, and you need to refer to 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 with icons for common tools, including a Partition Editor that starts GParted. Double-click the icon to start resizing your partition.

two。 Inform GParted of your changes

To adjust a partition, right-click it and select Resize/Move from the drop-down menu. The result is the dialog box shown in the figure. You can use the graphics slider or the text input field to resize and position the partition.

Move its starting point to the right to make room for the extension of / dev/sdb5.

You also need to move the swap partition (/ dev/sdb6) to the right before resizing / dev/sdb5. Alternatively, you can delete and recreate the swap partition; however, this may require modifying the UUID reference to swap the space in / etc/fstab, and when the swap space is moved, you can extend / dev/sdb5.

If you want to make room for the primary partition from the 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; however, you will find it easier to click on its list entries than to click on the entries in the chart of the partition list above.

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

3. Implement your changes in GParted

After you notify GParted of your change, you must implement it by selecting the Edit > Apply All Operations menu item or clicking the Apply icon. The result is a progress dialog that outlines everything the program is executing. If you decide to undo the operation, you can use GParted's undo feature or exit from the program without applying your changes, and there will be no change to your disk.

Partition adjustment operations take a certain amount of time to complete, ranging from one second to several hours, depending on the nature of the change and how much data is moved. Under no circumstances can you interrupt a running operation! Doing so will destroy the file system and make the data unrecoverable.

After reading the above, do you have any further understanding of how to create partitions and file systems in Linux? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report