Skip to content

Commit 8bb5e65

Browse files
authored
Merge pull request #4 from khnumdev/linux_cheatsheet
Linux cheatsheet
2 parents b8730d9 + ea001d3 commit 8bb5e65

File tree

1 file changed

+152
-0
lines changed

1 file changed

+152
-0
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
layout: post
3+
title: "My current linux cheatsheet/setup"
4+
date: 2023-11-01 19:47:20 +0200
5+
categories: linux
6+
---
7+
8+
Since I've joined [Worklytics](https://www.worklytics.co/) I'm using Linux as operanting system for my daily work there. I've used Linux first time
9+
when I was at high-school and then when I was at university, but then I've switch to Microsoft stack including Windows and
10+
rest of .NET things.
11+
12+
The purpose of this post is for me, as a note for the future with the links I've found useful for setup and using Ubuntu since then.
13+
All credits belongs to the author of the related posts, I've just put there as a compilation.
14+
15+
## Dual boot with Bitlocker
16+
17+
First time I've installed Linux it was a like a pain. Since the release of Kubuntu (yeah I'm not as younger as I'd like to be) and Ubuntu the installation process, updates and package manager have improved a lot. Now just downloading the ISO of Ubuntu and put it in a USB pen is enough to setup the whole Linux system. The installation provides all the partition setup required for that.
18+
19+
But for sure this is more complicated if you want to keep two SOs (Windows and Linux) over the same computer, having both with disk encryption features enabled.
20+
21+
**NOTE**: This is only when two features are enabled. If Bitlocker/encryption are not enabled (and you SHOULD use it!) this post is not useful.
22+
23+
I've follow the detailed description of steps from [Mike Kasberg dual boot ubuntu and linux](https://www.mikekasberg.com/blog/2020/04/08/dual-boot-ubuntu-and-windows-with-encryption.html) which describe the following steps (leaving steps here in case of the post is removed/lost):
24+
1. As a prerequisite, we are going to do a clean installation of both systems.
25+
2. Make a USB pen with Ubuntu installation
26+
3. Create the partitions from Ubuntu live installation:
27+
28+
```bash
29+
sudo su
30+
# sgdisk --zap-all /dev/sda
31+
# sgdisk --new=1:0:+550M /dev/sda
32+
# sgdisk --change-name=1:EFI /dev/sda
33+
# sgdisk --typecode=1:ef00 /dev/sda
34+
# mkfs.fat -F 32 /dev/sda1
35+
```
36+
37+
4. Install Windows and use the partitioning tool, for creating a new partition
38+
5. Enable Bitlocker
39+
6. Check partition status:
40+
41+
```bash
42+
ubuntu@ubuntu:~$ sudo sgdisk --print /dev/sda
43+
Disk /dev/sda: 500118192 sectors, 238.5 GiB
44+
45+
Number Start (sector) End (sector) Size Code Name
46+
1 2048 1128447 550.0 MiB EF00 EFI
47+
2 1128448 1161215 16.0 MiB 0C01 Microsoft reserved ...
48+
3 1161216 167825076 79.5 GiB 0700 Basic data partition
49+
4 167825408 168900607 525.0 MiB 2700
50+
```
51+
7. Create partitions from Ubuntu live USB:
52+
53+
```bash
54+
$ sudo su
55+
# sgdisk --new=5:0:+1800M /dev/sda
56+
# sgdisk --new=6:0:0 /dev/sda
57+
# sgdisk --change-name=5:/boot --change-name=6:rootfs /dev/sda
58+
# sgdisk --typecode=5:8300 --typecode=6:8300 /dev/sda
59+
# mkfs.ext4 -L boot /dev/sda5
60+
```
61+
62+
8. Setup LUKS:
63+
64+
```bash
65+
# cryptsetup luksFormat --type=luks2 /dev/sda6
66+
WARNING!
67+
========
68+
This will overwrite data on /dev/sda6 irrevocably.
69+
70+
Are you sure? (Type uppercase yes): YES
71+
Enter passphrase for /dev/sda6:
72+
Verify passphrase:
73+
74+
# cryptsetup open /dev/sda6 sda6_crypt
75+
Enter passphrase for /dev/sda6:
76+
77+
# ls /dev/mapper/
78+
control sda6_crypt
79+
```
80+
81+
9. Create new partitions for Ubuntu:
82+
83+
```
84+
# pvcreate /dev/mapper/sda6_crypt
85+
Physical volume "/dev/mapper/sda6_crypt" successfully created.
86+
# vgcreate ubuntu-vg /dev/mapper/sda6_crypt
87+
Volume group "ubuntu-vg" successfully created
88+
# lvcreate -L 8G -n swap_1 ubuntu-vg
89+
Logical volume "swap_1" created.
90+
# lvcreate -l 100%FREE -n root ubuntu-vg
91+
Logical volume "root" created.
92+
```
93+
94+
10. Install Ubuntu, but **choosing* the partitions created in previous step instead of leaving the installer do it itself
95+
11. [Setup the password to decrypt](https://www.mikekasberg.com/blog/2020/04/08/dual-boot-ubuntu-and-windows-with-encryption.html#phase-4-install-ubuntu) the disk
96+
97+
98+
Now the computer is setup with dual boot, Bitlocker and LUKS. Note at this point, *any* change done by updates (for example, updating firmware from Ubuntu updates) may modify the boot partition causing that Bilocker *detects* that a change has been done in the disk, requesting you your key to allow you to unblock your computer on next reboot. This is why I've try to update the main stuff from Windows and *not* from Ubuntu.
99+
100+
## Git coloured current branch in terminal
101+
102+
This is from my friend [Kartones](https://github.com/Kartones), he shared some terminal settings that are interesting to have. This one is to have the existing git branch coloured as part of the path of the terminal line, so it is easy to know where you are.
103+
104+
Edit `.bashrc` file and add the following:
105+
106+
```
107+
~/.bashrc
108+
109+
# enable git prompt
110+
# source ~/.git-prompt.sh
111+
# PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w\[\033[00m\]$(__git_ps1) \$ '
112+
parse_git_branch() {
113+
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
114+
}
115+
export PS1="\u@\h \w\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "
116+
```
117+
118+
And close terminals and reopen them again.
119+
120+
## Speaker issues (not solved!)
121+
122+
Still not solved. Sound drivers still are a nightmare in Linux and in my case, if I connect a set of speakers from the 3.5 mm jack I heard an electrical noise as sound. It is not a computer issue because that is not happening in Windows.
123+
124+
This is the [post](https://askubuntu.com/questions/1230833/annoying-click-popping-sound-on-ubuntu-20-04) where some solutions are present; I've read that the one to
125+
enable the [auto-mute](https://askubuntu.com/a/1351408) from alsamixer works for some people, but not in my case.
126+
127+
On my computer, it seems like the headset input (but it is selected headphones when plugged in) is producing the internal input sound, colliding with the microphone. Weird, but if I disable it there are no noise (and no sound!). However with a bluetooth headset there is no problem.
128+
129+
There is another [post](https://askubuntu.com/questions/1241617/ubuntu-20-04-after-last-update-speakers-are-buzzing-unless-i-open-the-sound-s) with more details; playing with internal mic volume and gain improved the noise but still is there.
130+
131+
My current solution is to have the speakers in low volume, as they have a physical volume regulator and then have the system volume in high values.
132+
133+
## Low space in boot partition
134+
135+
After several updates, the boot partition (the lower one) will complain that there is no enough free space. That could be a problem because it avoids you to continue updating the system. Ubuntu offers a partition tool to free space if you know what you need to remove.
136+
137+
The other option is to run the autoremove command:
138+
139+
```bash
140+
sudo apt autoremove
141+
```
142+
143+
That works normally like a charm, but it wasn't my case. After some research I've discovered that I had a lot of old linux kernels in the partition that weren't removed and they cause to have the partition with lower space. The solution is easy: delete the old kernels but taking into account that you should delete the OLD ones, not the current ones in use. And as I've said before, I'm old enough to have suffered on my prime the best kernel panics and issues with Linux. I don't want that
144+
on my current computer again.
145+
146+
I've found [this post](https://askubuntu.com/questions/1423156/ubuntu-22-upgrade-needs-extreme-amount-of-space-in-boot-partition/1449412#1449412) where it exposes a command to drop from the system all the kernels not used:
147+
148+
```bash
149+
$ dpkg -l | egrep "linux-(signed|modules|image|headers)" | grep -v $(uname -r | cut -d - -f 1) | awk {'print $2'} | xargs sudo apt purge -y
150+
```
151+
152+
And after that, the lower space issue was fixed.

0 commit comments

Comments
 (0)