A specific tutorial on installing Arch Linux on a USB drive

Source: Internet
Author: User
Tags locale mkdir uuid arch linux
Introduction to Arch Linux

Arch Linux (or arch) is a Linux distribution with lightweight simplicity as its design concept. Its development team adheres to the design tenet of simplicity, elegance, correctness and code minimization. The Arch Linux project was inspired by CRUX and started by Judd Vinet in 2002.
Arch Linux is a gnu/linux release that originated in Canada and is dedicated to simple, lightweight, and fast software updates. Founder Judd Vinet was created by dissatisfaction with the package manager for Debian and Red Hat, and by Crux Impact. Initially targeted at i686, but now it's also good for x86_64, and it's also a derivative of the arch Linux arm for the arm platform and the arch Hurd for the Hurd kernel (slow development).
Arch Linux defines simplicity as: Avoid any unnecessary additions, modifications, and complex additions. It provides software from the original developer (upstream) and only minimal modifications related to the distribution (downstream).
Does not contain upstream unwilling to accept patches. Most of the Arch downstream patches have been accepted upstream and will be included in the next official version.
The configuration file is also from upstream and contains only the necessary adjustments to the distribution, such as special file system path changes. Arch does not automatically start the service after installing a package.
Packages usually correspond directly to an upstream project. The package is split only in rare cases.
Arch does its best to keep the software in the latest stable version, as long as the system software package is not damaged, try to use the latest version. Arch adopts the rolling upgrade strategy, which can be upgraded continuously after installation without reloading. With just one command, arch can keep up to date.
Arch offers many new features to Gnu/linux users, including SYSTEMD initialization systems, modern file systems (EXT2/3/4, Reiser, XFS, JFS, BTRFS), LVM2/EVMS, software disk arrays (soft RAID), Udev support, Initcpio (with Mkinitcpio) and the latest kernel.

Basic System Installation
Would like to use GPT partition table, check some information, in order to make this U disk in the BIOS and UEFI computer can be used, need to create a BIOS boot partition, 2M size enough, position as far as possible. Multiple systems also create a 200M EFI system Partition (ESP) partition. These are not the problem, but actually do it, GPT in the NTFS partition in the Win7, want to use this partition as a regular U disk use is not, had to go back to the MBR partition table. If you are moving a hard drive with GPT you should have no problem.

So you still use MBR partitions, so you'll need to use Fdisk or cfdisk, you can't use Gdisk and cgdisk that support GPT, and 4k alignment is automatically done. Interestingly, if you want to convert a GPT partition table into an MBR partition table, you have to use Gdisk:r to enter the Recovery mode, G into MBR mode, and W for conversion. Depending on the actual situation, some partitioning conversions may not be successful, but changing back to the MBR partition table is not a problem.

NTFS partitions are on the first partition, or Windows does not recognize them.

The launch U disk is/dev/sdb, the target u disk is/DEV/SDC.

The code is as follows:
# FDISK/DEV/SDB
disk/dev/sdc:8022 MB, 8022982656 bytes, 15669888 sectors
Units = sectors of 1 * the bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk label Type:dos
Disk identifier:0x00000000
Device Boot Start End Blocks Id System
/DEV/SDB1 2048 1804287 901120 7 Hpfs/ntfs/exfat
/DEV/SDB2 * 1804288 2009087 102400 Linux
/DEV/SDB3 2009088 10405887 4198400 Linux
/DEV/SDB4 10405888 15669887 2632000 Linux
First partition with NTFS, when the normal U disk use, if you need to use the ESP partition, directly with this partition, or cut a part of the space past. The second partition 100M, Hang/boot, third partition 4G, as ArchLinux root partition, fourth partition 2.5G, as $HOME;

Format partitions:

If you use the XFS partitioning format:

The code is as follows:
# mkfs.ntfs-f/dev/sdc1-l f004-c
# mkfs.xfs-n Size=64k-l lazy-count=1/dev/sdc2-l f004-boot
# mkfs.xfs-n Size=64k-l size=128m,lazy-count=1/dev/sdc3-l f004-a
# mkfs.xfs-n Size=64k-l size=128m,lazy-count=1/dev/sdc4-l f004-b
The-n size=64k parameter increases the file name (directory) area size (default 4k), which reduces IO consumption, at the cost of more CPU consumption, which is clearly not a problem for modern computers. The-l size=128m parameter expands the capacity of the log (default 10m), and is more secure, at the cost of a longer mount time. The-l lazy-count=1 parameter reduces superblock read and write times and improves performance.

If you use the EXT4 partition format:

The code is as follows:
# mkfs.ntfs-f/dev/sdc1-l f004-c
# mkfs.ext4-b 4096-m 0-i 16384-o ' ^has_journal '/dev/sdc2-l f004-boot
# mkfs.ext4-b 4096-m 1-i 16384-o ' ^has_journal '/dev/sdc3-l f004-a
# mkfs.ext4-b 4096-m 0-i 16384-o ' ^has_journal '/dev/sdc4-l f004-b
The-b 4096 is the size of each storage block. -M 1 is to specify that the root reserve space for the 1%,home area is not left. -I 16384 is to specify how many bytes of data set an Inode node, increase its value will reduce the total number of inode, occupy less space, the corresponding ability to store the number of files also reduced, this a little attention is good, generally enough. -O ' ^has_journal ' is a little dangerous to turn off file system logs.

After two days of tossing, personal feeling ext4 on the U disk to read and write faster.

Mount Partition:

