Upgrading the hard disk of a Linux system

Upgrading the hard disk of the Linux system
Author : Brother Lianguo
The application on the Linux platform is increasing, which leads to the shortage of hard disk space. Upgrading the hard disk of the Linux system has become the most necessary knowledge.
There are two ways to add a hard disk to Linux: one is to add a hard disk to store data, and the original system hard disk remains unchanged; the other is to replace the original system with a new hard disk, that is, to replace the original system hard disk. This article will describe them separately.
Adding a new data disk for Linux
Because Linux accesses a hard disk differently from DOS, it uses an installable directory method, so adding a hard disk is a little different from the usual method under DOS/Windows, which is divided into 5 steps.
1. Physical installation: Turn off the power, jumper the hard drive, and install a new hard drive. This step is very simple and will not be discussed further. After the boot, the BIOS can recognize the dual hard disks, which means success. Depending on the jumper method, the device name corresponding to the hard disk is also different (as shown in the following table, taking IDE hard disk as an example):

No.
Cable and jumper position
Device name
1
Master disk of ide0
/dev/had
2
Slave disk of ide0
/ dev/hdb
3
ide1's master disk
/dev/hdc
4
ide1's slave disk
/dev/hdd

2. Partition the hard disk: because it is used as a data disk, it can be divided into one area. Log in to the system as user root, and use fdisk /dev/hdb (hereafter, /dev/hdb is used as an example) to enter the fdisk operation interface. The common commands of fdisk are: delete partition: d; add partition: n; save and exit: w; activate partition: a; ​​display partition: p; change partition type: t; display help information: m.

3. Install the file system: Since Linux uses the ext2 file system, the new hard disk needs to install the ext2 file system. Enter the following command: mkfs.ext2 /dev/hdb.

4. Create a mount point: Create a mount point in the root directory, and the new data disk will be installed in this directory in the future (take the data directory as an example):

mkdir /data
mount -t ext2 /dev/hdb1 /data

5. Modify /etc/fstab file to automatically mount filesystems at boot.

Through the above manual installation, the new hard disk (that is, the /data subdirectory) can be used. Enter the command df to see the information of all the installed file systems. However, we will also modify /etc/fstab so that this new hard disk is automatically mounted every time the computer is restarted. Open this file with vi and modify it. The first column of the /etc/fstab file is the device location, the second column is the mount point, and the other columns can be copied.

At this point, you are ready to use the new hard drive.

Upgrading the original system disk
with a new hard disk, the main problem is how to copy the data. And the settings of the swap partition should be taken into account when partitioning the hard disk.
1. Shut down and install the hard disk.

2. Partition the hard disk. When partitioning, refer to the original partition first, and the requirement is not less than the original partition setting. It should be noted that the newly created partitions of fdisk are all Linux native. If you change it to Linux swap format, you must first enter the command t, and then enter the Linux swap number 82.

3. Create a mount point for the new hard disk, eg: /newdisk.

4. Install the new hard disk to the newly created mount point, such as:

mount -t ext2 /dev/hdb2 /newdisk

5. Create /tmp and /proc subdirectories on the new hard disk, and change the attribute of /tmp to 777 , commands such as: mkdir /newdisk/tmp; mkdir /newdisk/proc; chmod 777 /newdisk/tmp.

6. Enter single-user mode and copy the original data to the new hard disk.

· Enter single-user mode: /sbin/telinit 1
· Copy subdirectories: cp -a /var /bin /usr /sbin /boot /newdisk
· Copy files in the root directory: cp -dp /* /.* /newdisk

If The subdirectories of the computer are inconsistent with those listed above, please change them according to your own needs, but note that the last list listed is the installation point of the new hard disk.

7. Check if /newdisk/etc/fstab is suitable. It should be reminded that although the new hard disk is currently the second hard disk and the device name is /dev/hdb, it will become the first primary hard disk after the upgrade, so the one listed in /newdisk/etc/fstab should be the first primary hard disk s position.

8. Make a boot disk, then remove the old hard disk, jump the new hard disk into the main disk, and restart the computer. The command to make a boot disk is: makebootdisk.

9. After the computer restarts, run fdisk to set the partition of the hard disk to be active. And configure lilo to facilitate booting the system later. Under normal circumstances, if it is the same as the original system partition, just enter lilo and press Enter. Otherwise, you need to modify the /etc/lilo.conf file.

10. Take out the boot floppy disk, restart it, and check whether it can be booted from the hard disk. If it cannot be started, use a floppy disk to start and then check the reason. The possible reasons are: the partition is not activated, and the lilo configuration is incorrect. Check /etc/fstab if there is an error in mounting the filesystem during startup.

At this point, Linux on the new hard drive should be able to run normally.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486722&siteId=291194637