Installing Debian 12 on a Dedicated Server

From Server rental store
Jump to navigation Jump to search

This article provides a comprehensive guide to installing Debian 12 (Bookworm) on a dedicated server, focusing on setting up RAID for data redundancy and LVM for flexible storage management. This guide is intended for users with some Linux familiarity but aims to be accessible to beginners transitioning to dedicated server administration.

Prerequisites

Before you begin the installation, ensure you have the following:

  • **Dedicated Server:** Access to a physical server with bootable media capabilities (e.g., IPMI, iDRAC, KVM over IP, or a physical keyboard/monitor).
  • **Debian 12 Installation Media:** A bootable USB drive or ISO image of Debian 12. You can download the netinst (network install) ISO from the official Debian website. Using the netinst ISO is recommended as it's smaller and downloads the latest packages during installation.
  • **Network Connectivity:** A stable internet connection for the server to download packages during installation.
  • **Basic Linux Knowledge:** Familiarity with command-line operations and basic partitioning concepts.
  • **Hardware RAID Controller (Optional but Recommended):** If your server has a hardware RAID controller, ensure you understand its configuration interface. This guide will primarily focus on software RAID (mdadm).
  • **Storage Devices:** Multiple hard drives for RAID configuration. For example, at least two drives for RAID 1 (mirroring) or at least three for RAID 5.

Understanding RAID and LVM

  • **RAID (Redundant Array of Independent Disks):** A technology that combines multiple physical disk drives into one or more logical units for the purposes of data redundancy, performance improvement, or both.
   *   **RAID 0 (Striping):** Improves performance by spreading data across drives, but offers no redundancy. A drive failure results in data loss. Not recommended for critical data.
   *   **RAID 1 (Mirroring):** Writes identical data to two or more drives, providing excellent redundancy. If one drive fails, the other(s) can continue operating. Performance is typically similar to a single drive.
   *   **RAID 5:** Stripes data across multiple drives and uses parity information distributed across all drives. It offers a good balance of performance and redundancy, tolerating one drive failure. Requires at least three drives.
  • **LVM (Logical Volume Management):** A storage management technology that provides a layer of abstraction over physical storage devices. It allows for flexible partitioning, resizing, snapshots, and easier management of storage.
   *   **Physical Volumes (PVs):** The physical storage devices (hard drives or partitions) that LVM will manage.
   *   **Volume Groups (VGs):** A pool of storage created by combining one or more PVs.
   *   **Logical Volumes (LVs):** Virtual partitions created from the VG. These are what you will mount and use as your file systems.

Using RAID with LVM provides both data redundancy and flexible storage management.

Booting from Installation Media

1. **Access BIOS/UEFI:** Reboot your server and enter the BIOS/UEFI setup. The key to press varies by manufacturer (commonly `Del`, `F2`, `F10`, `F12`, or `Esc`). 2. **Set Boot Order:** Configure the server to boot from your Debian 12 installation media (USB or DVD drive). 3. **Save and Exit:** Save your changes in the BIOS/UEFI and exit. The server should now boot from the installation media.

Debian 12 Installation Process

Once the server boots from the installation media, you will be presented with the Debian installer.

1. **Choose Installation Method:** Select "Graphical install" or "Install" (text-based). For this guide, we'll assume the graphical install. 2. **Select Language, Location, and Keyboard Layout:** Follow the on-screen prompts to configure these settings. 3. **Network Configuration:**

   *   The installer will attempt to configure the network via DHCP. If you have a static IP, you'll configure it here.
   *   **Hostname:** Enter a hostname for your server (e.g., `debian-server`).
   *   **Domain Name:** Enter your domain name (e.g., `yourdomain.local`).

4. **Set Root Password:** Create a strong password for the `root` user. This is critical for system security.

   *   **Security Implication:** A weak root password is a major security vulnerability. Use a combination of uppercase and lowercase letters, numbers, and symbols, and avoid common words or personal information.

5. **Create User Account:** Create a non-root user account. This is good practice for day-to-day administration.

   *   **Full Name:** Your name.
   *   **Username:** A short, lowercase username (e.g., `adminuser`).
   *   **Password:** A strong password for this user.