The code is as follows:
# mount/dev/sdc3/mnt
# Mkdir/mnt/boot
# Mount/dev/sdc2/mnt/boot
# Mkdir/mnt/home
# Mount/dev/sdc4/mnt/home
Df-h, check it out.
The code is as follows:
# XFS
FileSystem Size Used Avail use% mounted on
/DEV/SDC3 3.9G 33M 3.9G 1%/mnt
/DEV/SDC2 82M 5.2M 77M 7%/mnt
/DEV/SDC4 2.4G 33M 2.4G 2%/mnt/home
# EXT4
FileSystem Size Used Avail use% mounted on
/DEV/SDC3 3.9G 8.1M 3.8G 1%/mnt
/DEV/SDC2 96M 48K 96M 1%/mnt
/DEV/SDC4 2.5G 3.8M 2.4G 1%/mnt/home
EXT4 Change Bytes-per-inode does have a significant impact on the space occupied by the partition.

Install the basic system

There is no line from the home, the network is not configured, has been automatically connected.

Edit the/etc/pacman.d/mirrorlist and move the fastest source to the top. Generally speaking, the source of 163 and Taiwan is relatively fast, 163 seems to be unstable at times, and some sources of Chinese universities are IPv6. Once the installation is complete, the configuration file is automatically copied to the new system. Since the vi is really more difficult than vim, a moment to replace the first time.

According to the official website instructions, with the # PACSTRAP/MNT base base-devel installation of the basic system, Base-devel also installed, sooner or later will be used to AUR or ABS. Tip A total of 128 packages, you need to download 158.37M content, installation is completed after 507.09M.

Installation

The code is as follows:
Grub: # arch-chroot/mnt Pacman-s Grub

Generated

The code is as follows:
Fstab: # genfstab-p-u/mnt >>/mnt/etc/fstab
, and then change the Fstab (system default is generally better, not optimized also line):

Use Relatime to mount parameters.

Previously, it was recommended to increase the Noatime mount parameters, not to record the file read time, but this would result in errors in software such as Mutt that require file read time. Now instead of using the Relatime parameter (which has been added by default, Linux 2.6.30 becomes the default), the read time data is updated only if the file read time is earlier than the file update time.

Use the Nodiratime mount parameter to not record the directory read access time.

Put the/tmp on the TMPFS. (No separate partitions, free)

Discard mount parameters are no longer used.

This parameter is mainly for SSD hard disk, to do not support the mechanical hard disk of TRIM is invalid, to U disk seemingly effect is not obvious.

The Async mount parameter is no longer used to turn on asynchronous read-write mode. Because it's just "looks" fast, the actual data write speed does not improve, considering the stability, should this parameter be used?

Do not use barrier=0 mount parameters, this option seems to be suddenly cut off, pull a U disk, there is a chance of losing files or damaged partitions. (Based on my experience + reference)

Because there is no big application to run, to reduce the frequency of swap, modify the/mnt/etc/sysctl.conf:

The code is as follows:
vm.swappiness = 1
Vm.vfs_cache_pressure = 50
The previous sentence is to try not to use swap, the latter is to cache file system information.

The following actions can be run in a chroot environment:

The code is as follows:
# arch-chroot/mnt
Set Hostname:echo ' f004 ' >/etc/hostname.

To set the time zone:

The code is as follows:
# ln-s/usr/share/zoneinfo/asia/shanghai/etc/localtime
The new/etc/locale.conf content is:
The code is as follows:
Lang= ' en_US. UTF-8 '
Lc_collate= ' C '
lc_messages= ' C '
Edit/etc/locale.gen and Cancel en_US. UTF-8, ZH_CN. UTF-8, ZH_TW. UTF-8 the previous comment, and then execute the locale-gen command.

Change root password: passwd root.

Install the Grub boot system.

Still operates in the chroot environment. Edit the/etc/mkinitcpio.conf, check the HOOKS segment, have the block parameter next to the Udev parameter (load earlier), and then # Mkinitcpio-p Linux to generate the img file. At the same time add the shutdown parameters, the role of the test later. Resume parameters on the forget, U disk is small, slow, support sleep more painful. (Note: The block parameter in the new version replaces USB PATA SATA SCSI and other parameters)

To install Grub:

The code is as follows:
# grub-install--target=i386-pc--recheck--boot-directory=/boot--NO-FLOPPY/DEV/SDC
# cp-v/USR/SHARE/GRUB/{UNICODE.PF2,ASCII.PF2}/boot/grub/
# cp-v/usr/share/locale/en\ @quot/lc_messages/grub.mo/boot/grub/locale/en.mo
Whether 32-bit or 64-bit systems are using the--TARGET=I386-PC parameter,--no-floppy does not check the floppy drive (this thing should not be used now). The latter two sentences do not carry out, still do not understand what is done.

Then, never forget to generate the Grub.cfg file:

The code is as follows:
# Grub-mkconfig-o/boot/grub/grub.cfg
# grep ' Set=root '/boot/grub/grub.cfg
# BLKID/DEV/SDC2
The GRUB2 now uses a UUID to find the hard disk partition, and the second sentence checks to see if the partition UUID used by the newly generated grub.cfg matches the hard drive. If you forget to generate GRUB.CFG, you can start it again with a CD.

Finally, exit the chroot environment, Umount, reboot. Start the USB drive can be closed.

Startup, the new installation of the U disk into a/dev/sdb, it is best to Mkinitcpio grub-install grub-mkconfig again, otherwise it is possible to start on the next or another machine, damaged partition table, lost files. It may not make sense, but this is how many times I have repeated the installation, there may be the following reasons:

Live plug, but I have been umount ah, should not be so fragile.
was damaged by USB 3.0 High Current, did not pull a U disk burn I am lucky? I have heard of USB 3.0 damage U disk data.
/boot originally did not have separate partitions, this should not.
Did you originally use GPT partitioning to acclimatized on your BIOS computer? Can't you use a GPT partition on a USB disk?
Anyway, after changing back to the MBR partition, looks more normal.

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.