Zhao Dongyu's Blog

A life which is unexamined is not worth living.

0%

Using Ubuntu from scratch

原来的Ubuntu系统的用户权限搞崩了,从头开始搞一个~

1.系统安装

1.1 下载

Ubuntu 20.4镜像

1.2 把iso镜像文件转换成dmg文件

cd Downloads

hdiutil convert -format UDRW -o ubuntu.iso ubuntu-20.04.6-desktop-amd64.iso

  • -format为生成文件的权限;

  • UDRW :表示转换成有read/write的权限的镜像。

1
2
3
4
5
6
7
8
9
10
11
12
13
Reading Driver Descriptor Map (DDM : 0)…
Reading Ubuntu 20.04.6 LTS amd64 (Apple_ISO : 1)…
Reading Apple (Apple_partition_map : 2)…
Reading Ubuntu 20.04.6 LTS amd64 (Apple_ISO : 3)…
.....................................................
Reading EFI (Apple_HFS : 4)…
.....................................................
Reading Ubuntu 20.04.6 LTS amd64 (Apple_ISO : 5)…
...............................................................................
Elapsed Time: 4.971s
Speed: 834.8MB/s
Savings: 0.0%
created: /Users/zhaodongyu/Downloads/ubuntu.iso.dmg

1.3 烧录至优盘

注意找到U盘的路径,使用diskutil list命令查询。

1
2
3
4
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: FDisk_partition_scheme *16.0 GB disk4
1: Windows_FAT_32 NO NAME 16.0 GB disk4s1

找到U盘的路径为/dev/disk4,并使用命令行卸载U盘:

diskutil unmountDisk /dev/disk4

显示信息:Unmount of all volumes on disk4 was successful

把iso文件写入U盘 mv ubuntu.iso.dmg ubuntu.iso

sudo dd if=./ubuntu.iso of=/dev/disk4 bs=1m

等了几分钟后,显示

1
2
3
4149+1 records in
4149+1 records out
4351463424 bytes transferred in 369.833082 secs (11766020 bytes/sec)

弹出优盘

sudo eject /dev/disk4

2.系统设置

2.1 开启SSH连接

ubuntu开启SSH服务远程登录

sudo apt-get install openssh-server

可以ssh连接了

2.2 更新vim

  • 卸载旧版的vi:sudo apt-get remove vim-common

  • 安装新版的vim:sudo apt-get install vim

2.3 挂载硬盘

查看磁盘信息命令: sudo fdisk -l

其中有:

1
2
3
4
5
Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: ST1000DM003-1SB1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

查看硬盘的UUID命令: sudo blkid

1
/dev/sdb: UUID="2b4d86ff-3fb8-40c4-b5ef-dd840f65f94f" BLOCK_SIZE="4096" TYPE="ext4"

mkdir创建挂载点data

1
2
3
4
zhaodongyu@portal:/$ sudo mkdir data
zhaodongyu@portal:/$ ls
bin cdrom dev home lib32 libx32 media opt root sbin srv sys usr
boot data etc lib lib64 lost+found mnt proc run snap swapfile tmp var

手动挂载

sudo mount /dev/sdb /data

永久性挂载分区,修改分区文件,输入命令sudo vi /etc/fstab,增加

1
UUID=2b4d86ff-3fb8-40c4-b5ef-dd840f65f94f /data           ext4    defaults          0       0

查看挂载好的硬盘信息 df -hT

1
/dev/sdb       ext4   916G  207G  663G  24% /data

2.4 安装 VS code

打开 Ubuntu 软件中心,并且搜索Visual Studio Code,然后安装应用

2.5 安装make

sudo apt install make

2.5 cmake升级

参考

我在cmake官网下载了cmake-3.27.0-rc4-linux-x86_64.tar.gz

1
2
3
4
5
6
7
8
9
10
11
12
tar -zxvf cmake-3.27.0-rc4-linux-x86_64.tar.gz

sudo mv cmake-3.27.0-rc4-linux-x86_64 /opt/cmake-3.27.0

sudo ln -sf /opt/cmake-3.27.0/bin/* /usr/bin/

cmake --version
cmake version 3.27.0-rc4

sudo vim ~/.bashrc
export PATH=$PATH:/opt/cmake-3.27.0/bin
source ~/.bashrc

2.6 gcc降级

原来的gcc版本是9.4

sudo apt-get install gcc-9

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100

sudo apt-get install g++-9

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 100

Thanks for your support.