Setting up disks manually: Difference between revisions

From Alpine Linux
(Created page)
 
(working)
Line 1: Line 1:
You may have complex needs that aren't handled automatically by the [[Alpine Setup Scripts]]. In those cases, you'll need to prepare and mount your disks manually, and then supply the root mountpoint to [[setup-disk]].
{{Draft}}
 
You may have complex needs that aren't handled automatically by the [[Alpine Setup Scripts]]. In those cases, you'll need to prepare your disks manually.
 
=== RAID ====
<code>setup-disk</code> will automatically build a RAID array if you supply the '''-r''' switch, or if you specify more than one device.
 
If you instead want to build your RAID array manually, see [[Setting up a software raid1 array]]. Then you can add additional layers of encryption and/or LVM, or just assemble the RAID array, and supply the {{Path|/dev/md<i>i</i>}} device directly to [[setup-disk]]. When you're finished, be sure to disassemble the RAID array before rebooting.
 
=== Encryption ===
 
See [[Setting up encrypted volumes with LUKS]]. Then you can add an additional layer of LVM, or just unlock the volume you've created (using <code>cryptsetup luksOpen ...</code>), and supply the {{Path|/dev/mapper/<i>something</i>}} device directly to [[setup-disk]]. When you're finished, be sure to relock the volume (using <code>cryptsetup luksClose ...</code>) before rebooting.
 
=== LVM ===
<code>setup-disk</code> will automatically build and use volumes in a LVM group if you supply the '''-L''' switch.
 
If you instead want to build your LVM system manually, see [[Setting up Logical Volumes with LVM]]. Then <code>vgchange -ay</code>, format and mount your volumes, and supply the root mountpoint to [[setup-disk]]. When you're finished, be sure to
{{Cmd|umount ...
vgchange -an}}
before rebooting.
 
=== Dual-booting ===
See [[Installing Alpine on HDD dualbooting|Install to HDD with dual-boot]]
 
