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

How to install Arch Linux on USB flash drive

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "how to install Arch Linux on a U disk". In daily operation, I believe many people have doubts about how to install Arch Linux on a U disk. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to install Arch Linux on a U disk". Next, please follow the editor to study!

Introduction to Arch Linux

Arch Linux (or Arch) is a Linux distribution with a lightweight and concise design philosophy. Its development team adheres to the design tenet 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 that originated in Canada and is dedicated to simple use, lightweight system and fast software updates. Founder Judd Vinet was founded out of dissatisfaction with Debian and Red Hat's package manager, and was influenced by CRUX. It was originally targeted at i686, but now it also supports x86 desktop 64 well, and Arch Linux ARM for the ARM platform and Arch Hurd for the HURD kernel (slow growth) have been derived.

Arch Linux defines simplicity as avoiding any unnecessary additions, modifications, and complex additions. The software it provides comes from the original developer (upstream) with only minimal modifications related to the release (downstream).

Does not contain patches that the upstream is unwilling to accept. Most of the Arch downstream patches have been accepted upstream and will be included in the next official release.

The configuration file also comes from upstream and contains only the necessary adjustments for the release, such as special file system path changes. Arch does not automatically start the service after a package is installed.

Software packages usually correspond directly to an upstream project. The package is split only in rare cases.

Arch does its best to keep the software up-to-date and stable, using the latest version as long as there is no damage to the system package. Arch uses a rolling upgrade strategy, which can be upgraded continuously after installation without the need for reinstallation. Arch can be kept up-to-date with just one command.

Arch provides many new features to GNU/Linux users, including the systemd initialization system, modern file systems (Ext2/3/4, Reiser, XFS, JFS, BTRFS), LVM2/EVMS, software disk array (soft RAID), udev support, initcpio (with mkinitcpio), and the latest kernel.

Basic system installation

I wanted to use the GPT partition table and checked some information. in order to make this U disk work on both BIOS and UEFI computers, we need to create a BIOS boot partition with 2m size and a position as far as possible. For multiple systems, create a 200m EFI System Partition (ESP) partition. These are not problems, but in practice, 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 removable hard disk, there should be no problem with GPT.

So you still use MBR partitions, so you have to use fdisk or cfdisk, you can't use gdisk and cgdisk that support GPT, and 4k alignment is done automatically. Interestingly, if you want to convert a GPT partition table into an MBR partition table, you also have to enter Recovery mode with gdisk:r, g into MBR mode, and w for conversion. Depending on the actual situation, some partition conversions may not be successful, but there is no problem changing back to the MBR partition table.

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

Boot the flash drive to / dev/sdb, and the target flash drive becomes / dev/sdc.

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 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

The first partition first uses ntfs, when the normal USB disk is used, if you need to use the ESP partition in the future, use this partition directly, or cut part of the space. The second partition 100m, hang / boot; the third partition 4G as the ArchLinux root partition, and the fourth partition 2.5G as $HOME

Format the partition:

If you use the xfs partition format:

The code is as follows:

# mkfs.ntfs-f / dev/sdc1-L f004murc

# 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 f004mura

# mkfs.xfs-n size=64k-l size=128m,lazy-count=1 / dev/sdc4-L f004murb

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

If you use the ext4 partition format:

The code is as follows:

# mkfs.ntfs-f / dev/sdc1-L f004murc

# mkfs.ext4-b 4096-m 0-I 16384-O'^ has_journal' / dev/sdc2-L f004-boot

# mkfs.ext4-b 4096-M1-I 16384-O'^ has_journal' / dev/sdc3-L f004mura

# mkfs.ext4-b 4096-m 0-I 16384-O'^ has_journal' / dev/sdc4-L f004murb

-b 4096 is the size of each storage block. -m 1 specifies that 1% of the root reserved space is not reserved in the home area. -I 16384 is a specified number of bytes of data to set up an inode node, increasing its value will reduce the total number of inode, occupy less space, and correspondingly reduce the number of files that can be stored. -O'^ has_journal' is to turn off the file system log, which is a little dangerous.

After two days of twists and turns, I feel that ext4 reads and writes faster on USB flash drives.

