How to install arch Linux on USB flash disk

Time:2020-11-27

Introduction to arch Linux
Arch Linux (or arch) is a kind of Linux distribution designed with light weight and simplicity. Its development team adheres to the design principles of simplicity, elegance, correctness and code minimization. The arch Linux project, inspired by crux, was launched by Judd Vinet in 2002.
Arch Linux is a GNU / Linux distribution originated from Canada, which is committed to simple use, lightweight system and fast software update. Founder Judd Vinet was founded out of dissatisfaction with Debian and red hat’s package manager, as well as influenced by crux. Originally for i686, but now for x86_ 64 is also well supported, and has derived arch Linux arm for arm platform and arch Hurd for Hurd kernel (slow development).
Arch Linux defines conciseness as avoiding any unnecessary addition, modification and complexity. It provides software that comes from the original developer (upstream) with minimal modifications related to the release (downstream).
Do not include patches that the upstream does not want to accept. Most of the downstream patches of arch have been accepted upstream and will be included in the next official release.
Configuration files also come from upstream and contain only necessary adjustments to the distribution, such as special file system path changes. Arch does not start the service automatically after installing a package.
Software packages usually correspond directly to an upstream project. Packages are split only in rare cases.
Arch tries its best to keep the software in the latest stable version, and uses the latest version as long as the system software package is not damaged. Arch adopts the rolling upgrade strategy, which can be upgraded continuously after installation without re installation. With just one command, arch keeps up to date.
Arch provides GNU / Linux users with many new features, including SYSTEMd initialization system, modern file system (ext2 / 3 / 4, Reiser, XFS, JFS, Btrfs), lvm2 / EVMS, software disk array (soft RAID), udev support, initcpio (with mkinitcpio), and the latest internal core.

Basic system installation
I want to use the GPT partition table and check some information. In order to make this USB flash disk work on both BIOS and UEFI computers, it is necessary to create a BIOS boot partition with 2m size and the position as far as possible. For multiple systems, a 200m EFI system partition (ESP) partition should be created. These are not problems, but actually, the NTFS partition in GPT is not recognized under win7. If you want to use this partition as a regular U disk, you have to go back to the MBR partition table. If it is a mobile hard disk, there should be no problem with GPT.

Therefore, MBR partition is still used, so fdisk or cfdisk will be used instead of gdisk and cgdisk which support GPT. 4K alignment is also automatically completed. Interestingly, if you want to convert a GPT partition table to an MBR partition table, you have to use gdisk: R to enter recovery mode, G to MBR mode, and w to convert. According to the actual situation, some partition conversion may not succeed, but it is no problem to change back to MBR partition table.

NTFS partition must be in the first partition, otherwise windows will not recognize it.

The boot U disk is / dev / SDB, and the target U disk is / dev / SDC.

Copy code

The code is as follows:

# fdisk /dev/sdb

Disk /dev/sdc: 8022 MB, 8022982656 bytes, 15669888 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 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 83 Linux
/dev/sdb3 2009088 10405887 4198400 83 Linux
/dev/sdb4 10405888 15669887 2632000 83 Linux

NTFS is used for the first partition. When the USB flash disk is used normally, if you need to use the ESP partition in the future, you can use this partition to transfer or cut a part of the space. The second partition is 100m, hanging / boot; the third partition is 4G as the root partition of archlinux; the fourth partition is 2.5G as $home;

Format partition:

If you use XFS partition format:

Copy code

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 can reduce IO consumption at the cost of CPU consumption, which is obviously not a problem for modern computers. -The L size = 128M parameter expands the log capacity (10 m by default), which is more secure at the cost of longer mount time. -The parameter l lazy count = 1 reduces the number of super block reads and writes and improves performance.

If you use ext4 partition format:

Copy code

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

-B 4096 is the size of each memory block. -M 1 specifies that the root reserved space is 1%, and the home area is not reserved. -I 16384 specifies how many bytes of data to set an inode node. Increasing its value will reduce the total number of inodes, occupy less space, and correspondingly reduce the number of files that can be stored. It is good to pay a little attention to this, which is generally enough. -O ‘^has_ Journal ‘is to turn off the file system log, which is a little dangerous.

After two days of tossing, I feel ext4 read and write faster on the U disk.

Mount partition:

Copy code

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:

Copy code

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’s change of bytes per inode does have a great impact on the space occupied by partitions.

Install basic system

Home has wireless routing, the network does not need to be configured, has been automatically connected.