=== Other needs ===
* [[Installing Alpine Linux in a chroot]]
* [[Replacing non-Alpine Linux with Alpine remotely]]
 
 
<!--
Create partition with with type "Linux" (83).
apk_add e2fsprogs rsync
mkfs.ext3 /dev/hda1
mount -t ext3 /dev/hda1 /mnt
ROOT=/mnt apk_add uclibc busybox apk-tools alpine-baselayout alpine-conf
# Install busybox links
mkdir /mnt/proc && mount --bind /proc /mnt/proc && chroot /mnt /bin/busybox --install -s && umount /mnt/proc
# Copy the apk repository
rsync -ruav /media/cdrom/apks /mnt
mkdir /mnt/etc/apk && echo "APK_PATH=file://apks" > /mnt/etc/apk/apk.conf
# Copy the hd/ext3 initramfs image, kernel and kernel modules
rsync -ruav /media/cdrom/kernel/generic/hd-ext3.gz /media/cdrom/kernel/generic/bzImage /mnt
rsync -ruav /lib/modules/* /mnt/lib/modules/
-->
 
 
<!--
== Setting up the RAID ==
Set up a raid array as described [[Setting up a software raid1 array|here]].
In this document two raid arrays are configured: md0 for swap (512MB) and md1 for /var.
 
== Create filesystem ==
We need to install the software to create the filesystem ("format" the partition).
apk_add e2fsprogs
 
If you use an Alpine release older than 1.3.8 you will need to manually create a link to /etc/mtab.
ln -fs /proc/mounts /etc/mtab
 
Create the filesystem. The -j option makes it ext'''3'''. Without the -j option it will become non-journaling ext'''2'''. This step might take some time if your partition is big.
mke2fs -j /dev/md1
 
 
Now edit /etc/fstab and add your new partitions. Mine looks like this:
none            /proc          proc    defaults 0 0
none            /sys            sysfs  defaults 0 0
udev            /dev            tmpfs  size=100k 0 0
none            /dev/pts        devpts  defaults 0 0
tmpfs          /dev/shm        tmpfs  defaults 0 0
/dev/cdrom      /media/cdrom    iso9660 ro 0 0
/dev/fd0        /media/floppy  vfat    noauto  0 0
/dev/usba1      /media/usb      vfat    noauto  0 0
none            /proc/bus/usb  usbfs noauto 0 0
 
/dev/md0        swap            swap    defaults 0 0
/dev/md1        /var            ext3    defaults 0 0
 
== Move the data ==
Now you should stop all services running that put anything in /var (syslog for example). If you have booted on a clean installation and not run setup-alpine, then no services should be running. However, some packages might have created dirs in /var so we need to backup /var mount the new and move all backed up dirs back to the raided /var.
 
mv /var /var.tmp
mkdir /var
mount /var
mv /var.tmp/* /var
rmdir /var.tmp
 
Verify that everyting looks ok with the ''df'' utility.
~ $ df
Filesystem          1k-blocks      Used Available Use% Mounted on
none                    255172    23544    231628  9% /
udev                      100        0      100  0% /dev
/dev/cdrom              142276    142276        0 100% /media/cdrom
/dev/md1              37977060    181056  35866876  1% /var
 
== Survive reboots ==
Now we have everything up and running. We need to make sure that everything will be restored during next reboot.
 
Create an initscript that will mount /var for you during boot. I call it /etc/init.d/mountdisk and it looks like this:
#!/sbin/runscript
start() {
        ebegin "Mounting /var"
        mount /var
        eend $?
}
stop() {
        ebegin "Unmounting /var"
        umount /var
        eend $?
}
 
Make it exectutable:
chmod +x /etc/init.d/mountdisk
 
'''NOTE:''' Since Alpine-1.7.3 there is a ''localmount'' script shipped so you will not need to create your own ''mountdisk'' script.
 
And that /var is mounted *after* raid is created. The -k option will make alpine to unmount the /Var partition during boot. Also add start of swap too boot
rc_add -k -s 06 mountdisk
rc_add -k -s 06 swap
 
The /dev/md* device nodes will not be created automatically so we need to put the on floppy too.
lbu include /dev/md*
 
If you have users on the server and want /home to be permanent, you can create a directory /var/home and create links to /var/home.
mkdir /var/home
mv /home/* /var/home/
ln -s /var/home/* /home/
 
'''NOTE:''' You cannot just replace /home with a link that points to /var/home since the base has a /home directory. When the boot tries to copy the config from floppy it will fail because of the already existing /home directory.
 
Make sure the links are stored to floppy:
lbu include /home/*
 
Also remember to move any newly created users to /var/home and create a link:
adduser bob
mv /home/bob /var/home/
ln -s /var/home/bob /home/bob
lbu include /home/bob
 
Save to floppy:
lbu commit floppy
 
== Test it works ==
Reboot computer. Now should the raid start and /var should be mounted. Check with df:
~ $ df
Filesystem          1k-blocks      Used Available Use% Mounted on
none                    255172    23976    231196  9% /
mdev                      100        0      100  0% /dev
/dev/cdrom              140932    140932        0 100% /media/cdrom
/dev/md1              37977060    180984  35866948  1% /var
 
== Upgrades ==
Since the package database is placed on disk, you cannot update by simply replacing the CDROM. You will have to either run the upgrade on the new CDROM or run ''apk_add -u ... && update-conf'' manually.
-->
 
 
 
 
 
 
 


== Setting up swap ==
== Setting up swap ==

Revision as of 06:54, 5 March 2012

This material is work-in-progress ...

Do not follow instructions here until this notice is removed.
(Last edited by Dubiousjim on 5 Mar 2012.)

You may have complex needs that aren't handled automatically by the Alpine Setup Scripts. In those cases, you'll need to prepare your disks manually.

RAID =

setup-disk will automatically build a RAID array if you supply the -r switch, or if you specify more than one device.

If you instead want to build your RAID array manually, see Setting up a software raid1 array. Then you can add additional layers of encryption and/or LVM, or just assemble the RAID array, and supply the /dev/mdi device directly to setup-disk. When you're finished, be sure to disassemble the RAID array before rebooting.

Encryption

See Setting up encrypted volumes with LUKS. Then you can add an additional layer of LVM, or just unlock the volume you've created (using cryptsetup luksOpen ...), and supply the /dev/mapper/something device directly to setup-disk. When you're finished, be sure to relock the volume (using cryptsetup luksClose ...) before rebooting.

LVM

setup-disk will automatically build and use volumes in a LVM group if you supply the -L switch.

If you instead want to build your LVM system manually, see Setting up Logical Volumes with LVM. Then vgchange -ay, format and mount your volumes, and supply the root mountpoint to setup-disk. When you're finished, be sure to

umount ... vgchange -an

before rebooting.

Dual-booting

See Install to HDD with dual-boot

Other needs







Setting up swap

  1. create partition with type "linux swap" (82)
  2. mkswap /dev/sda2
  3. echo -e "/dev/sda2 none swap sw 0 0" >> /mnt/etc/fstab
  4. swapon /dev/sda2

Then

free

will show how much swap space is available.

If you prefer maximum speed, you don't need configure any raid devices for swap. Just add 2 swap partitions on different disks and linux will stripe them automatically. The downside is that at the moment one disk fails, the system will go down. For better reliability, put swap on raid1.

See also setup-cryptswap.