6. **Partition Disks:** This is the most crucial step for setting up RAID and LVM.

   *   Select **"Manual"** partitioning.
   *   **Identify Your Drives:** You will see a list of your available drives (e.g., `/dev/sda`, `/dev/sdb`, `/dev/sdc`).
   *   **Create Partitions for Software RAID:**
       *   For each drive you intend to use in your RAID array, you need to create a partition of type "Linux RAID".
       *   **Example for RAID 1 on `/dev/sda` and `/dev/sdb`:**
           *   Select `/dev/sda`.
           *   Choose "Create new partition".
           *   **Size:** Use the maximum available size.
           *   **Type:** Select "Primary".
           *   **Location:** Select "Beginning".
           *   **Use as:** Select "Physical volume for RAID".
           *   Repeat this for `/dev/sdb`.
       *   **Example for RAID 5 on `/dev/sda`, `/dev/sdb`, `/dev/sdc`:**
           *   Repeat the above for each drive, creating a partition of type "Linux RAID" on each.
   *   **Configure Software RAID:**
       *   Once you have created the partitions for RAID, select "Configure software RAID".
       *   Choose "Create RAID 1 volume" (or RAID 5, etc.).
       *   **Number of Devices:** Enter the number of drives in your array (e.g., 2 for RAID 1, 3 for RAID 5).
       *   **Select Partitions:** Select the RAID partitions you created (e.g., `/dev/sda1`, `/dev/sdb1`).
       *   **Device Name:** The system will suggest a name like `/dev/md0`. Accept this.
       *   **RAID Level:** Confirm the RAID level.
       *   **Create:** Confirm the creation.
   *   **Configure LVM:**
       *   After creating the RAID device (e.g., `/dev/md0`), you need to set it up as a Physical Volume for LVM.
       *   Select the RAID device (`/dev/md0`).
       *   Choose "Create new partition".
       *   **Size:** Use the maximum available size.
       *   **Type:** Select "Primary".
       *   **Location:** Select "Beginning".
       *   **Use as:** Select "Physical volume for LVM".
       *   **Create:** Confirm.
       *   Now, select "Configure LVM".
       *   Choose "Create volume group".
       *   **Volume Group Name:** Enter a name (e.g., `vg_system`).
       *   **Physical Volumes:** Select the LVM partition you just created (e.g., `/dev/md0p1`).
       *   **Create:** Confirm.
       *   Now, select "Create logical volume".
       *   **Logical Volume Name:** Enter a name (e.g., `lv_root`, `lv_home`, `lv_swap`).
       *   **Volume Group:** Select your created volume group (`vg_system`).
       *   **Size:** Allocate space for your logical volumes. For example:
           *   `lv_root`: 50GB (or as needed for your OS and applications).
           *   `lv_swap`: 2GB (or equal to your RAM if you plan to hibernate).
           *   `lv_home`: Remaining space.
       *   **Create:** Confirm.
   *   **Set up Mount Points:**
       *   Select the logical volume for your root filesystem (`lv_root`).
       *   Choose "Set up as: Ext4 journaling file system".
       *   Choose "Mount point: /".
       *   Select the logical volume for swap (`lv_swap`).
       *   Choose "Set up as: swap area".
       *   Select the logical volume for home directories (`lv_home`).
       *   Choose "Set up as: Ext4 journaling file system".
       *   Choose "Mount point: /home".
       *   **Finish Partitioning:** Once all logical volumes are configured, select "Finish partitioning and write changes to disk". Confirm the write operation.

7. **Install Base System:** The installer will now install the base Debian system onto your configured partitions. 8. **Package Manager Configuration:**

   *   **Scan extra media:** Choose "No".
   *   **Debian archive mirror:** Select a mirror close to your geographical location.
   *   **HTTP proxy:** Leave blank unless you use a proxy.

9. **Software Selection:**

   *   **Desktop environment:** For a server, it's generally recommended to deselect any desktop environments (like GNOME, KDE) to save resources and reduce the attack surface. Select "SSH server" and "Standard system utilities".

10. **Install GRUB Boot Loader:**

   *   **Install GRUB boot loader to MBR?** Select "Yes".
   *   **Device for boot loader installation:** Select your primary RAID device (e.g., `/dev/md0`). **Do NOT select a partition like `/dev/md0p1`.**

11. **Finish Installation:** The installer will prompt you to remove the installation media and reboot.

Post-Installation Configuration

