Wake-on-LAN for Linux

My sons upgraded their gaming computers last Christmas, and I ended up using their old parts to build a couple of Linux servers running Ubuntu servers. The idea is to use these extra servers as video encoders since they will have dedicated GPUs. However, the GPUs are also pretty power-hungry. Since they don’t need to be up 24 hours a day, I thought keeping these servers asleep until they are required would be good. At the same time, it would be pretty inconvenient to go to the servers to physically power them up when I needed them. The thought of configuring their Wake-on-LAN came to mind.

I found this helpful article online. I first found out that the Network Interface on the old motherboards supports Wake-on-LAN (WOL). Below is a series of commands that I executed to find out whether WOL is supported or not, and if so, then enable the support.

% sudo nmcli connection show
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  d46c707a-307b-3cb2-8976-f127168f80e6  ethernet  enp2s0

% sudo ethtool enp2s0 | grep -i wake
	Supports Wake-on: pumbg
	Wake-on: d

The line that reads,

Supports Wake-on: pumbg

indicates the WOL capabilities, and the line that reads,

Wake-on: d

indicates its current status. Each letter has a meaning:

  • d (disabled), or
  • triggered by
    • p (PHY activity), 
    • u (unicast activity),
    • m (multicast activity),
    • b (broadcast activity), 
    • a (ARP activity),
    • g (magic packet activity)

We will use the magic packet method. Below are the commands used to enable WOL based on the magic packet trigger.

% sudo nmcli connection modify d46c707a-307b-3cb2-8976-f127168f80e6 802-3-ethernet.wake-on-lan magic

% sudo nmcli connection up d46c707a-307b-3cb2-8976-f127168f80e6
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)

% sudo ethtool enp2s0 | grep -i wake
	Supports Wake-on: pumbg
	Wake-on: g

The above changes will persist even after the machine reboots. We put the machine to sleep by using the following command:

% sudo systemctl suspend

We need the IP address and the MAC address of the machine to wake the computer up using the wakeonlan utility.