Edit / etc / pacman.d/mirrorlist to move the fastest source to the top. Generally speaking, 163 and Taiwan’s sources are relatively fast. 163 seems to be unstable sometimes. Some of the sources of several Chinese universities are IPv6 and can’t be used. After the installation, the configuration file will be automatically copied to the new system. The VI that comes with is really much more difficult to use than vim. It will be changed for the first time in a while.

According to the instructions on the official website, install the basic system with ා pacstrap / MNT base base base devel, and also install base devel. Sooner or later, AUR or ABS will be used. There are 128 software packages in total, 158.37m content needs to be downloaded, and 507.09m after installation.

install

Copy code

The code is as follows:

grub: # arch-chroot /mnt pacman -S grub

generate

Copy code

The code is as follows:

fstab: # genfstab -p -U /mnt >> /mnt/etc/fstab

, and then change fstab (the system default is generally better, and it’s OK to not optimize it)

Use relative to mount the parameters.

Previously, it was recommended to add the noatime mount parameter without recording the file read time. However, this will cause errors in software that requires file reading time, such as mutt. Now the relative parameter is used instead (it has been added by default, and has become the default value since Linux 2.6.30). Only when the file read time is earlier than the file update time, the read time data will be updated.

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

Put / TMP on TMPFS. (no separate partition, no need)

The discard mount parameter is no longer used.

This parameter is mainly used for SSD hard disk, which is invalid for mechanical hard disk which does not support trim, and seems to have no obvious effect on U disk.

The async mount parameter is no longer used, and the asynchronous read-write mode is enabled. Due to the fact that “the speed of writing” is not considered, should not the stability of the data be improved?

Do not use the barrier = 0 mount parameter. This option seems to have a chance to lose files or damage partitions when you suddenly power off or unplug the USB flash disk. (based on my experience + reference)

In order to reduce the usage frequency of swap, modify / MNT / etc/ sysctl.conf :

Copy code

The code is as follows:

vm.swappiness = 1
vm.vfs_cache_pressure = 50

Try not to use swap as much as possible. The last sentence is to cache file system information.

The following operations can be run in chroot environment:

Copy code

The code is as follows:

# arch-chroot /mnt

Set the host name: echo ‘F004’ > / etc / host name.

Set time zone:

Copy code

The code is as follows:

# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

New / etc/ locale.conf The contents are as follows:

Copy code

The code is as follows:

LANG=’en_US.UTF-8′
LC_COLLATE=’C’

LC_MESSAGES=’C’
Edit / etc/ locale.gen , cancel en_ US.UTF -8, zh_ CN.UTF -8, zh_ TW.UTF -8, and then execute the locale Gen command.

Change the root password: passwd root.

Install grub boot system.

Still operating in the chroot environment. Edit / etc/ mkinitcpio.conf , check the homes section, make the block parameter immediately after udev parameter (load earlier), and then generate img file by mkinitcpio – P Linux. At the same time, the shutdown parameter is added. Try again later. Even if the resume parameter is ignored, the USB flash disk is small and slow, and it is more painful to support hibernation. (Note: in the new version, the block parameter replaces many parameters such as USB PATA SATA SCSI)

To install grub:

Copy code

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

Both 32-bit and 64 bit systems use the — target = i386 PC parameter, and – no floppy does not check the floppy drive (this device should not be used by now). I don’t know what I’m doing.

Don’t forget to generate grub.cfg Document:

Copy code

The code is as follows:

# grub-mkconfig -o /boot/grub/grub.cfg
# grep ‘set=root’ /boot/grub/grub.cfg
# blkid /dev/sdc2

Now Grub2 uses UUID to find the hard disk partition grub.cfg Whether the UUID of the partition used matches the hard disk. If you forget to generate grub.cfg You can use the CD to boot it again.

Finally, exit chroot, umount and restart. The USB flash drive can be started up.

After startup, the newly installed U disk becomes / dev / SDB. At this time, it is best to redo mkinitcpio grub install grub mkconfig again. Otherwise, the partition table may be damaged and files will be lost during the next boot or on another machine. Maybe it doesn’t make sense, but this is my feeling after repeated installation for many times. There may be the following reasons:

Live plug, but I am umount, should not be so vulnerable.
USB 3.0 high current to destroy, did not pull out the U disk burned, I am lucky? I’ve heard that USB 3.0 damages the data of USB flash disk.
/Boot did not have a separate partition. This should not be.
Is the original use of GPT partition in BIOS computer acclimatized? Can’t U disk be partitioned with GPT?
Anyway, after switching back to the MBR partition, it seems to be more normal.