aboutsummaryrefslogblamecommitdiff
path: root/en_US.ISO8859-1/books/handbook/disks/chapter.xml
blob: cbb2551daa55126bcacb8e7fe573d3f026e722f7 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                           


                                      
              
   




                                                          
                        
 
                                 

                           




                                                                   
 
                                                           
 
                  
                

                                                        
                 
 
                

                                                           


                 

                                                                 
                 

                

                                                               

                 
                

                                                            
                 
 
                
                                                
                 
 
                

                                                                
                 
 
                
                                                                 
                 
 
                




                                                                  

                                                         
                 
                   




                                                         

                                                                    

                   
          
 
                               


                                 
                   






                                                       
                    
           
 



                                   
 
                                                 
                                                                   

                                                                   


                                                                

                                                                    

                                                               
                                       
 
                                                        
               
                                                 
                
 
                                                                    

                                                                       
                                                                 










                                                                      


                                                                    

                                                                         
                                                                                 




                                                                      









                                                                               
 
                                                                              










                                                                        
                                                                                          




                                                                        
          
 










































                                                                      
                                                                                           















                                                                         
                                                                                                






                                                               
                                                                                           









                                                                     

                                                                     
 








                                                                                                        
                                                                                                                 
              
                                                                               













                                                                      
                                                                                          


                                                               







                                                                                                                                                                     
              
                                                                               




                                                       


                                                                   
 
                                                                                                                
            
                                                                               



                                                  
                                                                                           



                                                                    
                                                                                              






                                                                                                           





                                                                                                                                                 



                                                                    
                            
          
                                                           
 
                   






                                            
                    
           
 




                                  
                                                               
                                                                   


                                                                      
 

                                                                     
                                                                   



                                                                     
 





                                                                          









                                                                








                                                                 
 


                                                                     

           
                                         
 
                                                                     

                                                                     

                                                                 




                                                                                            

                                                                      





                                                                     
 



                                                                      

                                                                     




                                                                                      
 


                                                                                                     




                                                                      
                                                               
 
               
                                                                   



                                                                    

                

                                                                   
                                                                 
                                                        

                                                                     

                                                     
                                    
                                                        

            


                                                                
 
                                                                                                                
 


                                                                    



                                                                      

             
                                       
                                                 


                                                                        

                                                                     

                                                     
                                                      
 


                                                                   
                                                                         
                                 



                                                                      
                                                                
                                                             
                                                               



                                                                      
 

                                                                                                                                                                     
 

                                                                      

                                                                      
 
                                                                                                                                                 
 
                                                  
                                                            

                                                                                                           


                                                                     
 



                                                                          
            



                                                 
                                                               
                                            










                                                                
           

                                                      
                                                    
 
                                                                            


                                                                     
                                                         



                                                                     
                             








                                                                          
                                                                      



                                                                     
                                                           




                                                                         
                                                                  


                                                                

          
                               
          
                                                                   
 
                   






                                            
                    
           
 
               
                                                   

                                     
 







                                                                     


                                              



                                     
 



                                                     
 

                                                                    



                                                                   





















                                                               





                                                                      
 

                                                                 
 



                                                                          
 

                                                                
 









                                                                             
 

                                                                   
 


                                                                     
                                                                
 

                                                               

                                                                     
 
                                                        
 


                                                                    
 
                                                            
 

                                                                     
             
 







                                                                      
                                                                      

                                                                          
                                                                                              
            
 


                                                    

                                                                    

                                                                    
                                                                     



                                                                  
 
                                                                                                                                                   
 


                                                                  





                                                                    

                                                                                               


















                                                                          







                                                                      
 

                                                                    

                                                                     
                                                                                      
 

                                                                   

                                                                    

            
                            

                                                           
 

                                                                      

                                                                 
                                                     





                                                                     
 
                                                                                                                                                        
 
                 

                                       
                  
 




                                                                      
 
                 
                                       
                                     
                  
 
                                                             


                                                                    
                                                      
 



                                                                     

                                                                     
 
                 
                                                     
                                                
                  
 
                                                                  
                                                                    



                                                                      







                                                                      
                                                                  
                     
                                                      
 
                                                                                                                                    
 

                                                                     
 


                                                                                                 

                                                                  
 
                                                      

                                                                    

            





                                                                      


                                                                                                                                                      



                                                       

            
                                
                                                      
 






                                                                                                                                               




                                                                     
 

                                                                      
                                                                
                                                                      


                                                                      
 
            



                                                                    



                                                                
                                                                    
                                                            
             
 
                                                                      

                                                           
                                                              
                                                                  
                                                                
                                    


                                                
                                                                    
                                                                   




                                                                   


                                                               
                                                                  
                                                              
                                                                   
 
            



















                                                                                                          
            


                                                             
 


                                                                    
                                     
 





                                                                      
 

                                                                 
 
              
                                                                   

                                                                     

                                                                      

                                                                                       
 




                                                                      












                                                                                                                                   
            
          
 
                                
          
                                                                    
 
                   






                                            
                    
                   






                                              
                    
           
 
               
                                               


                                    




                                                                    
 

                                                               
 




                                                                     
                                                                                   

                                                            
 





                                                               
 









                                                                     
 


                                                                    



                                                                         
                 
 




                                                                   
 


                                                                      
 








                                                                      



                                  

                                                            
                                                                
                                                              
 






                                                                      
 


                                                                      


                                                           
                                    

                                                                                  
                                            

            


                                                                

                               


            
                                                         
 

                                                           
                                                                    


                                                                    
 
                                                     

                                                             
 
                                                                                                                                                                       
 


                                                                      

                       

                                                                     





                                                                    
 

                                                             
 
                                                                                                                                                                 

                                                                    


                                                                      

            
                                                                      
                                                                    



                                                                      
                                                        




                                                                     
 
                                                                                                                                                                                  


                                                      
                                                                                                                                                                                           
 



                                                                  





                                                                      
             

            
           
                                                           
 
                 
                                                 


                                        


                                                                   
                                                                  
                                                           
 

                                                                    



                                                                  
 
                                                                                                                                                                 
 



                                                                    

            
           
                                                      
 
                 

                                                        

                  





                                                                      
 
                                                                                                             
 
                                                                  


                                                                     
 
                                                                      


                                                                      
 
                                                                                                                                                              
 





                                                                   
 

                                                            
 
                                                                                                                                                               
 
                                                             


                                                                 
                                                               


                                                                     

             
                                           
 
                                                                                                                                                 

            
           
                                                      
 
                 

                                                        

                  



                                                                     
 



                                                                      
 

                                                              
 
                                                                                                                         

            

                                                                     



                                                                    
 
                                                                                                                                                                               
 



                                                                      
 
                                                                   

                                                                     

             


                                                                    
 
                                                                                                                                                           
 

                                                                     


                                                                      
 





                                                                      
 

                                                                      
 
                                                                                                             
 
                                                            
 
                                                                                                                         


            
                                  
 






                                                                   
 
                                                                   

                                                                     
 
                                                                                                                                                               
 





                                                                      

            




                                                                    
                       
             


            
                                         
 
                                                                      

                                                                 
                                           
 
                                  
                                                               




                                                                              

            


                                                                     
             
            
 
                                     
                                                       
 
                 

                                                         

                  




                                                                      
 
                                                           
 




                                                                      
 


                                                                                                                        
 


                                                                   
 

                                                                      
 
                                                                                                                                      
 

                                                                     
            

          
                           
                                                  
 
    
                   






                                              
                    
 
                   






                                          
                    
         
 
                                                                    
                     
 

                                             
 










                                                                     

                                                                                                   
             
 




                                                                      
 
                                                                   
 

                                                                                                  
 




                                                                     
 
                                                          
 
                                                                                        

                
 



                                                                     
          
 

                                
 

                 






                                              
                    
         
 



                                                                      
 



                                                                     


                  


                                                                      
                                                                   


                 
                                                                   
                                                             


                 
                                                             
                                                                 
                                                        


                 

                                                                 


                   

                                                                     

                                                                      
                                                                    
                                     
 

                                                                   
 
           
                                        
 
                 
                                          
                                             
                  





                                                     
 
                                                                 
                                                              
                                                                    







                                                                     
 
            
                                                            
                                                                    


                                                                    
             













                                                                      



                                                       




                                                                     



                                                                   

                                                                      
                                                 

               

                                                 
 
                                                                                                 
                                                                                                    
                
 
                                                                      
                                                        
                                                 

               

                                                                
                     
 
                                                                                                                                                         
                


            
                                      
 
                 

                                                     
                  
 
                                                                   

                                                        

                                                                      



                                                                      

                                                                      
 
                                                                   
                                 


                                                                  
 
               
                                                    
                                        
 
                                                                                                                    
                
 





                                                                      
 
               
                                                      

                                        
                                                                                                                 
                
 




                                                                      

                 

                                                      
                  
 
                                                                  
                                                           


                                                                     
 
                                                             



                                                                    
                                                       
 
               
                                                                      
                                                                     
 
                                                                                                                           
                
 
                 

                                                     




                                                                      





                                                                      
                                                                   


                                                                 

                                 
               
                                                    

                                        
                                                                                                                  
                

            






















                                                                      



                                                                      

                                                                    

                                                                                 
 








                                                                                                            
                                                                  
                                                  









                                                                                            


                                                             

                                                                                   

            
                                            
                                                 
 
                 
                                          
                  
 

                                                               



                                                                      
 
                                     
                                          

                                             
                                                    
            

           
                                       
 


                                                                
 



















                                                                  
                                
                                                     
 











                                                                    

                                                                     
                                                                                                                                                                                                                                                                                                              






                                                                     
 


                                                                     

            
 
                                
          
                                 
 
                   






                                                         
                    
           
 

                                                               



                                                                      
 





                                                                     
 
                                   
                                                            
 
                 
                                
                                     

                  








                                                                     
 
                                                                                                                                       
                                                                                                                                 
 

                                                                    

                                                                 


                                                                     
 




                                                      




                                                                   
 

                                                                                         
 


                                                                      
 
                                      
                                                                  
 



                                                 













                                                                      
 
                                                                                                                                       









                                                                                                              
 
                                                                      
                                                                    
                                                   
 
                                                                                                                                                   
                 
                           
 



                                                                     
 

                                                                                                                                  
                                                                             




                                                                                                               
                                                                       
                                                    

                                                       






                                                                     



                                                              
                                                                                                                                                                                                        

                                                                 







                                                                                                                                                                 
            
          
 
                            


                                          
                   






                                            
                    
           
 
               

                                      
                
 

                                                                   

                       

                                                                     




                                                                     



                                                                     

                                                                     
                                                                      

                                                                   
 
                                                                
                                                  
                                                                     
                     
 
                                                                                                      
 

                                                             
 
                                                                                            
 
                                                               
                                      
                          
 
                                                                                   
 

                                                          
 


                                                                     

                                                              
                 
 


                                                                     

                                                                 
                 
 
                




                                                                      
                 
 
                

                                                                  
                                                             
 
                                                                                                                



                                                                    




                                                                      
 
                                                            
                                                              
 
                                                                     
                                                              

                                                                                    
          
 
                         
                              
 




                                                         
 




                                                                      


                                                                     
                                        
 
           
                                         
 

                                                                     
 

                                                                                 
 
                                                                     


                                                                    
                                          
 
                                                    
 
                                       
                                                 

                                                         
 
                 

                                       
                  






                                                                      
 
                                                        
 
                                                                   



                                                                      
 
                                                                                  
 


                                                                    
 
                                                                                              
 

                                                                    
                                                                     

                                                                   
 
                                                                     


                                                                      
                                               
 

                                                                    
                                                                      
                                                   

            

                                         
 
                 

                                      

                  

                                                   
 
                                                                    
 
                                                                

                                                                 
 
                                                                    
                                          
 
                                                                  
                                                                  

                                                                     
                                                                    
                                                         
 
                                                          





                                                                    
                    
 
                                                          






                                                                      




                                                                     
                                             
 

                                                                  
                                                      
                                                       
                                                         
                                                                
 







                                                                      
 
                                                                                               
 
                                                             
                      
 
                                                                    




                                                                  

                                         
 
                                                                                       
 
                                                                  


            
                                                         
 
                 

                                       

                  





                                                                    
 
                                                                      





                                                                    
 
                                                           
                                                                               

                                                                                        
 
                                                            
 
                                                                     



                                                                      
            
 

                                    
 
                                                   
 




                                                                      
 



                                                        
 
                                                                                                                  
 
                                                          
 
                                                                                 

            
 
                                   


                                               
                   











                                                    
                    
           
 

                              

                                       
 
                                                          

                                                                
                                                              


                                                                     

                                                                      

                                                                     













                                                                      
 
           

                                               
 










                                                                      






                                                                      
                                     
 


                                                                     
 
                                                                            
 

                                                                  
 
                                                      
 


                                                                      
 
                 

                                                 
 

                                               
 



                                                                     

                                                                       
 
                                                                  


                                                           
               
 














                                                                               
 


                                                       
 

                                                                   




                                                                      
 

                                                                                                                               





                                                                          
                            
              
 


                                                                    


                                                                   

                                                                                                                                  
 

                                                               
                                    



                                                                     

                   




                                                                     

                    
 


                                                      
 
                                                                                                                
 



                                                                     
                                                             
 
                                                                  


                                                                        
               
 




                                                                  



                                                                     

                                                                 

                                                                                        
               
 

                                                      
 
                                                                 
                          
 

                                                                            
               
 


                                                         
 

                                                                   
 
                                                            






                                                                

                  
 




                                                                   
 
                                               
                                                
                                         
 
                                                               



                                                                   



                      







                                                                      


                                                                                                                

            
                                          


                                                                   
                     






                                              
                      
             
 




                                                                      


                    


                                                                
                   
 
                  
                                                                  

                                                 
                   
 

                                                               
                                                                  
                                                        
                   
 
                  
                                                              
                   
 
                  

                                                                 
                   
 
                  
                                                                    

                                                                      
                   
 
                  

                                                                   



                           
                                                            
                            
 








                                                                      

                 


                                          
              

                                                             



                                                                     






                                                                                
 

                                                                    
 

                                          


               
                                                
 










                                                                        

                                                                                                       
                                                                                


                                


                                                                      
 
                                                                      

                                                                    




                                                                                                                        



                                                                      



                                                                                            

                                                       
 




                                                                   




                                                                 


                                                                                              
                                                                                                    
 

                                                                     








                                                             
               
                  
 




                                                                      
 
                                                                  
                                                                 
 
                                                             


                                                                   
 
                                                                   
                                                                             
 













                                                                     
            
          
 
                                  
          
                                    
 
                   


                                            
                                       


                                        
                    
           
 




                                       


                                                                    







                                                                      
                     
                                                                     


                                               
 



                                                                      
 
                                                                                                                              
 
                                                                     

                                                          
 
                                                                                             
                                                                                          
 


                                                                     
 
                                                                                             
                                                                                          
 
                                                                    
                                                                      

                                                                 








































                                                                      
                                                                     




                                                                                                                          
 


            
                                                
 


                                                                 




                                                           
                                                           




                                                           
                                                           

            
 
                             
          

                                         
 
                   






                                            
                    
 
                   



























                                              
                    
           
 




                                              

                                                                     













                                                                      
 




                                                                  
 



                                                                   
 




                                                                      
 





                                                                 
 



                                                                   
 





                                                                      










































                                                                  

                                                                   
                                                                                 



                                   


                                                                    

                                                                     

                                                               
 


                                                                      
                                                                     


                                                                    

                                                                  

                                                                      

                                                                     

                                                                      



                                                                 
 
                                                                      




                                                                      
 
                                                                 
                                                             




                                                                    
 


                                                                    
 

                    





                                                                      

                                                                   
                   
 
                  


                                                                      
                                            
                   
 
                  





                                                                     

                     




                                       
                                                                     
                          

                    
                  


                                                                      
                   
 
                  

                                                
                   
 
                  


                                                                    


                     
                                                


                                                                   



                                                          
                                                                      




                                                                      
                                                

                                                                      
                                                        
                                                                
                                                                     
                                                
                                       
 
                                                                  

                                                                 
                  
 



                                                                
         


                                                            


                  

                                                     


                                                          

                                                               

                                                         

            

                                                               
                                                                     
                                                     
 
                                                                                                 
                                                                    

            

                                                            


                                                                     

                                                                     

             



                                                                    

                                                                 
 
                                                                                                                
 

                                                   
 
                                                                                                                  
 

                                                                      
 
                                                                                                          
 
                                                                   






                                                                      
 
                                                           



                                                                      
                                                                  
 


                                                                                                                                   


                                                                    
                                                               
                                      
                                                 






                                                                   
                                                                     













                                                                     
                                                 


                                                                 



                                                                      
                                           




                                                                      

                                                                      
                                                           


                                                                     


                                                                      
 
                                           

                                                                     














                                                         





                                                                   

                                                               
 
                                                                                  
 



                                                                     
                                                                

                                                                      
 

                                                         
 
                                 





                                                                   
                                           

















                                                                                         
                                                                                                          













                                                                                                                
                                                                           

























                                                                                                         
                                                                     




                                                       
                                                                  








                                                                                                                  
                                                                  
                                     


                      

                                                              
                     
 



                                                  
 
                    
                                         


                       
                                                   


                      
                                                                   
                     
 
                    
                                                              




                               



                                                                      


                  




                                                                   

              
                                                                    

                                                                                                 

              
 


                                    



                                                                     
                                                                     

                       
                                                             
                                                               




                                                                     
 
                                    

                                                                





                                                                      
 

                                                                      




                                                                     


                                                                                                      


              
          
<?xml version="1.0" encoding="iso-8859-1"?>
<!--
     The FreeBSD Documentation Project

     $FreeBSD$
-->

<chapter xmlns="http://docbook.org/ns/docbook"
  xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
  xml:id="disks">

  <title>Storage</title>

  <sect1 xml:id="disks-synopsis">
    <title>Synopsis</title>

    <para>This chapter covers the use of disks and storage media in
      &os;.  This includes <acronym>SCSI</acronym> and
      <acronym>IDE</acronym> disks, <acronym>CD</acronym> and
      <acronym>DVD</acronym> media, memory-backed disks, and
      <acronym>USB</acronym> storage devices.</para>

    <para>After reading this chapter, you will know:</para>

    <itemizedlist>
      <listitem>
	<para>How to add additional hard disks to a &os;
	  system.</para>
      </listitem>

      <listitem>
	<para>How to grow the size of a disk's partition on
	  &os;.</para>
      </listitem>

      <listitem>
	<para>How to configure &os; to use <acronym>USB</acronym>
	  storage devices.</para>
      </listitem>

      <listitem>
	<para>How to use <acronym>CD</acronym> and
	  <acronym>DVD</acronym> media on a &os; system.</para>
      </listitem>

      <listitem>
	<para>How to use the backup programs available under
	  &os;.</para>
      </listitem>

      <listitem>
	<para>How to set up memory disks.</para>
      </listitem>

      <listitem>
	<para>What file system snapshots are and how to use them
	  efficiently.</para>
      </listitem>

      <listitem>
	<para>How to use quotas to limit disk space usage.</para>
      </listitem>

      <listitem>
	<para>How to encrypt disks and swap to secure them against
	  attackers.</para>
      </listitem>

      <listitem>
	<para>How to configure a highly available storage
	  network.</para>
      </listitem>
    </itemizedlist>

    <para>Before reading this chapter, you should:</para>

    <itemizedlist>
      <listitem>
	<para>Know how to <link linkend="kernelconfig">configure and
	    install a new &os; kernel</link>.</para>
      </listitem>
    </itemizedlist>
  </sect1>

  <sect1 xml:id="disks-adding">
    <info>
      <title>Adding Disks</title>

      <authorgroup>
	<author>
	  <personname>
	    <firstname>David</firstname>
	    <surname>O'Brien</surname>
	  </personname>
	  <contrib>Originally contributed by </contrib>
	</author>
      </authorgroup>
    </info>

    <indexterm>
      <primary>disks</primary>
      <secondary>adding</secondary>
    </indexterm>

    <para>This section describes how to add a new
      <acronym>SATA</acronym> disk to a machine that currently only
      has a single drive.  First, turn off the computer and install
      the drive in the computer following the instructions of the
      computer, controller, and drive manufacturers.  Reboot the
      system and become
      <systemitem class="username">root</systemitem>.</para>

    <para>Inspect <filename>/var/run/dmesg.boot</filename> to ensure
      the new disk was found.  In this example, the newly added
      <acronym>SATA</acronym> drive will appear as
      <filename>ada1</filename>.</para>

    <indexterm><primary>partitions</primary></indexterm>
    <indexterm>
      <primary><command>gpart</command></primary>
    </indexterm>

    <para>For this example, a single large partition will be created
      on the new disk.  The <link
	xlink:href="http://en.wikipedia.org/wiki/GUID_Partition_Table">
	<acronym>GPT</acronym></link> partitioning scheme will be
      used in preference to the older and less versatile
      <acronym>MBR</acronym> scheme.</para>

    <note>
      <para>If the disk to be added is not blank, old partition
	information can be removed with
	<command>gpart delete</command>.  See &man.gpart.8; for
	details.</para>
    </note>

    <para>The partition scheme is created, and then a single partition
      is added.  To improve performance on newer disks with larger
      hardware block sizes, the partition is aligned to one megabyte
      boundaries:</para>

    <screen>&prompt.root; <userinput>gpart create -s GPT ada1</userinput>
&prompt.root; <userinput>gpart add -t freebsd-ufs -a 1M ada1</userinput></screen>

    <para>Depending on use, several smaller partitions may be desired.
      See &man.gpart.8; for options to create partitions smaller than
      a whole disk.</para>

    <para>The disk partition information can be viewed with
      <command>gpart show</command>:</para>

    <screen>&prompt.user; <userinput>gpart show ada1</userinput>
=>        34  1465146988  ada1  GPT  (699G)
          34        2014        - free -  (1.0M)
        2048  1465143296     1  freebsd-ufs  (699G)
  1465145344        1678        - free -  (839K)</screen>

    <para>A file system is created in the new partition on the new disk:</para>

    <screen>&prompt.root; <userinput>newfs -U /dev/ada1p1</userinput></screen>

    <para>An empty directory is created as a
      <emphasis>mountpoint</emphasis>, a location for mounting the new
      disk in the original disk's file system:</para>

    <screen>&prompt.root; <userinput>mkdir /newdisk</userinput></screen>

    <para>Finally, an entry is added to
      <filename>/etc/fstab</filename> so the new disk will be mounted
      automatically at startup:</para>

    <programlisting>/dev/ada1p1	/newdisk	ufs	rw	2	2</programlisting>

    <para>The new disk can be mounted manually, without restarting the
      system:</para>

    <screen>&prompt.root; <userinput>mount /newdisk</userinput></screen>
  </sect1>

  <sect1 xml:id="disks-growing">
    <info>
      <title>Resizing and Growing Disks</title>

      <authorgroup>
	<author>
	  <personname>
	    <firstname>Allan</firstname>
	    <surname>Jude</surname>
	  </personname>
	  <contrib>Originally contributed by </contrib>
	</author>
      </authorgroup>
    </info>

    <indexterm>
      <primary>disks</primary>
      <secondary>resizing</secondary>
    </indexterm>

    <para>A disk's capacity can increase without any changes to the
      data already present.  This happens commonly with virtual
      machines, when the virtual disk turns out to be too small and is
      enlarged.  Sometimes a disk image is written to a
      <acronym>USB</acronym> memory stick, but does not use the full
      capacity.  Here we describe how to resize or
      <emphasis>grow</emphasis> disk contents to take advantage of
      increased capacity.</para>

    <para>Determine the device name of the disk to be resized by
      inspecting <filename>/var/run/dmesg.boot</filename>.  In this
      example, there is only one <acronym>SATA</acronym> disk in the
      system, so the drive will appear as
      <filename>ada0</filename>.</para>

    <indexterm><primary>partitions</primary></indexterm>
    <indexterm>
      <primary><command>gpart</command></primary>
    </indexterm>

    <para>List the partitions on the disk to see the current
      configuration:</para>

    <screen>&prompt.root; <userinput>gpart show <replaceable>ada0</replaceable></userinput>
=>      34  83886013  ada0  GPT  (48G) [CORRUPT]
        34       128     1  freebsd-boot  (64k)
       162  79691648     2  freebsd-ufs  (38G)
  79691810   4194236     3  freebsd-swap  (2G)
  83886046         1        - free -  (512B)</screen>

    <note>
      <para>If the disk was formatted with the <link
	  xlink:href="http://en.wikipedia.org/wiki/GUID_Partition_Table">
	<acronym>GPT</acronym></link> partitioning scheme, it may show
	as <quote>corrupted</quote> because the <acronym>GPT</acronym>
	backup partition table is no longer at the end of the
	drive.  Fix the backup
	partition table with
	<command>gpart</command>:</para>

      <screen>&prompt.root; <userinput>gpart recover <replaceable>ada0</replaceable></userinput>
ada0 recovered</screen>
    </note>

    <para>Now the additional space on the disk is available for
      use by a new partition, or an existing partition can be
      expanded:</para>

    <screen>&prompt.root; <userinput>gpart show <replaceable>ada0</replaceable></userinput>
=>       34  102399933  ada0  GPT  (48G)
         34        128     1  freebsd-boot  (64k)
        162   79691648     2  freebsd-ufs  (38G)
   79691810    4194236     3  freebsd-swap  (2G)
   83886046   18513921        - free -  (8.8G)</screen>

    <para>Partitions can only be resized into contiguous free space.
      Here, the last partition on the disk is the swap partition, but
      the second partition is the one that needs to be resized.  Swap
      partitions only contain temporary data, so it can safely be
      unmounted, deleted, and then recreate the third partition after
      resizing the second partition.</para>

    <para>Disable the swap partition:</para>

    <screen>&prompt.root; <userinput>swapoff <replaceable>/dev/ada0p3</replaceable></userinput></screen>

    <para>Delete the third partition, specified by the
      <option>-i</option> flag, from the disk
      <replaceable>ada0</replaceable>.</para>

    <screen>
&prompt.root; <userinput>gpart delete -i <replaceable>3</replaceable> <replaceable>ada0</replaceable></userinput>
ada0p3 deleted
&prompt.root; <userinput>gpart show <replaceable>ada0</replaceable></userinput>
=>       34  102399933  ada0  GPT  (48G)
         34        128     1  freebsd-boot  (64k)
        162   79691648     2  freebsd-ufs  (38G)
   79691810   22708157        - free -  (10G)</screen>

    <warning>
      <para>There is risk of data loss when modifying the partition
	table of a mounted file system.  It is best to perform the
	following steps on an unmounted file system while running from
	a live <acronym>CD-ROM</acronym> or <acronym>USB</acronym>
	device.  However, if absolutely necessary, a mounted file
	system can be  resized after disabling GEOM safety
	features:</para>

      <screen>&prompt.root; <userinput>sysctl kern.geom.debugflags=16</userinput></screen>
    </warning>

    <para>Resize the partition, leaving room to recreate a swap
      partition of the desired size.  The partition to resize is
      specified with <option>-i</option>, and the new desired size
      with <option>-s</option>.  Optionally, alignment of the
      partition is controlled with <option>-a</option>.  This only
      modifies the size of the partition.  The file system in the
      partition will be expanded in a separate step.</para>

    <screen>&prompt.root; <userinput>gpart resize -i <replaceable>2</replaceable> -s <replaceable>47G</replaceable> -a 4k <replaceable>ada0</replaceable></userinput>
ada0p2 resized
&prompt.root; <userinput>gpart show <replaceable>ada0</replaceable></userinput>
=>       34  102399933  ada0  GPT  (48G)
         34        128     1  freebsd-boot  (64k)
        162   98566144     2  freebsd-ufs  (47G)
   98566306    3833661        - free -  (1.8G)</screen>

    <para>Recreate the swap partition and activate it.  If no size
      is specified with <option>-s</option>, all remaining space is
      used:</para>

    <screen>&prompt.root; <userinput>gpart add -t freebsd-swap -a 4k <replaceable>ada0</replaceable></userinput>
ada0p3 added
&prompt.root; <userinput>gpart show <replaceable>ada0</replaceable></userinput>
=>       34  102399933  ada0  GPT  (48G)
         34        128     1  freebsd-boot  (64k)
        162   98566144     2  freebsd-ufs  (47G)
   98566306    3833661     3  freebsd-swap  (1.8G)
&prompt.root; <userinput>swapon <replaceable>/dev/ada0p3</replaceable></userinput></screen>

    <para>Grow the <acronym>UFS</acronym> file system to use the new
      capacity of the resized partition:</para>

    <screen>&prompt.root; <userinput>growfs <replaceable>/dev/ada0p2</replaceable></userinput>
Device is mounted read-write; resizing will result in temporary write suspension for /.
It's strongly recommended to make a backup before growing the file system.
OK to grow file system on /dev/ada0p2, mounted on /, from 38GB to 47GB? [Yes/No] <userinput>Yes</userinput>
super-block backups (for fsck -b #) at:
 80781312, 82063552, 83345792, 84628032, 85910272, 87192512, 88474752,
 89756992, 91039232, 92321472, 93603712, 94885952, 96168192, 97450432</screen>

    <para>If the file system is <acronym>ZFS</acronym>, the resize is
      triggered by running the <option>online</option> subcommand with
      <option>-e</option>:</para>

    <screen>&prompt.root; <userinput>zpool online -e <replaceable>zroot</replaceable> <replaceable>/dev/ada0p2</replaceable></userinput></screen>

    <para>Both the partition and the file system on it have now been
      resized to use the newly-available disk space.</para>
  </sect1>

  <sect1 xml:id="usb-disks">
    <info>
      <title><acronym>USB</acronym> Storage Devices</title>

      <authorgroup>
	<author>
	  <personname>
	    <firstname>Marc</firstname>
	    <surname>Fonvieille</surname>
	  </personname>
	  <contrib>Contributed by </contrib>
	</author>
      </authorgroup>
    </info>

    <indexterm>
      <primary>USB</primary>
      <secondary>disks</secondary>
    </indexterm>

    <para>Many external storage solutions, such as hard drives,
      <acronym>USB</acronym> thumbdrives, and <acronym>CD</acronym>
      and <acronym>DVD</acronym> burners, use the Universal Serial Bus
      (<acronym>USB</acronym>).  &os; provides support for
      <acronym>USB</acronym> 1.x, 2.0, and 3.0 devices.</para>

    <note>
      <para><acronym>USB</acronym> 3.0 support is not compatible with
	some hardware, including Haswell (Lynx point) chipsets.  If
	&os; boots with a <errorname>failed with error 19</errorname>
	message, disable xHCI/USB3 in the system
	<acronym>BIOS</acronym>.</para>
    </note>

    <para>Support for <acronym>USB</acronym> storage devices is built
      into the <filename>GENERIC</filename> kernel.  For a custom
      kernel, be sure that the following lines are present in the
      kernel configuration file:</para>

    <programlisting>device scbus	# SCSI bus (required for ATA/SCSI)
device da	# Direct Access (disks)
device pass	# Passthrough device (direct ATA/SCSI access)
device uhci	# provides USB 1.x support
device ohci	# provides USB 1.x support
device ehci	# provides USB 2.0 support
device xhci	# provides USB 3.0 support
device usb	# USB Bus (required)
device umass	# Disks/Mass storage - Requires scbus and da
device cd	# needed for CD and DVD burners</programlisting>

    <para>&os; uses the &man.umass.4; driver which uses the
      <acronym>SCSI</acronym> subsystem to access
      <acronym>USB</acronym> storage devices.  Since any
      <acronym>USB</acronym> device will be seen as a
      <acronym>SCSI</acronym> device by the system, if the
      <acronym>USB</acronym> device is a <acronym>CD</acronym> or
      <acronym>DVD</acronym> burner, do <emphasis>not</emphasis>
      include <option>device atapicam</option> in a custom kernel
      configuration file.</para>

    <para>The rest of this section demonstrates how to verify that a
      <acronym>USB</acronym> storage device is recognized by &os; and
      how to configure the device so that it can be used.</para>

    <sect2>
      <title>Device Configuration</title>

      <para>To test the <acronym>USB</acronym> configuration, plug in
	the <acronym>USB</acronym> device.  Use
	<command>dmesg</command> to confirm that the drive appears in
	the system message buffer.  It should look something like
	this:</para>

      <screen>umass0: &lt;STECH Simple Drive, class 0/0, rev 2.00/1.04, addr 3&gt; on usbus0
umass0:  SCSI over Bulk-Only; quirks = 0x0100
umass0:4:0:-1: Attached to scbus4
da0 at umass-sim0 bus 0 scbus4 target 0 lun 0
da0: &lt;STECH Simple Drive 1.04&gt; Fixed Direct Access SCSI-4 device
da0: Serial Number WD-WXE508CAN263
da0: 40.000MB/s transfers
da0: 152627MB (312581808 512 byte sectors: 255H 63S/T 19457C)
da0: quirks=0x2&lt;NO_6_BYTE&gt;</screen>

      <para>The brand, device node (<filename>da0</filename>), speed,
	and size will differ according to the device.</para>

      <para>Since the <acronym>USB</acronym> device is seen as a
	<acronym>SCSI</acronym> one, <command>camcontrol</command> can
	be used to list the <acronym>USB</acronym> storage devices
	attached to the system:</para>

      <screen>&prompt.root; <userinput>camcontrol devlist</userinput>
&lt;STECH Simple Drive 1.04&gt;          at scbus4 target 0 lun 0 (pass3,da0)</screen>

      <para>Alternately, <command>usbconfig</command> can be used to
	list the device.  Refer to &man.usbconfig.8; for more
	information about this command.</para>

      <screen>&prompt.root; <userinput>usbconfig</userinput>
ugen0.3: &lt;Simple Drive STECH&gt; at usbus0, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (2mA)</screen>

      <para>If the device has not been formatted, refer to <xref
	  linkend="disks-adding"/> for instructions on how to format
	and create partitions on the <acronym>USB</acronym> drive.  If
	the drive comes with a file system, it can be mounted by
	<systemitem class="username">root</systemitem> using the
	instructions in <xref linkend="mount-unmount"/>.</para>

      <warning>
	<para>Allowing untrusted users to mount arbitrary media, by
	  enabling <varname>vfs.usermount</varname> as described
	  below, should not be considered safe from a security point
	  of view.  Most file systems were not built to safeguard
	  against malicious devices.</para>
      </warning>

      <para>To make the device mountable as a normal user, one
	solution is to make all users of the device a member of the
	<systemitem class="groupname">operator</systemitem> group
	using &man.pw.8;.  Next, ensure that <systemitem
	  class="groupname">operator</systemitem> is able to read and
	write the device by adding these lines to
	<filename>/etc/devfs.rules</filename>:</para>

      <programlisting>[localrules=5]
add path 'da*' mode 0660 group operator</programlisting>

      <note>
	<para>If internal <acronym>SCSI</acronym> disks are also
	  installed in the system, change the second line as
	  follows:</para>

	<programlisting>add path 'da[<replaceable>3</replaceable>-9]*' mode 0660 group operator</programlisting>

	<para>This will exclude the first three
	  <acronym>SCSI</acronym> disks (<filename>da0</filename> to
	  <filename>da2</filename>)from belonging to the <systemitem
	    class="groupname">operator</systemitem> group.  Replace
	  <replaceable>3</replaceable> with the number of internal
	  <acronym>SCSI</acronym> disks.  Refer to &man.devfs.rules.5;
	  for more information about this file.</para>
      </note>

      <para>Next, enable the ruleset in
	<filename>/etc/rc.conf</filename>:</para>

      <programlisting>devfs_system_ruleset="localrules"</programlisting>

      <para>Then, instruct the system to allow regular users to mount
	file systems by adding the following line to
	<filename>/etc/sysctl.conf</filename>:</para>

      <programlisting>vfs.usermount=1</programlisting>

      <para>Since this only takes effect after the next reboot, use
	<command>sysctl</command> to set this variable now:</para>

      <screen>&prompt.root; <userinput>sysctl vfs.usermount=1</userinput>
vfs.usermount: 0 -&gt; 1</screen>

      <para>The final step is to create a directory where the file
	system is to be mounted.  This directory needs to be owned by
	the user that is to mount the file system.  One way to do that
	is for <systemitem class="username">root</systemitem> to
	create a subdirectory owned by that user as <filename
	  >/mnt/<replaceable>username</replaceable></filename>.
	In the following example, replace
	<replaceable>username</replaceable> with the login name of the
	user and <replaceable>usergroup</replaceable> with the user's
	primary group:</para>

      <screen>&prompt.root; <userinput>mkdir /mnt/<replaceable>username</replaceable></userinput>
&prompt.root; <userinput>chown <replaceable>username</replaceable>:<replaceable>usergroup</replaceable> /mnt/<replaceable>username</replaceable></userinput></screen>

      <para>Suppose a <acronym>USB</acronym> thumbdrive is plugged in,
	and a device <filename>/dev/da0s1</filename> appears.  If the
	device is formatted with a <acronym>FAT</acronym> file system,
	the user can mount it using:</para>

      <screen>&prompt.user; <userinput>mount -t msdosfs -o -m=644,-M=755 /dev/da0s1 /mnt/<replaceable>username</replaceable></userinput></screen>

      <para>Before the device can be unplugged, it
	<emphasis>must</emphasis> be unmounted first:</para>

      <screen>&prompt.user; <userinput>umount /mnt/<replaceable>username</replaceable></userinput></screen>

      <para>After device removal, the system message buffer will show
	messages similar to the following:</para>

      <screen>umass0: at uhub3, port 2, addr 3 (disconnected)
da0 at umass-sim0 bus 0 scbus4 target 0 lun 0
da0: &lt;STECH Simple Drive 1.04&gt; s/n WD-WXE508CAN263          detached
(da0:umass-sim0:0:0:0): Periph destroyed</screen>
    </sect2>

    <sect2>
      <title>Automounting Removable Media</title>

      <para><acronym>USB</acronym> devices can be automatically
	mounted by uncommenting this line in
	<filename>/etc/auto_master</filename>:</para>

      <screen>/media		-media		-nosuid</screen>

      <para>Then add these lines to
	<filename>/etc/devd.conf</filename>:</para>

      <screen>notify 100 {
	match "system" "GEOM";
	match "subsystem" "DEV";
	action "/usr/sbin/automount -c";
};</screen>

      <para>Reload the configuration if &man.autofs.5;
	and &man.devd.8; are already running:</para>

      <screen>&prompt.root; <userinput>service automount restart</userinput>
&prompt.root; <userinput>service devd restart</userinput></screen>

      <para>&man.autofs.5; can be set to start at boot by adding this
	line to <filename>/etc/rc.conf</filename>:</para>

      <programlisting>autofs_enable="YES"</programlisting>

      <para>&man.autofs.5; requires &man.devd.8; to be enabled, as it
	is by default.</para>

      <para>Start the services immediately with:</para>

      <screen>&prompt.root; <userinput>service automount start</userinput>
&prompt.root; <userinput>service automountd start</userinput>
&prompt.root; <userinput>service autounmountd start</userinput>
&prompt.root; <userinput>service devd start</userinput></screen>

      <para>Each file system that can be automatically mounted appears
	as a directory in <filename>/media/</filename>.  The directory
	is named after the file system label.  If the label is
	missing, the directory is named after the device node.</para>

      <para>The file system is transparently mounted on the first
	access, and unmounted after a period of inactivity.
	Automounted drives can also be unmounted manually:</para>

      <screen>&prompt.root; <userinput>automount -fu</userinput></screen>

      <para>This mechanism is typically used for memory cards and
	<acronym>USB</acronym> memory sticks.  It can be used with
	any block device, including optical drives or
	<acronym>iSCSI</acronym> <acronym>LUN</acronym>s.</para&g