% ifconfig
enp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.168.185  netmask 255.255.255.0  broadcast 192.168.168.255
        inet6 fd1a:ee9:b47:e840:6cd0:bf9b:2b7e:afb6  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::41bc:2081:3903:5288  prefixlen 64  scopeid 0x20<link>
        inet6 fd1a:ee9:b47:e840:21b9:4a98:dafd:27ee  prefixlen 64  scopeid 0x0<global>
        ether 1c:1b:0d:70:80:84  txqueuelen 1000  (Ethernet)
        RX packets 33852015  bytes 25769211052 (25.7 GB)
        RX errors 0  dropped 128766  overruns 0  frame 0
        TX packets 3724164  bytes 4730498904 (4.7 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

We use the above ifconfig to find the addresses highlighted in bold. Once we have the required information, we can then wake the computer up remotely by executing the wakeonlan command from another computer.

% wakeonlan -i 192.168.168.255 -p 4343 1c:1b:0d:70:80:84
Sending magic packet to 192.168.168.185:4343 with 1c:1b:0d:70:80:84

Note that the above IP address used is the broadcast address and not the machine’s direct IP address. Now I can place these servers to sleep and only turn them on remotely when I need them.

EXT4-fs Errors on NVME SSD

In my previous post, I replaced my NVME boot disk on our media server thinking that the disk was defective because the file system (EXT4-fs) was reporting numerous htree_dirblock_to_tree:1080 errors.

The errors continue to persist with the new disk, so I can eliminate the possibility of hardware as the cause of the issue.

I noticed that the htree_dirblock_to_tree:1080 errors were caused by the tar command and the time in which these errors occur coincided when the media server is being backed up. Apparently, the backup process is causing these errors with the tar command.

This backup process has remained unchanged for quite some time and has worked really well for us. I guess for some reason there is a bug in the kernel or in the tar command that is not quite compatible with NVME devices.

I had to resort to finding an alternative backup methodology. I ended up using the rsync method instead.

sudo rsync --delete \
  --exclude 'dev' \
  --exclude 'proc' \
  --exclude 'sys' \
  --exclude 'tmp' \
  --exclude 'run' \
  --exclude 'mnt' \
  --exclude 'media' \
  --exclude 'cdrom' \
  --exclude 'lost+found' \
  --exclude 'home/kang/log' \
  -aAXv / /mnt/backup

It looks like this method is faster and can perform incremental backup. However, instead of backing up to an archive file, which I later need to extract and prepare during the restoration process, I have to back it up to a dedicated backup device. Since the old NVME disk is perfectly fine, I reused it as my backup device. I have partitioned this backup device in the same layout as the current boot disk.

Device          Start        End    Sectors   Size Type
/dev/sdi1        2048    2203647    2201600     1G Microsoft basic data
/dev/sdi2     2203648 1921875967 1919672320 915.4G Linux filesystem
/dev/sdi3  1921875968 1953523711   31647744  15.1G Linux swap

The only exception is that the first partition is not marked as boot and esp, so during the restoration process I will have to mark that partition accordingly with the parted command by using the following commands:

set 1 boot on
set 1 esp on

The idea is that at 3am every night/morning, I will backup the root filesystem to the second partition of the backup drive. If anything happens with the current boot disk, the backup drive can act as an immediately available replacement, after a grub-install preparation as mentioned in the previous article.

Let us see how this new backup process works and hopefully, we can bid a final farewell to the htree_dirblock_to_tree:1080 errors!

Update: 2023-12-22

It looks like even with the rsync command, the htree_dirblock_to_tree:1080 errors still came back during the backup process. I decided to upgrade the kernel from vmlinuz-5.15.0-91-generic to vmlinuz-6.2.0-39-generic. Last night (2023-12-23 early morning) was the first backup after the kernel upgrade, and no errors were recorded. I hope this behavior persists and it is not a one-off.

Replacing NVME Boot Disk

A few months ago, the boot disk of our media server begin to incur some errors, such as the ones below:

Dec 17 03:01:35 avs kernel: [32515.068669] EXT4-fs error (device nvme1n1p2): htree_dirblock_to_tree:1080: inode #10354778: comm tar: Directory block failed checksum
Dec 17 03:02:35 avs kernel: [32575.183005] EXT4-fs error (device nvme1n1p2): htree_dirblock_to_tree:1080: inode #13500463: comm tar: Directory block failed checksum
Dec 17 03:02:35 avs kernel: [32575.183438] EXT4-fs error (device nvme1n1p2): htree_dirblock_to_tree:1080: inode #13500427: comm tar: Directory block failed checksum

The boot disk is a NVME device and I thought it may be due to over heating, so I purchased a heat sink and installed it. Unfortunately the errors persisted after the heat sink.

I decided to replace the boot disk with the exact same model which was the Samsung 980Pro 1TB. This should have been a pretty easy maintenance task. We clone the drive, and swap in the new drive. However, Murphy is sure to strike!

My usual goto cloning utility is Clonezilla, unfortunately this utility did not like cloning NVME drives. The utility resulted in a kernel panic after trying multiple versions. I am not sure what is the problem here. It could be Clonezilla or the USB 3.0 NVME enclosure that I was using for the new disk.

I resigned to using the dd command:

dd if=/dev/source of=/dev/target status=progress

Unfortunately this would have taken way too long something like 20+ hours, so I gave up with this approach.

I decided to do a good old restore of the nightly backup. I started by cloning the partition table:

sfdisk -d /dev/olddisk | sfdisk /dev/newdisk

I then proceeded with the restore of the nightly backup. Murphy strikes twice! The nightly backup was corrupted! I guess it is not surprising when the root directory’s integrity is in question. The whole reason why we are doing this exercise.

Without the nightly backup, I had to resort to a live backup. I booted system again, and performed:

sudo su -
mount /dev/new_disk_root_partition /mnt/newboot
cd /
tar -cvpf - --exclude=/tmp --exclude=/home/kang/log --exclude=/span --exclude="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Cache" --one-file-system / | tar xvpzf - -C /mnt/newboot --numeric-owner

The above took about an hour. I then copy the /span directory manually, because this directory tends to change while the server is up and running.

With all the contents copied, I forgot how to install grub and had to re-teach myself again. I had to use a live copy Ubuntu USB and use that to boot up the machine, and then mount both the root and efi partitions respectively.

nvme1n1                              259:0    0 931.5G  0 disk
├─nvme1n1p1                          259:1    0     1G  0 part  /boot/efi
├─nvme1n1p2                          259:2    0 915.4G  0 part  /
└─nvme1n1p3                          259:3    0  15.1G  0 part  [SWAP]

And install GRUB.

sudo su -
mkdir /efi
mount /dev/nvme1n1p1 /efi
mount /dev/nvme1n1p2 /mnt
grub-install --efi-directory /efi --root-directory /mnt

I also have fix the /etc/fstab to ensure the root partition and /boot/efi partition are properly referenced by their corresponding, correct UUID. The blkid command came in handy to find the UUID. For the swap partition, I had to use the mkswap command before I get the UUID.

After I rebooted, I reinstalled GRUB one more time with the following as super user:

grub-install /dev/nvme1n1

I also updated the initramfs using:

update-initramfs -c -k all

For something that should have taken less than an hour, it took the majority of the day. The server is now running with the new NVME replacement disk. Hopefully this resolves the file system corruptions. We have to wait and see!

Update: The Day After

The same errors occurred again! I noticed that these corruptions occur when we do a system backup. How ironic! I later confirmed that performing the tar command on the root directory during the backup process can cause such an error. I now have to see why this is. I will disable the system backup for the next few days to see if the errors come back or not.

How China Got Rich

After watching the documentary called “How China Got Rich” by Michael Woods, originally released in 2019, from my Amazon Prime subscription, I thought while my China experiences and memories are still fresh in my mind, I provide a few of my own takeaways here. Not all of these thoughts stem from the video itself. Some of these ideas have been toiling in my mind for quite some time and the video has just triggered them to the surface. I have articulated some of these ideas on Quora before but have never really put them in a long and organized form, which I will attempt to do here.

The video starts with the transition from Mao Zedong (毛泽东) to Deng Xiaoping (邓小平), where Chinese leadership collectively recognized that the focus on ideology alone cannot be the sole recipe for success. Sooner or later practicality, along with social improvement is required. One can debate whether the Communist Party of China (CPC) took too long to recognize this change, or that it took the passing of Mao for this change to be realized, the important takeaway here is that the government recognized the need for change and carried it out. The documentary even gave some examples where certain changes were carried out within weeks of the decision to formulate the Special Economic Zones.

Although a peaceful change in government is one of many foundational ideas in a Western-style democracy, a similar change of equal magnitude in the West will be challenging. The concept of when people are unhappy with the government, they can use their voting power to change it, sounds really attractive, and the West habitually points out that Communist China lacks this governing feature.

The theory of these peaceful changes fails to deliver on the actual progress desired by the majority of us. The new government often runs similar policies to the previous government because many of the appointed civil servants, advisors, and lobbyist groups remain unchanged. One can even argue that the voted-in politicians are nothing more than figureheads, while true decision and policy-making power stems from the people behind the scenes. Yes, policy changes do happen, but at a much slower pace and with a lot of back-and-forth debates. These debates culminate in grandstanding and ego projections instead of converging to constructive agreements.

An example of a change that occurs at a glacier pace is that to this day, Toronto subway systems still lack modern data services to their passengers while riding on the train. Meanwhile from the inception of mobile services to today, Chinese cities have built (many from scratch) modern subway systems with full 5G data coverage for their ridership.

The West meanders changes through cycles of elections. When social discourse is in harmony, progress is still made at a snail’s pace. When social division is the norm, like today, change in power represents flip-flopping of decisions, and taking one step forward and two steps back.

Although centralized power is disliked by the West, China’s leaders understand that their centralized power stems from the people. As architects of the previous revolution, they understand how unhappy people can be quickly mustard to form a strong force against the incumbent government. Therefore they are more compelled to listen and truly reflect on their own policies and institute potential changes. Any disagreement by the public nearing social disruptions, is rapidly answered by the government. Examples are:

  • Failure of regional banks which incites loud demonstrations by local customers forced the government to guarantee all of their deposits;
  • A rapidly transmitting and lethal disease in 2019 called COVID-19 caused public outcry due to government inaction. The government was compelled to change from its original decision of censorship to immediate action leading to a rapid city lockdown of Wuhan;
  • Once COVID-19 has mutated to be less deadly and containment proved to be too challenging, public opinion shifted to open the gates. The government hesitated but ultimately relented to the gradual opening up of the entire society;

The documentary gave numerous accounts where the CPC’s primary focus is the betterment of the livelihood of ordinary people, lifting them from their impoverished state. It is not about world domination, or increasing the country’s soft power over other nations. It was all about improving people’s day-to-day life.

CPC’s foreign policy is one of many instruments towards the goal of what makes an average Chinese life better. The same is true of its monetary, economic, climate, and other policies. The end results of these policies are being interpreted by the West as threats of domination or have the potential of tainting the way of life of the West. These grievances are just envious (but despicable) interpretations of China’s rapid social, economic, technological, and military progress. The primary focus of the CPC is the average life of a Chinese living in China. And yes, this includes the Chinese in Taiwan.

In China, once they set out on a goal, their path to executing that goal is unrelenting. Any distractions or distractors are removed as soon as they are realized to be inhibitors of the ultimate plan. Sacrifices are weighed and hard decisions are taken with the assumption that the plan is better for the entire society. And it is okay that certain individuals’ welfare or organizations are sacrificed for the greater cause.

The idea that the populace must hold the country’s interest to be higher than a family’s or individual’s interest is a concept that is very difficult for the West to accept, since individual freedom and property ownership is a core value to the West’s concept of liberty. In Chinese society, social stability is paramount, and they are tolerant if they have to make certain minority groups unhappy to achieve their goals. Personal happiness is simply secondary to social well-being.

The video mentions that the CPC made an early and conscious decision to embark on economic liberalization but retain political centralization. This is an important decision by the CPC so that they have the power to execute on the big economic changes. These changes undoubtedly will cause some amount of short-term inequity and they have to be endured. In short, the massive economic change over the past 40 years did not create happiness for everyone, for the majority, yes.

The CPC realizes that the macro economy of any society is simply too complex to be planned out every five years. The capitalist free market model allows for a self-adjusting system, which determines the most optimal products and services to be made and delivered, and a self-regulation of demand based on a value-based system. This value-based system requires the natural flow and ebb of market pricing to work, creating a self-prioritization of goods and services, through the use of natural price elasticity, which is driven by market forces of supply and demand. The root driver of this economic momentum and self-adjustment is a degree of inequity in the system. Without profit which is an inequity between revenue and cost, the free market ceases to function.

The CPC realizes the benefit of such a market force and pursues this agenda through Special Economic Zones like Shenzhen. In these zones, a market is allowed to be established, and businesses (and their owners) can prosper (get wealthy) in developing and choosing the most optimal products that are in need, for both domestic and global consumption.

At the same time, political changes (such as a move to a Western style of democratization), are avoided and prohibited. In this way, the CPC can keep Chinese society focused on its primary goal, improving people’s lives. Changing both the political and economic system will be one change too many.

If China does not have a central authority and lacks the one-party system, the pace we witness today simply will not exist. Think of China as a big technology corporation. The CPC is the management authority within this company. The CPC sets up R&D divisions within the company. These divisions are akin to the Special Economic Zones. Once the CPC figures out what works and what does not, the management mechanism rolls it forward to the rest of the country or company.

The evolution of the Chinese market has allowed a growing income gap to form. Initially, this is tolerated because the CPC needs to allow innovation and there is no greater incentive and motivation than getting rich individually. However, the existence of an income gap is counter to the beliefs of the betterment for all. This income inequity is a deviation from the CPC’s primary goal. The economic zones created huge opportunities for millions of people but certainly did not spread the wealth equally to all people in China, especially those in the rural areas of China.

To balance the nature of a free market and a means of wealth distribution such that more of the population benefits from the country’s continual development, and yet not upsetting the rich too much, a central form of control is required. A Western democratic system will cause the rapid growth of the free market uncontrollable. CPC today has the power to reel in the corruption of those in authority and manage the influence of the rich. An excellent example is the dismantling of the financial instruments provided by the Ant Group (a Jack Ma’s company) before it is allowed to impact the country’s financial systems.

CPC’s central authority is the primary mechanism by which the party can influence its population. You can call it brainwashing, propaganda, or education. However you choose to categorize or term this form of control, it is how the CPC coaches its population to ensure each member of the “team” knows the direction of the goal. Every five years the CPC develops a new Five-Year-Plan that is effectively a playbook to guide members of society so that they kick the ball towards the goal(s) in the most efficient and unified fashion possible. I think this is ultimately the secret sauce in China’s acceleration to its rapid pace in accumulating its wealth and capabilities.

Most of the West believes in the Invisible Hand of the economy, and that the government should allow the market to function without much intervention. This belief has worked during economic revolutions spanning from the industrial to the information revolution. During these revolutions, the biggest challenge of modern governments was the management of poverty and the middle-classes. Some are more successful than others. However, as we enter into the era of artificial intelligence (AI) when human economic value is effectively being eroded or eliminated, we may not be able to depend on the Invisible Hand to ensure our livelihoods. The Chinese system is well positioned to regulate AI in its economy and provides a thicker security blanket to people’s well-being from potential threats from AI.

China’s implementation of its development is to leverage the Invisible Hand of the free market forces to determine what works and guide it with its Strong Hand of central authority such that the focus on its primary goal is not lost. The speed of development is the result of walking this balance.

Controversies

We now live in a world where if you live in the West, democracy is good, and authoritarian or dictatorship is bad. The mechanism and structure of the government are automatically used to categorize whether the government is good or bad for its people. The debates summarily center around what democracy provides, which is freedom and liberty, versus repressions and restrictions that non-democratic governments project. These ideas have been entrenched in us since our early education, that it is extremely difficult for a person in the West to have an open mind regarding non-democratic societies. Interestingly, we allow for different religions to be practiced, but in terms of the types of government, it is democracy and nothing else.

Many of us will not measure the true effectiveness of a government by observing the results that the government yields for its people. Instead, we flock to the core idea of the ability to vote, and the assumption that our voting power gives us the ability to affect change in our government. Elections are held every four to five years, and hold the firm belief that we can participate in the change of government and elect representatives that then decide what is best for us for the next four to five years. However, these elections are nothing more than pacifying events creating an illusion of power to change. In reality, it is simply a hand-waving motion that takes place every four to five years.

In effect, if an individual really wants to implement change in the current government, one needs to be politically active. Similar to starting a company and seeking funding to operate its business, the same holds true for any political ventures in the West. Politicians are therefore at the mercy of the wealthy who can allocate the money required to enable the politicians to play within the political system. It is therefore easy to see how political representation is ultimately biased towards the people who are funding you instead of those who directly voted for you.

The Chinese governing system is a meritocracy, where leaders are first proven with smaller responsibilities at the county or municipal level, and subsequently appointed to larger portfolios such as city and province levels. Eventually through competition, political maneuvering, and when the stars and planets finally align, you can attain the top position of the party and the presidency of the country. Throughout this ascension, a party member holding a leadership position acquires skills to make people’s lives better, from thousands to ultimately billions of people.

It is easy to debate which type of government is procedurally (and theoretically) better, but in the end, what matters to the people is a government that delivers a better livelihood to its people. I compare this debate to an argument about which Apple Pie recipe tastes better. However, the recipe (procedure or mechanics) is not enough in the sole determination of how tasty the final pie will taste to one’s palate. Other factors exist to determine the success of the pie, such as the sourcing of the ingredients, the cook’s skill in carrying out the recipe with his experience, and the final presentation and delivery of the pie. There are simply too many other variations other than the recipe.

Debating the form of government is unproductive. It is more valid to debate what the government actually accomplishes for its people. Otherwise, we are just debating on ideological differences, something to be avoided if we do not want a reoccurrence of the Crusades when Christianity was pitted against the religion of Islam.

Results

China’s combination of a centralized government and a market economy gives it a unique power to solve some large social issues, with both efficiency and focus. They are not perfect and mistakes have been made. However, they also can self-reflect and take corrective actions. And yes sometimes unfair decisions are made in the process.

People that I have met and discussed within China certainly do not feel oppressed. They feel free and lucky to be living in a country, where they can now enjoy many of the same goods and services that are available in the West. People who are 35 years of age and older will have witnessed this improvement, which they directly credit the CPC.

Except for Hong Kong and Macau, the Chinese can take advantage of their convenient and cheap transportation system and enjoy their vast country with beautiful geological sceneries, and diverse ethnic cultures. Why the exception to Hong Kong and Macau? The working theory is to protect Hong Kong and Macau’s market development. Imagine if people can freely move into the former colonies, their markets will be diluted and it will be harder for them to remain globally competitive.

With that said, there are still people in China who prefer to live in the West. These are typically upper middle class or higher, who have made their riches and do not want to experience the potential of the CPC to relevel their wealth. This is quite understandable from an individual perspective. Managing a sustainable income gap is one of CPC’s core challenges.

Other Thoughts

My thoughts on the subject of China have led me to come to some other conclusions in the following areas:

  • The true meaning of rights and freedoms within a society;
  • Intellectual properties and what it really means to a society;
  • The concept of profit, income, and debt, and how we are all manipulated by the modern financial system;
  • The right to project one’s will and values on another based on one’s moral high ground;
  • The justification of censorship vs. free speech;

This post is already quite lengthy, so I think will come back to the above topics and address each one in turn.

Fenggang to Toronto

We spent the remaining days of November in Fenggang and then took our flight home via Tokyo on December 1st.

Not much exciting happened in the remaining days other than relaxing and going about what locals do. Effectively, we enjoyed the native life in Fenggang County (县), Dongguan City (市), Guangdong Province (省). I fell ill, so there was zero energy in me to do much travelling. Our original plan of visiting Shenzhen had to be scuttled.

We completed some final banking businesses, and also learned that our access to our Chinese banking accounts may be difficult through our Nihao Mobile numbers, but it was a bit too late to make this change. If we had to do things differently next time, we would probably get a number from one of the big three mobile operators in China, which are: China Mobile (中国移动), China Telecom (中国电信), and China Unicom (中国联通). The primary reason is that Nihao Mobile numbers cannot be active outside of China, but the others can be roamed in Canada and receive SMS messages for authentication services, which are essential for banking applications. We will get this fix on our next trip, which we plan to go at about the same time next year.

Our last leg home was on a flight through Air Canada. Every time I fly this leg from the Far East to Toronto, I swear that I will not be flying on Air Canada ever again on the same route. However the cheap the fare was, it was not worth the hassle. The disorganized boarding process, the narrow seats, the low quality of the food and sometimes adversarial cabin service, and finally the baggage handling delays, all would make me regret in saving a few bucks. Cathay Pacific all the way next time for sure, or one of the Chinese airlines.

Below are the remaining and final videos from Carol documenting our Asian Trip. It has been a blast.

November 28th: Grocery shopping
November 29th: Sampling more restaurants from Fenggang
November 30th: Sampling all the wontons from different restaurants
December 1st: Coming home via Hong Kong and Tokyo