Linux tips: Step-by-Step partitioning

Source: Internet
Author: User
Article Title: Linux tips: Step-by-Step partitioning operations. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In this new tip set, Daniel Robbins explains how to change the partition layout on a running system. He also introduced several tips to minimize the downtime and avoid serious errors. In this article, he will explain how to move/home to another partition.
  
/Home is one of the most moving partitions. In some cases, all space in/home is used up, and a hard drive needs to be added. In other cases,/home is set as part of the root partition. To improve performance or facilitate backup, you may need to move it elsewhere. I will describe how to move/home safely and effectively in each case.
  
Warning
The following Technique describes how to move one or more partitions. Although the design of this technology enables you to "undo" failed partition movement, it does not prevent user errors. In other words, as long as you format a partition or copy a large number of files, a large amount of data may be damaged due to incorrect input. Therefore, it is strongly recommended that you take appropriate measures to back up all important files before proceeding.
  
Now you are ready to move/home. The exact steps you want to complete depend on whether/home is currently residing in its own separate partition or on the Root partition. Note this when we complete the following steps (I will remind you if necessary ). If you are moving/home to a new hard drive, the drive should now be physically installed in your system.
  
   1. Create a New partition if necessary
If you are moving/home to an existing partition (there is no need to be an ext2 file system, as long as the target primary partition or extended partition exists, you can directly go to step 2.
  
If the new partition does not exist, use cfdisk (preferred) or fdisk to create a new partition. If this partition is not on the first drive, do not forget to specify the device name as the first parameter of cfdisk or fdisk. After creating an appropriate primary partition or extended partition, restart the system to read the Partition Table correctly. This is the only time to restart the system.
  
   2. Create a file system on the new partition
To create a file system in a new partition, you must first know the accurate device name of the new partition (for example,/dev/sda5 ). If you cannot determine the exact device name, stop immediately and check the device name carefully. Then, enter the following command as root:
  
# Mkfs. ext2/dev /???
  
In the sample code above and later, replace ??? with the target partition name ???. After executing this command, the target partition will contain an empty ext2 file system.
  
   3. Mount the new file system under/mnt
Create a directory named/mnt/newpart and mount the new partition to this directory:
  
# Mount/dev /??? /Mnt/newpart
  
   4. Enter the single-user mode
To maximize the availability of the system, I try to postpone this step, but now we have to enter single-user mode and then copy the files in/home to/mnt/newpart. You should not open any file in/home, but enter single-user mode to eliminate this possibility:
  
# Init 1
  
If a prompt is displayed, enter the root password to execute the system maintenance task. You should be in root shell now.
  
   5. Change the current directory to/home and copy the file.
Type the following command:
  
# Cd/home
# Cp-ax */mnt/newpart
  
The cp-ax command cyclically copies the content in/home to/mnt/newpart, retains all file attributes, and does not cross any mount points. After the command is executed,/mnt/newpart will include the exact copies of all files and directories currently contained in/home. If the original/home is in its own partition (listed in a separate row in/etc/fstab), go to step 6a. Otherwise, go to step 6b.
  
   6a. Use a new partition (when the original/home is a partition)
The following description applies to the system where the original/home already exists in its own dedicated partition. If this is not the case, see step 6b.
  
Run the following command to uninstall the original partition:
  
# Cd/
# Umount/home
  
Then, Unmount and re-mount the new partition:
  
# Umount/mnt/newpart
# Mount/dev /??? /Home
  
Now you can access the new partition through/home and make it ready for use immediately. We can perform the last few steps in multi-user mode. Press the CTRL-D to exit single user mode so that the system returns to startup running.
  
Important: After the system is started normally, Log On As root and edit/etc/fstab to enable/dev /??? Instead of attaching the original partition to the mount point. For example, set the following line:
  
/Dev/hda3/home ext2 defaults 1 2
  
Changed:
  
/Dev /??? /Home ext2 defaults 1 2
  
   6b. Use the new partition (when the original/home is not a partition)
If/home is not in its own separate partition (for example, if/home is only a directory in the root partition), follow the instructions below. Run the following command:
  
# Cd/
# Mv/home. old
# Mkdir/home
# Mount/dev /??? /Home
  
Now, press CTRL-D to leave single user mode. After the system returns to the startup and running status, edit the/etc/fstab file and add a line similar to the following:
  
/Dev /??? /Home ext2 defaults 1 2
  
In this way, when you restart the system next time, your new partition will be correctly mounted.
  
   7. Tail Scanning
We deliberately keep the original/home directory/partition to prevent problems when copying files. After confirming that the system runs stably, you can use the original/home partition for other purposes, or delete the original/home directory.
Related Article

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.