After the reboot, your Debian 12 server should boot up. Log in with the user account you created.

1. **Update System:**

   ```bash
   sudo apt update
   sudo apt upgrade -y
   ```
   *   **Why:** This ensures all installed packages are up-to-date with the latest security patches and bug fixes.
   *   **Expected Output:** A stream of package information and download progress.

2. **Verify RAID Status:**

   ```bash
   cat /proc/mdstat
   ```
   *   **Expected Output:**
       ```
       Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10]
       md0 : active raid1 sda1[0] sdb1[1]
             976631808 blocks super 1.2 [2/2] [UU]
             [====>................]  resync = 25.0% (244157952/976631808) finish=60.5min speed=26666K/sec
       ```
       *   `[UU]` indicates both drives in the array are up and running. `[_U]` would indicate one drive has failed.
   *   **Troubleshooting:** If one drive shows as failed (`_U` or `UU` with a drive missing), you'll need to replace the failed drive and rebuild the array. Refer to your RAID controller's documentation or `mdadm` man pages for specific rebuild instructions.

3. **Verify LVM Configuration:**

   ```bash
   sudo pvs
   sudo vgs
   sudo lvs
   ```
   *   **Expected Output:**
       ```
       PV         VG       Status  LVMVersion
       /dev/md0p1 vg_system lvm2   2.03.17-ioctl (2022-07-01)
       VG       #PV #LV #SN Attr   VSize   <VSize
       vg_system  1   3   0 wz--n- 931.51g <931.51g
       LV      VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
       lv_home vg_system -wi-a----- 900.00g
       lv_root vg_system -wi-a-----  50.00g
       lv_swap vg_system -wi-a-----   2.00g
       ```
   *   **Why:** This confirms LVM has correctly recognized your physical volume, volume group, and logical volumes.

4. **Configure SSH Access:**

   *   For enhanced security, consider disabling root login via SSH and enforcing key-based authentication.
   *   Edit the SSH configuration file:
       ```bash
       sudo nano /etc/ssh/sshd_config
       ```
   *   Find and modify these lines:
       ```
       PermitRootLogin no
       PasswordAuthentication no # If using key-based authentication
       ```
   *   **Security Implication:** Disabling root login and password authentication significantly reduces the risk of brute-force attacks.
   *   **Restart SSH service:**
       ```bash
       sudo systemctl restart ssh
       ```

5. **Install Essential Server Software:**

   *   **Web Server (e.g., Nginx):**
       ```bash
       sudo apt install nginx -y
       sudo systemctl enable nginx
       sudo systemctl start nginx
       ```
   *   **Database (e.g., PostgreSQL):**
       ```bash
       sudo apt install postgresql postgresql-contrib -y
       sudo systemctl enable postgresql
       sudo systemctl start postgresql
       ```
   *   **PHP (if needed for web applications):**
       ```bash
       sudo apt install php-fpm php-mysql -y
       ```

Troubleshooting Common Issues

  • **"No bootable device found"**:
   *   **Cause:** GRUB may not have been installed correctly or the boot order in BIOS/UEFI is incorrect.
   *   **Solution:** Re-enter the BIOS/UEFI and ensure the boot order prioritizes the drive where GRUB was installed. If necessary, boot from the Debian installer again and use the "rescue mode" to reinstall GRUB.
  • **RAID array not assembling:**
   *   **Cause:** Partitions not correctly marked for RAID, or `mdadm` configuration issues.
   *   **Solution:** Boot from the installer, select "Manual" partitioning, and carefully re-examine the RAID partition types and the `mdadm` configuration. Ensure the `/etc/mdadm/mdadm.conf` file is correctly populated.
  • **LVM logical volumes not appearing:**
   *   **Cause:** Physical volumes not correctly initialized or volume groups not created.
   *   **Solution:** Boot from the installer, select "Manual" partitioning, and verify that the RAID devices are marked as "Physical volume for LVM" and that a volume group has been successfully created.
  • **SSH connection refused:**
   *   **Cause:** SSH service not running, firewall blocking port 22, or incorrect SSH configuration.
   *   **Solution:** Check the status of the SSH service (`sudo systemctl status ssh`). Verify firewall rules (e.g., `sudo ufw status`). Ensure `sshd_config` is correctly formatted.

Related Articles