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

Implementation of Linux disk mounting, Partition and capacity expansion Operation

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Basic concept

Before you operate, you should first understand some basic concepts.

Magnetic disk

In the Linux system, all devices are stored as files. Devices are generally stored in the / dev directory, with sda, sda1, sda2... , sdb, sdb1... , hda,hdb . Today's devices are generally named after sd, while the old hard drives are named after ha.

Sda: the first hard disk, if the disk is partitioned, there will be sda1 (the first partition), sda2, etc.

Sdb: the second hard disk, there is also sdb1,sdb2 after partitioning the hard disk.

Zoning

The purpose of partition is to facilitate management, for example, in the Windows system we usually divide into C disk, D disk, E disk and so on.

Linux can only create four primary partitions, and if you need to create more partitions for that long, you must create logical partitions, where logical partitions need to occupy one primary partition.

File system

The file system in Linux is the partition type, and there are NTEF,FAT32 in Windows, and Ext2, Ext3, Ext4, Linux swap, proc, sysfs, tmpfs and so on are common in linux. You can view the currently mounted file system through mount naming.

Formatting

After creating the partition, one step is to format the partition. In fact, it is the same in the Windows system. After creating a partition, you also need to format the partition, which can only be formatted into a specific file type.

Mounting

The partition can be used after the partition is formatted in Windows, but in the Linux system, the partition must be mounted to a specific path.

Common command

Lsblk to view the current disk situation

Df-lh view file system-l view mount point

Parted-l lists file system types

Fdisk-l View the currently unmounted hard disk

Mount a new hard drive

The basic idea of mounting a new hard disk is to create a partition, create a file system, and mount it.

First, check the new hard drive

First, check the status of the hard drive:

Fdisk-l

Where:

If there is something similar under the disk: Disk / dev/sdc doesn't contain a valid partition table; or there is nothing like: sdb1 sdb2 indicates that the disk is not mounted

Suppose you see the hard drive named / dev/sdb

Second, create a partition

Dfisk / dev/sdb

According to the prompt, enter "n", "p"1", enter twice, and "wq"

It means to create a new primary partition (1), the size of which is the entire sdb disk, and then write.

Note: for simplicity, just create a primary partition. In fact, a disk can have at most four primary partitions (including an extended partition), and 1-4 are all primary partitions. We can also use one partition as an extended partition (the system found through df-lh is Extended).

At this point, the disk is partitioned, but there is no file system, and the disk is still unavailable.

III. Writing system

Mkfs.ext4 / dev/sdb

This command formats the disk and writes to the file system

IV. Mounting

For example, mount to / data

Mkdir / data # omit mount / dev/sdb / data if this step exists

5. Set up automatic mount on boot.

The above is only temporary mount, and it needs to be set to boot and mount automatically.

Vim / etc/fstab# then add a line at the end of the content (note that the file type corresponds to it): / dev/sdb / data ext4 defaults 0 0

Expand capacity

About mounting to an existing directory

If the directory you want to mount is not empty, the contents in the original directory will disappear temporarily after the file system is mounted. It is not overwritten, but temporarily hidden, and when the new partition slot is removed, the original contents of the original directory will come out again.

If you want to mount an existing directory permanently, you can mount it to a temporary directory after the file system is created on the new hard disk, then copy the directory to be extended to the temporary directory, then delete the directory to be extended, unmount the temporary mount point, and remount to the directory to be extended. For example:

# for example, to expand / var#, create a new temporary mount point storagemkdir / storage# after the file system is created. Mount / dev/sdb1 to / storage all the contents under mount / dev/sdb1 / storage# copy / var to the new hard disk cp-pdr / var / storage# or execute under / var directory: find. -depth-print | cpio-pldvm / temp# deletes the contents in the current / var directory rm-rf / var/*# and remounts the hard disk to the / var directory umount / dev/sdb1mount / dev/sdb1 / var#. If you are prompted that the disk is busy, use fuser to find out the program that will be using the disk and end it; fuser-m-v / varfuser-m-v-I-k / var

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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