Mount the 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:

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 changing the bytes-per-inode does have a big impact on the space occupied by the partition.

Install the basic system

There is no line at home, the network does not need to be configured, has been automatically connected.

Edit / etc/pacman.d/mirrorlist, move the fastest source to the top. Generally speaking, 163s and Taiwan's sources are relatively fast, 163s seem to be unstable sometimes, and some of the sources of several Chinese universities are ipv6 and cannot be used. After the installation is complete, this configuration file will also be automatically copied to the new system. The built-in vi is really much more difficult to use than vim. It will be replaced as soon as possible.

According to the instructions on the official website, install the basic system with # pacstrap / mnt base base-devel and install base-devel, which will use AUR or ABS sooner or later. Tips a total of 128 software packages, need to download 158.37m content, after the installation is 507.09m.

Installation

The code is as follows:

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

.

Generate

The code is as follows:

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

And then change the fstab (the system default is generally better, or you don't have to optimize it):

Use relatime mount parameters.

In the past, it is recommended to add the noatime mount parameter, which does not record the file read time, but this will lead to errors in software such as Mutt that need file read time. Now the relatime parameter has been used instead (it has been added by default, which has been the default since Linux 2.6.30), and the read time data is updated only when the file read time is earlier than the file update time.

Use the nodiratime mount parameter and do not record the directory read access time.

Put / tmp on tmpfs. (no separate partition, no need)

Discard mount parameters are no longer used.

This parameter is mainly for SSD hard disk, not for mechanical hard disk that does not support TRIM, and seems to have no obvious effect on U disk.

Instead of using the async mount parameter, turn on asynchronous read-write mode. Since it just "looks" fast and the actual data writing speed has not improved, should this parameter be used for stability?

Do not use the barrier=0 mount parameter, which seems to have the chance of losing files or corrupting partitions when power is suddenly cut off or USB drives are unplugged. (based on my experience + reference)

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

The code is as follows:

Vm.swappiness = 1

Vm.vfs_cache_pressure = 50

The first sentence is to try not to use swap, and the second sentence is to cache file system information.

The following operations can be run in a chroot environment:

The code is as follows:

# arch-chroot / mnt

Set up hostname: echo 'f004' > / etc/hostname.

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, uncomment before 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 the Grub boot system.

Still operating in the chroot environment. Edit / etc/mkinitcpio.conf, check the HOOKS section, make the block parameter immediately after the udev parameter (loaded earlier), and then # mkinitcpio-p linux generates the img file. At the same time, the shutdown parameter is added, and try again after the function. Forget the resume parameter, the USB disk is already small and slow, and it is more painful to support hibernation. (note: the block parameter replaces many parameters such as usb pata sata scsi in the new version)

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

Both 32-bit and 64-bit systems use the-- target=i386-pc parameter,-- no-floppy does not check the floppy drive (this should not be used by anyone now). It's okay if you don't execute the last two sentences. I don't know what to do yet.

Then, don't 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

Today's Grub2 uses UUID to find the hard disk partition, and the last two sentences are to check whether the partition UUID used by the newly generated grub.cfg matches the hard drive. If you forget to generate grub.cfg, you can boot it into the CD again.

Finally, exit the chroot environment, umount, and restart. Start the flash drive and put it away.

After booting, the newly installed USB drive becomes / dev/sdb, so it's best to do mkinitcpio grub-install grub-mkconfig again at this time, otherwise you may damage the partition table and lose files the next time you boot or on another machine. It may not make sense, but this is how I feel after installing it many times, possibly for the following reasons:

Live plug and unplug, but I am umount ah, should not be so fragile.

It was destroyed by the high current of USB 3.0. am I lucky that I didn't pull the flash drive and burn it? I've heard of USB 3.0 corrupting USB disk data.

/ boot didn't have a separate partition before, so this shouldn't be.

Is the original use of GPT partition on the BIOS computer is not satisfied? Can't USB drives be partitioned with GPT?

Anyway, after switching back to the MBR partition, it seems to be quite normal.

At this point, the study on "how to install Arch Linux on a USB disk" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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