Skip to content

Instantly share code, notes, and snippets.

@PokeGuys
Last active March 21, 2021 14:00
Show Gist options
  • Save PokeGuys/89d10e165c0a310617a8cd56fb222742 to your computer and use it in GitHub Desktop.
Save PokeGuys/89d10e165c0a310617a8cd56fb222742 to your computer and use it in GitHub Desktop.
Linux setup script

Arch Linux

How can I resize my / (root) partition?

Step by Step Instructions

sudo fdisk /dev/mmcblk0

then type p to list the partition table

you should see three partitions. if you look in the last column labeled System you should have

  1. W95 FAT32
  2. Linux
  3. Linux Swap

make a note of the start number for partiton 2, you will need this later. though it will likely still be on the screen (just in case).

next type d to delete a partition.

You will then be prompted for the number of the partition you want to delete. In the case above you want to delete both the Linux and Linux swap partitions.

So type 2

then type d again and then type 3 to delete the swap partition.

Now you can resize the main partition.

type n to create a new partition.

This new partition needs to be a primary partition so type p.

Next enter 2 when prompted for a partition number.

You will now be prompted for the first sector for the new partition. Enter the start number from the earlier step (the Linux partition)

Next you will be prompted for the last sector you can just hit enter to accept the default which will utilize the remaining disk space.

Type w to save the changes you have made.

Next reboot the system with the following command:

sudo reboot

once the system has reboot and you are back at the commandline enter the following command:

sudo resize2fs /dev/mmcblk0p2

Note: this can take a long time (depending on the card size and speed) be patient and let it finish so you do not mess up the file system and have to start from scratch.

Once it is done reboot the system with the following command:

sudo reboot

You can now verify that the system is using the full capacity of the SD Card by entering the following command:

df -h

Why This Works:

The real magic here is that you delete the root and swap partitions, then recreate only the root partition (using the original start sector) before writing the data to the disk. As a result you don't erase the existing data from the root partition.

By removing the swap partition you allow the root partition room to grow beyond its current size and fill the unused portion of the disk (because of the placement of the partitions -the root partition is sandwiched between the boot and swap partitions - it can't simply be resized leaving the swap partition alone).

You then resize (which is safe to run on a mounted disk) the file system to use all the space in the new root partition.

ref:

#!/usr/bin/bash
# Setup pacman keys
pacman-key --init
pacman-key --populate archlinuxarm
pacman -Syy
# Setup sudoer
pacman -S sudo
# Search `%wheel ALL=(ALL) ALL` and uncomment it:
EDITOR=nano visudo
# Add a new user
useradd -d /home/yourUserName -m -G wheel -s /bin/bash yourUserName
passwd yourUserName
sudo userdel alarm
#!/usr/bin/bash
# Prioritize pacman mirror
sudo pacman -S pacman-contrib
sudo cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
sudo sed -i 's/^# Server =/Server=/' /etc/pacman.d/mirrorlist.backup
sudo bash -c "rankmirrors -n 6 /etc/pacman.d/mirrorlist.backup > /etc/pacman.d/mirrorlist"
# Upgrade & update package
sudo pacman -Syu --noconfirm
# Installing Terminal-related package
sudo pacman -S --noconfirm zsh alacritty wget mlocate git base-devel ripgrep unzip zstd
# Fixing mlocate.db
sudo updatedb
# Setup oh-my-zsh.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
sudo pacman -S --noconfirm zsh-theme-powerlevel10k zsh-autosuggestions zsh-syntax-highlighting
echo "source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
echo "source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
echo "bindkey '^H' backward-kill-word" >> ~/.zshrc
# Setup dev-tool
## PHP
sudo pacman -S --noconfirm php
## Nodejs
sudo pacman -S --noconfirm nodejs yarn
## Golang
sudo pacman -S --noconfirm go
## Python2, 3
sudo pacman -S --noconfirm python python-pip python-setuptools
sudo pacman -S --noconfirm python2 python2-pip python2-setuptools
# Setup docker
sudo pacman -S --noconfirm docker
sudo groupadd docker
sudo usermod -aG docker $USER
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment